



import contextlib
import importlib
import io
import unittest

import transformers

# Try to import everything from transformers to ensure every object can be loaded.
from transformers import *  # noqa F406
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_flax, require_tf, require_torch
from transformers.utils import ContextManagers, find_labels, is_flax_available, is_tf_available, is_torch_available


if is_torch_available():
    from transformers import BertForPreTraining, BertForQuestionAnswering, BertForSequenceClassification

if is_tf_available():
    from transformers import TFBertForPreTraining, TFBertForQuestionAnswering, TFBertForSequenceClassification

if is_flax_available():
    from transformers import FlaxBertForPreTraining, FlaxBertForQuestionAnswering, FlaxBertForSequenceClassification


__UpperCAmelCase          =       DUMMY_UNKNOWN_IDENTIFIER
# An actual model hosted on huggingface.co

__UpperCAmelCase          =       '''main'''
# Default branch name
__UpperCAmelCase          =       '''f2c752cfc5c0ab6f4bdec59acea69eefbee381c2'''
# One particular commit (not the top of `main`)
__UpperCAmelCase          =       '''aaaaaaa'''
# This commit does not exist, so we should 404.

__UpperCAmelCase          =       '''d9e9f15bc825e4b2c9249e9578f884bbcb5e3684'''
# Sha-1 of config.json on the top of `main`, for checking purposes
__UpperCAmelCase          =       '''4b243c475af8d0a7754e87d7d096c92e5199ec2fe168a2ee7998e3b8e9bcb1d3'''
@contextlib.contextmanager
def 		UpperCamelCase	(   )	->     Tuple:
   print('Welcome!'	)
   yield
   print('Bye!'	)
@contextlib.contextmanager
def 		UpperCamelCase	(   )	->     List[Any]:
   print('Bonjour!'	)
   yield
   print('Au revoir!'	)



class 				lowerCAmelCase_		(  unittest.TestCase							):
       def 					snake_case_       (			self       )     ->		Any:
          # If the spec is missing, importlib would not be able to import the module dynamically.
          assert transformers.__spec__ is not None
          assert importlib.util.find_spec('transformers'       ) is not None






class 				lowerCAmelCase_		(  unittest.TestCase							):
       @unittest.mock.patch('sys.stdout',			new_callable=io.StringIO       )
       def 					snake_case_       (			self,			SCREAMING_SNAKE_CASE_       )     ->		List[str]:
          with ContextManagers([]       ):
             print('Transformers are awesome!'       )
          # The print statement adds a new line at the end of the output
          self.assertEqual(mock_stdout.getvalue(),			'Transformers are awesome!\n'       )
       @unittest.mock.patch('sys.stdout',			new_callable=io.StringIO       )
       def 					snake_case_       (			self,			SCREAMING_SNAKE_CASE_       )     ->		List[Any]:
          with ContextManagers([context_en()]       ):
             print('Transformers are awesome!'       )
          # The output should be wrapped with an English welcome and goodbye
          self.assertEqual(mock_stdout.getvalue(),			'Welcome!\nTransformers are awesome!\nBye!\n'       )
       @unittest.mock.patch('sys.stdout',			new_callable=io.StringIO       )
       def 					snake_case_       (			self,			SCREAMING_SNAKE_CASE_       )     ->		str:
          with ContextManagers([context_fr(), context_en()]       ):
             print('Transformers are awesome!'       )
          # The output should be wrapped with an English and French welcome and goodbye
          self.assertEqual(mock_stdout.getvalue(),			'Bonjour!\nWelcome!\nTransformers are awesome!\nBye!\nAu revoir!\n'       )
       @require_torch
       def 					snake_case_       (			self       )     ->		Union[str, Any]:
          self.assertEqual(find_labels(SCREAMING_SNAKE_CASE_       ),			['labels']       )
          self.assertEqual(find_labels(SCREAMING_SNAKE_CASE_       ),			['labels', 'next_sentence_label']       )
          self.assertEqual(find_labels(SCREAMING_SNAKE_CASE_       ),			['start_positions', 'end_positions']       )



          class 				lowerCAmelCase_		(  a__							):
                 pass






          self.assertEqual(find_labels(SCREAMING_SNAKE_CASE_       ),			['labels']       )
       @require_tf
       def 					snake_case_       (			self       )     ->		Optional[int]:
          self.assertEqual(find_labels(SCREAMING_SNAKE_CASE_       ),			['labels']       )
          self.assertEqual(find_labels(SCREAMING_SNAKE_CASE_       ),			['labels', 'next_sentence_label']       )
          self.assertEqual(find_labels(SCREAMING_SNAKE_CASE_       ),			['start_positions', 'end_positions']       )



          class 				lowerCAmelCase_		(  a__							):
                 pass






          self.assertEqual(find_labels(SCREAMING_SNAKE_CASE_       ),			['labels']       )






       @require_flax
       def 					snake_case_       (			self       )     ->		Tuple:
          # Flax models don't have labels
          self.assertEqual(find_labels(SCREAMING_SNAKE_CASE_       ),			[]       )
          self.assertEqual(find_labels(SCREAMING_SNAKE_CASE_       ),			[]       )
          self.assertEqual(find_labels(SCREAMING_SNAKE_CASE_       ),			[]       )



          class 				lowerCAmelCase_		(  a__							):
                 pass






          self.assertEqual(find_labels(SCREAMING_SNAKE_CASE_       ),			[]       )








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


__UpperCAmelCase          =       logging.get_logger(__name__)

__UpperCAmelCase          =       {
    '''facebook/s2t-wav2vec2-large-en-de''': (
        '''https://huggingface.co/facebook/s2t-wav2vec2-large-en-de/resolve/main/config.json'''
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech2text2
}



class 				lowerCAmelCase_		(  a__							):
       UpperCAmelCase__				:					Optional[Any]        =  "speech_to_text_2"
       UpperCAmelCase__				:					List[Any]        =  ["past_key_values"]
       UpperCAmelCase__				:					Any        =  {"num_attention_heads": "decoder_attention_heads", "hidden_size": "d_model"}
       def __init__(			self,			SCREAMING_SNAKE_CASE_=1_0000,			SCREAMING_SNAKE_CASE_=6,			SCREAMING_SNAKE_CASE_=2048,			SCREAMING_SNAKE_CASE_=4,			SCREAMING_SNAKE_CASE_=0.0,			SCREAMING_SNAKE_CASE_=True,			SCREAMING_SNAKE_CASE_="relu",			SCREAMING_SNAKE_CASE_=256,			SCREAMING_SNAKE_CASE_=0.1,			SCREAMING_SNAKE_CASE_=0.0,			SCREAMING_SNAKE_CASE_=0.0,			SCREAMING_SNAKE_CASE_=0.02,			SCREAMING_SNAKE_CASE_=2,			SCREAMING_SNAKE_CASE_=True,			SCREAMING_SNAKE_CASE_=1,			SCREAMING_SNAKE_CASE_=0,			SCREAMING_SNAKE_CASE_=2,			SCREAMING_SNAKE_CASE_=1024,			**SCREAMING_SNAKE_CASE_,			)     ->		int:
          UpperCamelCase    :  Optional[int]							=	vocab_size
          UpperCamelCase    :  List[str]							=	d_model
          UpperCamelCase    :  List[str]							=	decoder_ffn_dim
          UpperCamelCase    :  Optional[Any]							=	decoder_layers
          UpperCamelCase    :  Any							=	decoder_attention_heads
          UpperCamelCase    :  Tuple							=	dropout
          UpperCamelCase    :  str							=	attention_dropout
          UpperCamelCase    :  str							=	activation_dropout
          UpperCamelCase    :  Union[str, Any]							=	activation_function
          UpperCamelCase    :  Optional[int]							=	init_std
          UpperCamelCase    :  Tuple							=	decoder_layerdrop
          UpperCamelCase    :  Dict							=	use_cache
          UpperCamelCase    :  Any							=	decoder_layers
          UpperCamelCase    :  Union[str, Any]							=	scale_embedding  # scale factor will be sqrt(d_model) if True
          UpperCamelCase    :  Union[str, Any]							=	max_target_positions

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



