





'''simple docstring'''




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


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

lowercase__   :				List[Any]      =   {
    '''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 			SCREAMING_SNAKE_CASE   (__lowerCamelCase							):
					lowerCAmelCase		      =	'speech_to_text_2'
					lowerCAmelCase		      =	['past_key_values']
					lowerCAmelCase		      =	{'num_attention_heads': 'decoder_attention_heads', 'hidden_size': 'd_model'}


					def __init__(						self						,     _UpperCAmelCase=1_0000						,     _UpperCAmelCase=6						,     _UpperCAmelCase=2048						,     _UpperCAmelCase=4						,     _UpperCAmelCase=0.0						,     _UpperCAmelCase=True						,     _UpperCAmelCase="relu"						,     _UpperCAmelCase=256						,     _UpperCAmelCase=0.1						,     _UpperCAmelCase=0.0						,     _UpperCAmelCase=0.0						,     _UpperCAmelCase=0.02						,     _UpperCAmelCase=2						,     _UpperCAmelCase=True						,     _UpperCAmelCase=1						,     _UpperCAmelCase=0						,     _UpperCAmelCase=2						,     _UpperCAmelCase=1024						,     **_UpperCAmelCase						,     ):

										'''simple docstring'''






										__A						:			Any								=	vocab_size
										__A						:			int								=	d_model
										__A						:			Optional[int]								=	decoder_ffn_dim
										__A						:			List[str]								=	decoder_layers
										__A						:			int								=	decoder_attention_heads
										__A						:			List[str]								=	dropout
										__A						:			Tuple								=	attention_dropout
										__A						:			Union[str, Any]								=	activation_dropout
										__A						:			Optional[Any]								=	activation_function
										__A						:			Optional[int]								=	init_std
										__A						:			List[str]								=	decoder_layerdrop
										__A						:			Optional[Any]								=	use_cache
										__A						:			Any								=	decoder_layers
										__A						:			int								=	scale_embedding  # scale factor will be sqrt(d_model) if True
										__A						:			List[str]								=	max_target_positions

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






'''simple docstring'''




from tempfile import TemporaryDirectory
from unittest import TestCase
from unittest.mock import MagicMock, patch

from transformers import AutoModel, TFAutoModel
from transformers.onnx import FeaturesManager
from transformers.testing_utils import SMALL_MODEL_IDENTIFIER, require_tf, require_torch


@require_torch
@require_tf
class 			SCREAMING_SNAKE_CASE   (a__							):


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						:			Optional[int]								=	SMALL_MODEL_IDENTIFIER
          __A						:			Any								=	'pt'
          __A						:			str								=	'tf'


     def 							SCREAMING_SNAKE_CASE  (						self						,     _UpperCAmelCase):

          '''simple docstring'''






          __A						:			Any								=	AutoModel.from_pretrained(self.test_model)
          model_pt.save_pretrained(_UpperCAmelCase)


     def 							SCREAMING_SNAKE_CASE  (						self						,     _UpperCAmelCase):

          '''simple docstring'''






          __A						:			Union[str, Any]								=	TFAutoModel.from_pretrained(self.test_model						,     from_pt=_UpperCAmelCase)
          model_tf.save_pretrained(_UpperCAmelCase)


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						:			Union[str, Any]								=	'mock_framework'

          # Framework provided - return whatever the user provides
          __A						:			Union[str, Any]								=	FeaturesManager.determine_framework(self.test_model						,     _UpperCAmelCase)
          self.assertEqual(_UpperCAmelCase						,     _UpperCAmelCase)

          # Local checkpoint and framework provided - return provided framework
          # PyTorch checkpoint
          with TemporaryDirectory() as local_pt_ckpt:
               self._setup_pt_ckpt(_UpperCAmelCase)
               __A						:			List[str]								=	FeaturesManager.determine_framework(_UpperCAmelCase						,     _UpperCAmelCase)
               self.assertEqual(_UpperCAmelCase						,     _UpperCAmelCase)

          # TensorFlow checkpoint
          with TemporaryDirectory() as local_tf_ckpt:
               self._setup_tf_ckpt(_UpperCAmelCase)
               __A						:			Tuple								=	FeaturesManager.determine_framework(_UpperCAmelCase						,     _UpperCAmelCase)
               self.assertEqual(_UpperCAmelCase						,     _UpperCAmelCase)


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          with TemporaryDirectory() as local_pt_ckpt:
               self._setup_pt_ckpt(_UpperCAmelCase)
               __A						:			Optional[int]								=	FeaturesManager.determine_framework(_UpperCAmelCase)
               self.assertEqual(_UpperCAmelCase						,     self.framework_pt)

          # TensorFlow checkpoint
          with TemporaryDirectory() as local_tf_ckpt:
               self._setup_tf_ckpt(_UpperCAmelCase)
               __A						:			List[str]								=	FeaturesManager.determine_framework(_UpperCAmelCase)
               self.assertEqual(_UpperCAmelCase						,     self.framework_tf)

          # Invalid local checkpoint
          with TemporaryDirectory() as local_invalid_ckpt:
               with self.assertRaises(_UpperCAmelCase):
                    __A						:			Tuple								=	FeaturesManager.determine_framework(_UpperCAmelCase)


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						:			Tuple								=	MagicMock(return_value=_UpperCAmelCase)
          with patch('transformers.onnx.features.is_tf_available'						,     _UpperCAmelCase):
               __A						:			Union[str, Any]								=	FeaturesManager.determine_framework(self.test_model)
               self.assertEqual(_UpperCAmelCase						,     self.framework_pt)

          # PyTorch not in environment -> use TensorFlow
          __A						:			List[str]								=	MagicMock(return_value=_UpperCAmelCase)
          with patch('transformers.onnx.features.is_torch_available'						,     _UpperCAmelCase):
               __A						:			List[Any]								=	FeaturesManager.determine_framework(self.test_model)
               self.assertEqual(_UpperCAmelCase						,     self.framework_tf)

          # Both in environment -> use PyTorch
          __A						:			Any								=	MagicMock(return_value=_UpperCAmelCase)
          __A						:			Dict								=	MagicMock(return_value=_UpperCAmelCase)
          with patch('transformers.onnx.features.is_tf_available'						,     _UpperCAmelCase), patch(
              'transformers.onnx.features.is_torch_available'						,     _UpperCAmelCase):
               __A						:			int								=	FeaturesManager.determine_framework(self.test_model)
               self.assertEqual(_UpperCAmelCase						,     self.framework_pt)

          # Both not in environment -> raise error
          __A						:			List[str]								=	MagicMock(return_value=_UpperCAmelCase)
          __A						:			Tuple								=	MagicMock(return_value=_UpperCAmelCase)
          with patch('transformers.onnx.features.is_tf_available'						,     _UpperCAmelCase), patch(
              'transformers.onnx.features.is_torch_available'						,     _UpperCAmelCase):
               with self.assertRaises(_UpperCAmelCase):
                    __A						:			int								=	FeaturesManager.determine_framework(self.test_model)