
"""simple docstring"""




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


A__   :					Any							=   logging.get_logger(__name__)

A__   :					Tuple							=   {
    '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__       (       SCREAMING_SNAKE_CASE__ ):
       UpperCamelCase_   =		'''speech_to_text'''
       UpperCamelCase_   =		['''past_key_values''']
       UpperCamelCase_   =		{'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}
       def __init__(     self ,				A_=1_0000 ,				A_=12 ,				A_=2048 ,				A_=4 ,				A_=6 ,				A_=2048 ,				A_=4 ,				A_=0.0 ,				A_=0.0 ,				A_=True ,				A_=True ,				A_="relu" ,				A_=256 ,				A_=0.1 ,				A_=0.0 ,				A_=0.0 ,				A_=0.02 ,				A_=2 ,				A_=True ,				A_=1 ,				A_=0 ,				A_=2 ,				A_=6000 ,				A_=1024 ,				A_=2 ,				A_=(5, 5) ,				A_=1024 ,				A_=80 ,				A_=1 ,				**A_ ,				)     ->	Optional[Any]:





         """simple docstring"""




         _lowercase       =     vocab_size
         _lowercase       =     d_model
         _lowercase       =     encoder_ffn_dim
         _lowercase       =     encoder_layers
         _lowercase       =     encoder_attention_heads
         _lowercase       =     decoder_ffn_dim
         _lowercase       =     decoder_layers
         _lowercase       =     decoder_attention_heads
         _lowercase       =     dropout
         _lowercase       =     attention_dropout
         _lowercase       =     activation_dropout
         _lowercase       =     activation_function
         _lowercase       =     init_std
         _lowercase       =     encoder_layerdrop
         _lowercase       =     decoder_layerdrop
         _lowercase       =     use_cache
         _lowercase       =     encoder_layers
         _lowercase       =     scale_embedding  # scale factor will be sqrt(d_model) if True
         _lowercase       =     max_source_positions
         _lowercase       =     max_target_positions
         _lowercase       =     num_conv_layers
         _lowercase       =     list(A_       )
         _lowercase       =     conv_channels
         _lowercase       =     input_feat_per_channel
         _lowercase       =     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=A_ ,				bos_token_id=A_ ,				eos_token_id=A_ ,				is_encoder_decoder=A_ ,				decoder_start_token_id=A_ ,				**A_ ,				)


"""simple docstring"""




import json
import os
import tempfile
import unittest
import unittest.mock as mock
from pathlib import Path

from requests.exceptions import HTTPError

from transformers.utils import (
    CONFIG_NAME,
    FLAX_WEIGHTS_NAME,
    TF2_WEIGHTS_NAME,
    TRANSFORMERS_CACHE,
    WEIGHTS_NAME,
    cached_file,
    get_file_from_repo,
    has_file,
)


A__   :					Any							=   'hf-internal-testing/tiny-random-bert'
A__   :					int							=   os.path.join(TRANSFORMERS_CACHE, 'models--hf-internal-testing--tiny-random-bert')
A__   :					Dict							=   '9b8c223d42b2188cb49d29af482996f9d0f3e5a6'


class 			__magic_name__       (       unittest.TestCase ):
       def 							lowercase_							(     self       )     ->	str:





         """simple docstring"""




         _lowercase:			Dict       =     cached_file(A_ ,				A_       )
         # Should have downloaded the file in here
         self.assertTrue(os.path.isdir(A_       )       )
         # Cache should contain at least those three subfolders:
         for subfolder in ["blobs", "refs", "snapshots"]:
           self.assertTrue(os.path.isdir(os.path.join(A_ ,				A_       )       )       )
         with open(os.path.join(A_ ,				'''refs''' ,				'''main'''       )       ) as f:
           _lowercase:			Tuple       =     f.read()
         self.assertEqual(A_ ,				os.path.join(A_ ,				'''snapshots''' ,				A_ ,				A_       )       )
         self.assertTrue(os.path.isfile(A_       )       )

         # File is cached at the same place the second time.
         _lowercase:			List[Any]       =     cached_file(A_ ,				A_       )
         self.assertEqual(A_ ,				A_       )

         # Using a specific revision to test the full commit hash.
         _lowercase:			Union[str, Any]       =     cached_file(A_ ,				A_ ,				revision='''9b8c223'''       )
         self.assertEqual(A_ ,				os.path.join(A_ ,				'''snapshots''' ,				A_ ,				A_       )       )
       def 							lowercase_							(     self       )     ->	Optional[Any]:





         """simple docstring"""




         with self.assertRaisesRegex(A_ ,				'''is not a valid model identifier'''       ):
           _lowercase:			Union[str, Any]       =     cached_file('''tiny-random-bert''' ,				A_       )

         with self.assertRaisesRegex(A_ ,				'''is not a valid git identifier'''       ):
           _lowercase:			List[Any]       =     cached_file(A_ ,				A_ ,				revision='''aaaa'''       )

         with self.assertRaisesRegex(A_ ,				'''does not appear to have a file named'''       ):
           _lowercase:			int       =     cached_file(A_ ,				'''conf'''       )
       def 							lowercase_							(     self       )     ->	Optional[int]:





         """simple docstring"""




         with self.assertRaisesRegex(A_ ,				'''does not appear to have a file named'''       ):
           _lowercase:			Dict       =     cached_file(A_ ,				'''conf'''       )

         with open(os.path.join(A_ ,				'''refs''' ,				'''main'''       )       ) as f:
           _lowercase:			int       =     f.read()
         self.assertTrue(os.path.isfile(os.path.join(A_ ,				'''.no_exist''' ,				A_ ,				'''conf'''       )       )       )

         _lowercase:			Optional[int]       =     cached_file(A_ ,				'''conf''' ,				_raise_exceptions_for_missing_entries=A_       )
         self.assertIsNone(A_       )

         _lowercase:			Optional[int]       =     cached_file(A_ ,				'''conf''' ,				local_files_only=A_ ,				_raise_exceptions_for_missing_entries=A_       )
         self.assertIsNone(A_       )

         _lowercase:			Optional[Any]       =     mock.Mock()
         _lowercase:			Optional[Any]       =     500
         _lowercase:			Optional[Any]       =     {}
         _lowercase:			Dict       =     HTTPError
         _lowercase:			Optional[Any]       =     {}

         # Under the mock environment we get a 500 error when trying to reach the tokenizer.
         with mock.patch('''requests.Session.request''' ,				return_value=A_       ) as mock_head:
           _lowercase:			Tuple       =     cached_file(A_ ,				'''conf''' ,				_raise_exceptions_for_connection_errors=A_       )
           self.assertIsNone(A_       )
           # This check we did call the fake head request
           mock_head.assert_called()
       def 							lowercase_							(     self       )     ->	str:





         """simple docstring"""




         self.assertTrue(has_file('''hf-internal-testing/tiny-bert-pt-only''' ,				A_       )       )
         self.assertFalse(has_file('''hf-internal-testing/tiny-bert-pt-only''' ,				A_       )       )
         self.assertFalse(has_file('''hf-internal-testing/tiny-bert-pt-only''' ,				A_       )       )
       def 							lowercase_							(     self       )     ->	Tuple:





         """simple docstring"""




         self.assertIsNone(get_file_from_repo('''bert-base-cased''' ,				'''ahah.txt'''       )       )

         # The function raises if the repository does not exist.
         with self.assertRaisesRegex(A_ ,				'''is not a valid model identifier'''       ):
           get_file_from_repo('''bert-base-case''' ,				A_       )

         # The function raises if the revision does not exist.
         with self.assertRaisesRegex(A_ ,				'''is not a valid git identifier'''       ):
           get_file_from_repo('''bert-base-cased''' ,				A_ ,				revision='''ahaha'''       )

         _lowercase:			Optional[int]       =     get_file_from_repo('''bert-base-cased''' ,				A_       )
         # The name is the cached name which is not very easy to test, so instead we load the content.
         _lowercase:			Union[str, Any]       =     json.loads(open(A_ ,				'''r'''       ).read()       )
         self.assertEqual(config['''hidden_size'''] ,				768       )



       def 							lowercase_							(     self       )     ->	Tuple:





         """simple docstring"""




         with tempfile.TemporaryDirectory() as tmp_dir:
           _lowercase:			List[Any]       =     Path(A_       ) / '''a.txt'''
           filename.touch()
           self.assertEqual(get_file_from_repo(A_ ,				'''a.txt'''       ) ,				str(A_       )       )

           self.assertIsNone(get_file_from_repo(A_ ,				'''b.txt'''       )       )
