'''simple docstring'''




import os
import shutil
import sys
import tempfile
import unittest
from pathlib import Path

import pytest

import transformers
from transformers import (
    BERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
    GPT2_PRETRAINED_CONFIG_ARCHIVE_MAP,
    AutoTokenizer,
    BertConfig,
    BertTokenizer,
    BertTokenizerFast,
    CTRLTokenizer,
    GPTaTokenizer,
    GPTaTokenizerFast,
    PreTrainedTokenizerFast,
    RobertaTokenizer,
    RobertaTokenizerFast,
    is_tokenizers_available,
)
from transformers.models.auto.configuration_auto import CONFIG_MAPPING, AutoConfig
from transformers.models.auto.tokenization_auto import (
    TOKENIZER_MAPPING,
    get_tokenizer_config,
    tokenizer_class_from_name,
)
from transformers.models.roberta.configuration_roberta import RobertaConfig
from transformers.testing_utils import (
    DUMMY_DIFF_TOKENIZER_IDENTIFIER,
    DUMMY_UNKNOWN_IDENTIFIER,
    SMALL_MODEL_IDENTIFIER,
    RequestCounter,
    require_tokenizers,
    slow,
)


sys.path.append(str(Path(__file__).parent.parent.parent.parent / "utils"))

from test_module.custom_configuration import CustomConfig  # noqa E402
from test_module.custom_tokenization import CustomTokenizer  # noqa E402


if is_tokenizers_available():
						from test_module.custom_tokenization_fast import CustomTokenizerFast





class 					__magic_name__		(					unittest.TestCase):







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Union[str, Any]					):
										lowercase_      :    Any       		= 0







			@slow
			def 			SCREAMING_SNAKE_CASE_  (			self       :						List[Any]					):
										for model_name in (x for x in BERT_PRETRAINED_CONFIG_ARCHIVE_MAP.keys() if "japanese" not in x):
																	lowercase_      :    Tuple       		= AutoTokenizer.from_pretrained(lowercase_					)
																	self.assertIsNotNone(lowercase_					)
																	self.assertIsInstance(lowercase_       ,    (BertTokenizer, BertTokenizerFast)					)
																	self.assertGreater(len(lowercase_					)       ,    0					)

										for model_name in GPT2_PRETRAINED_CONFIG_ARCHIVE_MAP.keys():
																	lowercase_      :    str       		= AutoTokenizer.from_pretrained(lowercase_					)
																	self.assertIsNotNone(lowercase_					)
																	self.assertIsInstance(lowercase_       ,    (GPTaTokenizer, GPTaTokenizerFast)					)
																	self.assertGreater(len(lowercase_					)       ,    0					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[Any]					):
										lowercase_      :    Union[str, Any]       		= AutoTokenizer.from_pretrained(lowercase_					)
										self.assertIsInstance(lowercase_       ,    (BertTokenizer, BertTokenizerFast)					)
										self.assertEqual(tokenizer.vocab_size       ,    12					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[Any]					):
										lowercase_      :    int       		= AutoTokenizer.from_pretrained(lowercase_					)
										self.assertIsInstance(lowercase_       ,    (RobertaTokenizer, RobertaTokenizerFast)					)
										self.assertEqual(tokenizer.vocab_size       ,    20					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[Any]					):
										lowercase_      :    List[Any]       		= AutoConfig.from_pretrained(lowercase_					)
										self.assertIsInstance(lowercase_       ,    lowercase_					)
										# Check that tokenizer_type ≠ model_type
										lowercase_      :    Union[str, Any]       		= AutoTokenizer.from_pretrained(lowercase_       ,    config=lowercase_					)
										self.assertIsInstance(lowercase_       ,    (BertTokenizer, BertTokenizerFast)					)
										self.assertEqual(tokenizer.vocab_size       ,    12					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Any					):
										with tempfile.TemporaryDirectory() as tmp_dir:
																	shutil.copy("""./tests/fixtures/vocab.txt"""       ,    os.path.join(lowercase_       ,    """vocab.txt"""					)					)

																	lowercase_      :    Dict       		= AutoTokenizer.from_pretrained(lowercase_       ,    tokenizer_type="""bert"""       ,    use_fast=lowercase_					)
																	self.assertIsInstance(lowercase_       ,    lowercase_					)

										with tempfile.TemporaryDirectory() as tmp_dir:
																	shutil.copy("""./tests/fixtures/vocab.json"""       ,    os.path.join(lowercase_       ,    """vocab.json"""					)					)
																	shutil.copy("""./tests/fixtures/merges.txt"""       ,    os.path.join(lowercase_       ,    """merges.txt"""					)					)

																	lowercase_      :    Union[str, Any]       		= AutoTokenizer.from_pretrained(lowercase_       ,    tokenizer_type="""gpt2"""       ,    use_fast=lowercase_					)
																	self.assertIsInstance(lowercase_       ,    lowercase_					)







			@require_tokenizers
			def 			SCREAMING_SNAKE_CASE_  (			self       :						Tuple					):
										with tempfile.TemporaryDirectory() as tmp_dir:
																	shutil.copy("""./tests/fixtures/vocab.txt"""       ,    os.path.join(lowercase_       ,    """vocab.txt"""					)					)

																	lowercase_      :    Union[str, Any]       		= AutoTokenizer.from_pretrained(lowercase_       ,    tokenizer_type="""bert"""					)
																	self.assertIsInstance(lowercase_       ,    lowercase_					)

										with tempfile.TemporaryDirectory() as tmp_dir:
																	shutil.copy("""./tests/fixtures/vocab.json"""       ,    os.path.join(lowercase_       ,    """vocab.json"""					)					)
																	shutil.copy("""./tests/fixtures/merges.txt"""       ,    os.path.join(lowercase_       ,    """merges.txt"""					)					)

																	lowercase_      :    Tuple       		= AutoTokenizer.from_pretrained(lowercase_       ,    tokenizer_type="""gpt2"""					)
																	self.assertIsInstance(lowercase_       ,    lowercase_					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[Any]					):
										with pytest.raises(lowercase_					):
																	AutoTokenizer.from_pretrained("""./"""       ,    tokenizer_type="""xxx"""					)







			@require_tokenizers
			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[int]					):
										for tokenizer_class in [BertTokenizer, BertTokenizerFast, AutoTokenizer]:
																	lowercase_      :    Dict       		= tokenizer_class.from_pretrained("""wietsedv/bert-base-dutch-cased"""					)
																	self.assertIsInstance(lowercase_       ,    (BertTokenizer, BertTokenizerFast)					)

																	if isinstance(lowercase_       ,    lowercase_					):
																								self.assertEqual(tokenizer.basic_tokenizer.do_lower_case       ,    lowercase_					)
																	else:
																								self.assertEqual(tokenizer.do_lower_case       ,    lowercase_					)

																	self.assertEqual(tokenizer.model_max_length       ,    512					)







			@require_tokenizers
			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[Any]					):
										for tokenizer_class in [BertTokenizer, BertTokenizerFast, AutoTokenizer]:
																	with self.assertRaisesRegex(
																	    lowercase_       ,    """julien-c/herlolip-not-exists is not a local folder and is not a valid model identifier"""       ,    ):
																								lowercase_      :    Union[str, Any]       		= tokenizer_class.from_pretrained("""julien-c/herlolip-not-exists"""					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Dict					):
										# tests: https://github.com/huggingface/transformers/pull/13251
										# 1. models with `-`, e.g. xlm-roberta -> xlm_roberta
										# 2. models that don't remap 1-1 from model-name to model file, e.g., openai-gpt -> openai
										lowercase_      :    Union[str, Any]       		= TOKENIZER_MAPPING.values()
										lowercase_      :    Union[str, Any]       		= []

										for slow_tok, fast_tok in tokenizers:
																	if slow_tok is not None:
																								tokenizer_names.append(slow_tok.__name__					)

																	if fast_tok is not None:
																								tokenizer_names.append(fast_tok.__name__					)

										for tokenizer_name in tokenizer_names:
																	# must find the right class
																	tokenizer_class_from_name(lowercase_					)







			@require_tokenizers
			def 			SCREAMING_SNAKE_CASE_  (			self       :						Tuple					):
										self.assertIsInstance(AutoTokenizer.from_pretrained("""bert-base-cased"""       ,    use_fast=lowercase_					)       ,    lowercase_					)
										self.assertIsInstance(AutoTokenizer.from_pretrained("""bert-base-cased"""					)       ,    lowercase_					)







			@require_tokenizers
			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[int]					):
										lowercase_      :    List[str]       		= AutoTokenizer.from_pretrained("""distilbert-base-uncased"""       ,    do_lower_case=lowercase_					)
										lowercase_      :    Union[str, Any]       		= """Hello, world. How are you?"""
										lowercase_      :    Optional[Any]       		= tokenizer.tokenize(lowercase_					)
										self.assertEqual("""[UNK]"""       ,    tokens[0]					)

										lowercase_      :    Optional[int]       		= AutoTokenizer.from_pretrained("""microsoft/mpnet-base"""       ,    do_lower_case=lowercase_					)
										lowercase_      :    Optional[int]       		= tokenizer.tokenize(lowercase_					)
										self.assertEqual("""[UNK]"""       ,    tokens[0]					)







			@require_tokenizers
			def 			SCREAMING_SNAKE_CASE_  (			self       :						Dict					):
										lowercase_      :    List[str]       		= AutoTokenizer.from_pretrained("""robot-test/dummy-tokenizer-fast-with-model-config"""					)
										self.assertEqual(type(lowercase_					)       ,    lowercase_					)
										self.assertEqual(tokenizer.model_max_length       ,    512					)
										self.assertEqual(tokenizer.vocab_size       ,    30000					)
										self.assertEqual(tokenizer.unk_token       ,    """[UNK]"""					)
										self.assertEqual(tokenizer.padding_side       ,    """right"""					)
										self.assertEqual(tokenizer.truncation_side       ,    """right"""					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[Any]					):
										lowercase_      :    Tuple       		= AutoTokenizer.from_pretrained(lowercase_					)
										self.assertIsInstance(lowercase_       ,    (BertTokenizer, BertTokenizerFast)					)
										with tempfile.TemporaryDirectory() as tmp_dir:
																	tokenizer.save_pretrained(lowercase_					)
																	lowercase_      :    Union[str, Any]       		= AutoTokenizer.from_pretrained(lowercase_					)

										self.assertIsInstance(lowercase_       ,    tokenizer.__class__					)
										self.assertEqual(tokenizera.vocab_size       ,    12					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Tuple					):
										lowercase_      :    int       		= AutoTokenizer.from_pretrained("""ctrl"""					)
										# There is no fast CTRL so this always gives us a slow tokenizer.
										self.assertIsInstance(lowercase_       ,    lowercase_					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						List[str]					):
										# Check we can load the tokenizer config of an online model.
										lowercase_      :    str       		= get_tokenizer_config("""bert-base-cased"""					)
										lowercase_      :    Optional[Any]       		= config.pop("""_commit_hash"""       ,    lowercase_					)
										# If we ever update bert-base-cased tokenizer config, this dict here will need to be updated.
										self.assertEqual(lowercase_       ,    {"""do_lower_case""": False}					)

										# This model does not have a tokenizer_config so we get back an empty dict.
										lowercase_      :    Optional[Any]       		= get_tokenizer_config(lowercase_					)
										self.assertDictEqual(lowercase_       ,    {}					)

										# A tokenizer saved with `save_pretrained` always creates a tokenizer config.
										lowercase_      :    Optional[int]       		= AutoTokenizer.from_pretrained(lowercase_					)
										with tempfile.TemporaryDirectory() as tmp_dir:
																	tokenizer.save_pretrained(lowercase_					)
																	lowercase_      :    Tuple       		= get_tokenizer_config(lowercase_					)

										# Check the class of the tokenizer was properly saved (note that it always saves the slow class).
										self.assertEqual(config["""tokenizer_class"""]       ,    """BertTokenizer"""					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						List[Any]					):
										try:
																	AutoConfig.register("""custom"""       ,    lowercase_					)

																	AutoTokenizer.register(lowercase_       ,    slow_tokenizer_class=lowercase_					)
																	# Trying to register something existing in the Transformers library will raise an error
																	with self.assertRaises(lowercase_					):
																								AutoTokenizer.register(lowercase_       ,    slow_tokenizer_class=lowercase_					)

																	lowercase_      :    int       		= CustomTokenizer.from_pretrained(lowercase_					)
																	with tempfile.TemporaryDirectory() as tmp_dir:
																								tokenizer.save_pretrained(lowercase_					)

																								lowercase_      :    str       		= AutoTokenizer.from_pretrained(lowercase_					)
																								self.assertIsInstance(lowercase_       ,    lowercase_					)

										finally:
																	if "custom" in CONFIG_MAPPING._extra_content:
																								del CONFIG_MAPPING._extra_content["custom"]
																	if CustomConfig in TOKENIZER_MAPPING._extra_content:
																								del TOKENIZER_MAPPING._extra_content[CustomConfig]







			@require_tokenizers
			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[Any]					):
										try:
																	AutoConfig.register("""custom"""       ,    lowercase_					)

																	# Can register in two steps
																	AutoTokenizer.register(lowercase_       ,    slow_tokenizer_class=lowercase_					)
																	self.assertEqual(TOKENIZER_MAPPING[CustomConfig]       ,    (CustomTokenizer, None)					)
																	AutoTokenizer.register(lowercase_       ,    fast_tokenizer_class=lowercase_					)
																	self.assertEqual(TOKENIZER_MAPPING[CustomConfig]       ,    (CustomTokenizer, CustomTokenizerFast)					)

																	del TOKENIZER_MAPPING._extra_content[CustomConfig]
																	# Can register in one step
																	AutoTokenizer.register(
																	    lowercase_       ,    slow_tokenizer_class=lowercase_       ,    fast_tokenizer_class=lowercase_					)
																	self.assertEqual(TOKENIZER_MAPPING[CustomConfig]       ,    (CustomTokenizer, CustomTokenizerFast)					)

																	# Trying to register something existing in the Transformers library will raise an error
																	with self.assertRaises(lowercase_					):
																								AutoTokenizer.register(lowercase_       ,    fast_tokenizer_class=lowercase_					)

																	# We pass through a bert tokenizer fast cause there is no converter slow to fast for our new toknizer
																	# and that model does not have a tokenizer.json
																	with tempfile.TemporaryDirectory() as tmp_dir:
																								lowercase_      :    Union[str, Any]       		= BertTokenizerFast.from_pretrained(lowercase_					)
																								bert_tokenizer.save_pretrained(lowercase_					)
																								lowercase_      :    Dict       		= CustomTokenizerFast.from_pretrained(lowercase_					)

																	with tempfile.TemporaryDirectory() as tmp_dir:
																								tokenizer.save_pretrained(lowercase_					)

																								lowercase_      :    int       		= AutoTokenizer.from_pretrained(lowercase_					)
																								self.assertIsInstance(lowercase_       ,    lowercase_					)

																								lowercase_      :    List[str]       		= AutoTokenizer.from_pretrained(lowercase_       ,    use_fast=lowercase_					)
																								self.assertIsInstance(lowercase_       ,    lowercase_					)

										finally:
																	if "custom" in CONFIG_MAPPING._extra_content:
																								del CONFIG_MAPPING._extra_content["custom"]
																	if CustomConfig in TOKENIZER_MAPPING._extra_content:
																								del TOKENIZER_MAPPING._extra_content[CustomConfig]







			def 			SCREAMING_SNAKE_CASE_  (			self       :						int					):
										# If remote code is not set, we will time out when asking whether to load the model.
										with self.assertRaises(lowercase_					):
																	lowercase_      :    int       		= AutoTokenizer.from_pretrained("""hf-internal-testing/test_dynamic_tokenizer"""					)
										# If remote code is disabled, we can't load this config.
										with self.assertRaises(lowercase_					):
																	lowercase_      :    Dict       		= AutoTokenizer.from_pretrained(
																	    """hf-internal-testing/test_dynamic_tokenizer"""       ,    trust_remote_code=lowercase_					)

										lowercase_      :    Any       		= AutoTokenizer.from_pretrained("""hf-internal-testing/test_dynamic_tokenizer"""       ,    trust_remote_code=lowercase_					)
										self.assertTrue(tokenizer.special_attribute_present					)
										# Test tokenizer can be reloaded.
										with tempfile.TemporaryDirectory() as tmp_dir:
																	tokenizer.save_pretrained(lowercase_					)
																	lowercase_      :    List[Any]       		= AutoTokenizer.from_pretrained(lowercase_       ,    trust_remote_code=lowercase_					)
										self.assertTrue(reloaded_tokenizer.special_attribute_present					)

										if is_tokenizers_available():
																	self.assertEqual(tokenizer.__class__.__name__       ,    """NewTokenizerFast"""					)
																	self.assertEqual(reloaded_tokenizer.__class__.__name__       ,    """NewTokenizerFast"""					)

																	# Test we can also load the slow version
																	lowercase_      :    List[Any]       		= AutoTokenizer.from_pretrained(
																	    """hf-internal-testing/test_dynamic_tokenizer"""       ,    trust_remote_code=lowercase_       ,    use_fast=lowercase_					)
																	self.assertTrue(tokenizer.special_attribute_present					)
																	self.assertEqual(tokenizer.__class__.__name__       ,    """NewTokenizer"""					)
																	# Test tokenizer can be reloaded.
																	with tempfile.TemporaryDirectory() as tmp_dir:
																								tokenizer.save_pretrained(lowercase_					)
																								lowercase_      :    Optional[Any]       		= AutoTokenizer.from_pretrained(lowercase_       ,    trust_remote_code=lowercase_       ,    use_fast=lowercase_					)
																	self.assertEqual(reloaded_tokenizer.__class__.__name__       ,    """NewTokenizer"""					)
																	self.assertTrue(reloaded_tokenizer.special_attribute_present					)
										else:
																	self.assertEqual(tokenizer.__class__.__name__       ,    """NewTokenizer"""					)
																	self.assertEqual(reloaded_tokenizer.__class__.__name__       ,    """NewTokenizer"""					)







			@require_tokenizers
			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[int]					):





										class 					__magic_name__		(					_UpperCAmelCase):
													UpperCamelCase__       = False





										class 					__magic_name__		(					_UpperCAmelCase):
													UpperCamelCase__       = NewTokenizer
													UpperCamelCase__       = False

										try:
																	AutoConfig.register("""custom"""       ,    lowercase_					)
																	AutoTokenizer.register(lowercase_       ,    slow_tokenizer_class=lowercase_					)
																	AutoTokenizer.register(lowercase_       ,    fast_tokenizer_class=lowercase_					)
																	# If remote code is not set, the default is to use local
																	lowercase_      :    Dict       		= AutoTokenizer.from_pretrained("""hf-internal-testing/test_dynamic_tokenizer"""					)
																	self.assertEqual(tokenizer.__class__.__name__       ,    """NewTokenizerFast"""					)
																	self.assertFalse(tokenizer.special_attribute_present					)
																	lowercase_      :    str       		= AutoTokenizer.from_pretrained("""hf-internal-testing/test_dynamic_tokenizer"""       ,    use_fast=lowercase_					)
																	self.assertEqual(tokenizer.__class__.__name__       ,    """NewTokenizer"""					)
																	self.assertFalse(tokenizer.special_attribute_present					)

																	# If remote code is disabled, we load the local one.
																	lowercase_      :    Optional[int]       		= AutoTokenizer.from_pretrained(
																	    """hf-internal-testing/test_dynamic_tokenizer"""       ,    trust_remote_code=lowercase_					)
																	self.assertEqual(tokenizer.__class__.__name__       ,    """NewTokenizerFast"""					)
																	self.assertFalse(tokenizer.special_attribute_present					)
																	lowercase_      :    List[Any]       		= AutoTokenizer.from_pretrained(
																	    """hf-internal-testing/test_dynamic_tokenizer"""       ,    trust_remote_code=lowercase_       ,    use_fast=lowercase_					)
																	self.assertEqual(tokenizer.__class__.__name__       ,    """NewTokenizer"""					)
																	self.assertFalse(tokenizer.special_attribute_present					)

																	# If remote is enabled, we load from the Hub
																	lowercase_      :    Union[str, Any]       		= AutoTokenizer.from_pretrained(
																	    """hf-internal-testing/test_dynamic_tokenizer"""       ,    trust_remote_code=lowercase_					)
																	self.assertEqual(tokenizer.__class__.__name__       ,    """NewTokenizerFast"""					)
																	self.assertTrue(tokenizer.special_attribute_present					)
																	lowercase_      :    Tuple       		= AutoTokenizer.from_pretrained(
																	    """hf-internal-testing/test_dynamic_tokenizer"""       ,    trust_remote_code=lowercase_       ,    use_fast=lowercase_					)
																	self.assertEqual(tokenizer.__class__.__name__       ,    """NewTokenizer"""					)
																	self.assertTrue(tokenizer.special_attribute_present					)

										finally:
																	if "custom" in CONFIG_MAPPING._extra_content:
																								del CONFIG_MAPPING._extra_content["custom"]
																	if CustomConfig in TOKENIZER_MAPPING._extra_content:
																								del TOKENIZER_MAPPING._extra_content[CustomConfig]







			def 			SCREAMING_SNAKE_CASE_  (			self       :						str					):
										lowercase_      :    Optional[int]       		= AutoTokenizer.from_pretrained(
										    """hf-internal-testing/test_dynamic_tokenizer_legacy"""       ,    trust_remote_code=lowercase_					)
										self.assertTrue(tokenizer.special_attribute_present					)
										if is_tokenizers_available():
																	self.assertEqual(tokenizer.__class__.__name__       ,    """NewTokenizerFast"""					)

																	# Test we can also load the slow version
																	lowercase_      :    Any       		= AutoTokenizer.from_pretrained(
																	    """hf-internal-testing/test_dynamic_tokenizer_legacy"""       ,    trust_remote_code=lowercase_       ,    use_fast=lowercase_					)
																	self.assertTrue(tokenizer.special_attribute_present					)
																	self.assertEqual(tokenizer.__class__.__name__       ,    """NewTokenizer"""					)
										else:
																	self.assertEqual(tokenizer.__class__.__name__       ,    """NewTokenizer"""					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Any					):
										with self.assertRaisesRegex(
										    lowercase_       ,    """bert-base is not a local folder and is not a valid model identifier"""					):
																	lowercase_      :    Optional[int]       		= AutoTokenizer.from_pretrained("""bert-base"""					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						List[str]					):
										with self.assertRaisesRegex(
										    lowercase_       ,    r"""aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"""					):
																	lowercase_      :    List[str]       		= AutoTokenizer.from_pretrained(lowercase_       ,    revision="""aaaaaa"""					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[Any]					):
										# Make sure we have cached the tokenizer.
										lowercase_      :    Optional[int]       		= AutoTokenizer.from_pretrained("""hf-internal-testing/tiny-random-bert"""					)
										with RequestCounter() as counter:
																	lowercase_      :    Dict       		= AutoTokenizer.from_pretrained("""hf-internal-testing/tiny-random-bert"""					)
																	self.assertEqual(counter.get_request_count       ,    0					)
																	self.assertEqual(counter.head_request_count       ,    1					)
																	self.assertEqual(counter.other_request_count       ,    0					)






'''simple docstring'''




from ...configuration_utils import PretrainedConfig
from ...utils import logging


_lowercase		:				Optional[Any]	       =		logging.get_logger(__name__)

_lowercase		:				Union[str, Any]	       =		{
    "facebook/s2t-small-librispeech-asr": (
        "https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/config.json"
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech_to_text
}





class 					__magic_name__		(					_UpperCAmelCase):
			UpperCamelCase__       = '''speech_to_text'''
			UpperCamelCase__       = ['''past_key_values''']
			UpperCamelCase__       = {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}







			def __init__(			self       :						str       ,    lowercase_       :						Optional[int]=10000       ,    lowercase_       :						int=12       ,    lowercase_       :						Any=2048       ,    lowercase_       :						Any=4       ,    lowercase_       :						Dict=6       ,    lowercase_       :						Any=2048       ,    lowercase_       :						List[str]=4       ,    lowercase_       :						str=0.0       ,    lowercase_       :						str=0.0       ,    lowercase_       :						Union[str, Any]=True       ,    lowercase_       :						List[Any]=True       ,    lowercase_       :						int="relu"       ,    lowercase_       :						str=256       ,    lowercase_       :						int=0.1       ,    lowercase_       :						int=0.0       ,    lowercase_       :						str=0.0       ,    lowercase_       :						Optional[int]=0.02       ,    lowercase_       :						str=2       ,    lowercase_       :						Union[str, Any]=True       ,    lowercase_       :						Any=1       ,    lowercase_       :						Dict=0       ,    lowercase_       :						List[str]=2       ,    lowercase_       :						List[Any]=6000       ,    lowercase_       :						Tuple=1024       ,    lowercase_       :						str=2       ,    lowercase_       :						Any=(5, 5)       ,    lowercase_       :						Union[str, Any]=1024       ,    lowercase_       :						Dict=80       ,    lowercase_       :						List[Any]=1       ,    **lowercase_       :						int       ,    ):
										lowercase_      :    List[Any]       		= vocab_size
										lowercase_      :    str       		= d_model
										lowercase_      :    List[Any]       		= encoder_ffn_dim
										lowercase_      :    str       		= encoder_layers
										lowercase_      :    Dict       		= encoder_attention_heads
										lowercase_      :    str       		= decoder_ffn_dim
										lowercase_      :    int       		= decoder_layers
										lowercase_      :    Any       		= decoder_attention_heads
										lowercase_      :    Any       		= dropout
										lowercase_      :    Dict       		= attention_dropout
										lowercase_      :    Optional[int]       		= activation_dropout
										lowercase_      :    Any       		= activation_function
										lowercase_      :    Union[str, Any]       		= init_std
										lowercase_      :    str       		= encoder_layerdrop
										lowercase_      :    Optional[int]       		= decoder_layerdrop
										lowercase_      :    Dict       		= use_cache
										lowercase_      :    Union[str, Any]       		= encoder_layers
										lowercase_      :    Tuple       		= scale_embedding  # scale factor will be sqrt(d_model) if True
										lowercase_      :    Dict       		= max_source_positions
										lowercase_      :    Optional[int]       		= max_target_positions
										lowercase_      :    Tuple       		= num_conv_layers
										lowercase_      :    Tuple       		= list(lowercase_					)
										lowercase_      :    Union[str, Any]       		= conv_channels
										lowercase_      :    str       		= input_feat_per_channel
										lowercase_      :    str       		= input_channels

										if len(self.conv_kernel_sizes					) != self.num_conv_layers:
																	raise ValueError(
																	    """Configuration for convolutional module is incorrect. """
																	    """It is required that `len(config.conv_kernel_sizes)` == `config.num_conv_layers` """
																	    f'''but is `len(config.conv_kernel_sizes) = {len(self.conv_kernel_sizes					)}`, '''
																	    f'''`config.num_conv_layers = {self.num_conv_layers}`.'''					)

										super().__init__(
										    pad_token_id=lowercase_       ,    bos_token_id=lowercase_       ,    eos_token_id=lowercase_       ,    is_encoder_decoder=lowercase_       ,    decoder_start_token_id=lowercase_       ,    **lowercase_       ,    )





