



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


A__  :  str								=					logging.get_logger(__name__)

A__  :  List[str]								=					{
    '''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 				__snake_case						(     UpperCamelCase_						):
							_a			      = '''speech_to_text'''
							_a			      = ['''past_key_values''']
							_a			      = {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}




							def __init__(       self     :       Union[str, Any]				,				A_     :       Optional[Any]=1_0_0_0_0				,				A_     :       Optional[int]=1_2				,				A_     :       int=2_0_4_8				,				A_     :       str=4				,				A_     :       Tuple=6				,				A_     :       Dict=2_0_4_8				,				A_     :       Optional[int]=4				,				A_     :       Any=0.0				,				A_     :       Dict=0.0				,				A_     :       Optional[Any]=True				,				A_     :       List[Any]=True				,				A_     :       Tuple="relu"				,				A_     :       List[str]=2_5_6				,				A_     :       Tuple=0.1				,				A_     :       Dict=0.0				,				A_     :       List[str]=0.0				,				A_     :       Optional[Any]=0.02				,				A_     :       Dict=2				,				A_     :       Tuple=True				,				A_     :       int=1				,				A_     :       Any=0				,				A_     :       List[Any]=2				,				A_     :       Optional[Any]=6_0_0_0				,				A_     :       Union[str, Any]=1_0_2_4				,				A_     :       List[str]=2				,				A_     :       List[Any]=(5, 5)				,				A_     :       Union[str, Any]=1_0_2_4				,				A_     :       Any=8_0				,				A_     :       Any=1				,				**A_     :       List[str]				,				):
									lowerCAmelCase_			:     Dict									= vocab_size
									lowerCAmelCase_			:     Optional[Any]									= d_model
									lowerCAmelCase_			:     List[str]									= encoder_ffn_dim
									lowerCAmelCase_			:     Optional[Any]									= encoder_layers
									lowerCAmelCase_			:     Any									= encoder_attention_heads
									lowerCAmelCase_			:     List[str]									= decoder_ffn_dim
									lowerCAmelCase_			:     int									= decoder_layers
									lowerCAmelCase_			:     Tuple									= decoder_attention_heads
									lowerCAmelCase_			:     Optional[int]									= dropout
									lowerCAmelCase_			:     List[Any]									= attention_dropout
									lowerCAmelCase_			:     List[Any]									= activation_dropout
									lowerCAmelCase_			:     List[str]									= activation_function
									lowerCAmelCase_			:     List[str]									= init_std
									lowerCAmelCase_			:     List[str]									= encoder_layerdrop
									lowerCAmelCase_			:     Union[str, Any]									= decoder_layerdrop
									lowerCAmelCase_			:     Union[str, Any]									= use_cache
									lowerCAmelCase_			:     Optional[int]									= encoder_layers
									lowerCAmelCase_			:     Union[str, Any]									= scale_embedding  # scale factor will be sqrt(d_model) if True
									lowerCAmelCase_			:     Optional[Any]									= max_source_positions
									lowerCAmelCase_			:     int									= max_target_positions
									lowerCAmelCase_			:     Tuple									= num_conv_layers
									lowerCAmelCase_			:     str									= list(A_)
									lowerCAmelCase_			:     int									= conv_channels
									lowerCAmelCase_			:     str									= input_feat_per_channel
									lowerCAmelCase_			:     Dict									= 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_				,				)






import os
import tempfile
import unittest
from pathlib import Path

from transformers import AutoConfig, is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
   import tensorflow as tf

   from transformers import TensorFlowBenchmark, TensorFlowBenchmarkArguments





@require_tf
class 		_lowercase						(					unittest.TestCase       ):

 def 						SCREAMING_SNAKE_CASE__   ( self	:							int   ,      snake_case	:							Union[str, Any]			)   ->						Optional[int]:

  """simple docstring"""





  for model_result in results.values():
   for batch_size, sequence_length in zip(model_result['bs']   ,      model_result['ss']			):
    UpperCamelCase_					:						Optional[Any] =					model_result['result'][batch_size][sequence_length]
    self.assertIsNotNone(snake_case			)

 def 						SCREAMING_SNAKE_CASE__   ( self	:							int			)   ->						Tuple:

  """simple docstring"""





  UpperCamelCase_					:						Optional[Any] =					'sshleifer/tiny-gpt2'
  UpperCamelCase_					:						Dict =					TensorFlowBenchmarkArguments(
      models=[MODEL_ID]   ,      training=snake_case   ,      inference=snake_case   ,      sequence_lengths=[8]   ,      batch_sizes=[1]   ,      eager_mode=snake_case   ,      multi_process=snake_case   ,      )
  UpperCamelCase_					:						Tuple =					TensorFlowBenchmark(snake_case			)
  UpperCamelCase_					:						List[str] =					benchmark.run()
  self.check_results_dict_not_empty(results.time_inference_result			)
  self.check_results_dict_not_empty(results.memory_inference_result			)

 def 						SCREAMING_SNAKE_CASE__   ( self	:							str			)   ->						Optional[Any]:

  """simple docstring"""





  UpperCamelCase_					:						Dict =					'sgugger/tiny-distilbert-classification'
  UpperCamelCase_					:						int =					TensorFlowBenchmarkArguments(
      models=[MODEL_ID]   ,      training=snake_case   ,      inference=snake_case   ,      sequence_lengths=[8]   ,      batch_sizes=[1]   ,      multi_process=snake_case   ,      only_pretrain_model=snake_case   ,      )
  UpperCamelCase_					:						int =					TensorFlowBenchmark(snake_case			)
  UpperCamelCase_					:						Tuple =					benchmark.run()
  self.check_results_dict_not_empty(results.time_inference_result			)
  self.check_results_dict_not_empty(results.memory_inference_result			)

 def 						SCREAMING_SNAKE_CASE__   ( self	:							Tuple			)   ->						List[str]:

  """simple docstring"""





  UpperCamelCase_					:						str =					'sshleifer/tiny-gpt2'
  UpperCamelCase_					:						Any =					TensorFlowBenchmarkArguments(
      models=[MODEL_ID]   ,      training=snake_case   ,      inference=snake_case   ,      sequence_lengths=[8]   ,      batch_sizes=[1]   ,      multi_process=snake_case   ,      )
  UpperCamelCase_					:						List[str] =					TensorFlowBenchmark(snake_case			)
  UpperCamelCase_					:						Optional[int] =					benchmark.run()
  self.check_results_dict_not_empty(results.time_inference_result			)
  self.check_results_dict_not_empty(results.memory_inference_result			)

 def 						SCREAMING_SNAKE_CASE__   ( self	:							Tuple			)   ->						Dict:

  """simple docstring"""





  UpperCamelCase_					:						List[str] =					'sshleifer/tiny-gpt2'
  UpperCamelCase_					:						str =					AutoConfig.from_pretrained(snake_case			)
  UpperCamelCase_					:						List[str] =					TensorFlowBenchmarkArguments(
      models=[MODEL_ID]   ,      training=snake_case   ,      inference=snake_case   ,      sequence_lengths=[8]   ,      batch_sizes=[1]   ,      eager_mode=snake_case   ,      multi_process=snake_case   ,      )
  UpperCamelCase_					:						int =					TensorFlowBenchmark(snake_case   ,      [config]			)
  UpperCamelCase_					:						Optional[Any] =					benchmark.run()
  self.check_results_dict_not_empty(results.time_inference_result			)
  self.check_results_dict_not_empty(results.memory_inference_result			)

 def 						SCREAMING_SNAKE_CASE__   ( self	:							Optional[Any]			)   ->						List[str]:

  """simple docstring"""





  UpperCamelCase_					:						List[str] =					'sshleifer/tiny-gpt2'
  UpperCamelCase_					:						int =					AutoConfig.from_pretrained(snake_case			)
  UpperCamelCase_					:						Any =					TensorFlowBenchmarkArguments(
      models=[MODEL_ID]   ,      training=snake_case   ,      inference=snake_case   ,      sequence_lengths=[8]   ,      batch_sizes=[1]   ,      multi_process=snake_case   ,      )
  UpperCamelCase_					:						Tuple =					TensorFlowBenchmark(snake_case   ,      [config]			)
  UpperCamelCase_					:						Tuple =					benchmark.run()
  self.check_results_dict_not_empty(results.time_inference_result			)
  self.check_results_dict_not_empty(results.memory_inference_result			)

 def 						SCREAMING_SNAKE_CASE__   ( self	:							Tuple			)   ->						int:

  """simple docstring"""





  UpperCamelCase_					:						Optional[int] =					'sshleifer/tiny-gpt2'
  UpperCamelCase_					:						Tuple =					TensorFlowBenchmarkArguments(
      models=[MODEL_ID]   ,      training=snake_case   ,      inference=snake_case   ,      sequence_lengths=[8]   ,      batch_sizes=[1]   ,      multi_process=snake_case   ,      )
  UpperCamelCase_					:						Optional[int] =					TensorFlowBenchmark(snake_case			)
  UpperCamelCase_					:						str =					benchmark.run()
  self.check_results_dict_not_empty(results.time_train_result			)
  self.check_results_dict_not_empty(results.memory_train_result			)

 def 						SCREAMING_SNAKE_CASE__   ( self	:							Any			)   ->						int:

  """simple docstring"""





  UpperCamelCase_					:						Tuple =					'sshleifer/tiny-gpt2'
  UpperCamelCase_					:						List[str] =					AutoConfig.from_pretrained(snake_case			)
  UpperCamelCase_					:						int =					TensorFlowBenchmarkArguments(
      models=[MODEL_ID]   ,      training=snake_case   ,      inference=snake_case   ,      sequence_lengths=[8]   ,      batch_sizes=[1]   ,      multi_process=snake_case   ,      )
  UpperCamelCase_					:						List[Any] =					TensorFlowBenchmark(snake_case   ,      [config]			)
  UpperCamelCase_					:						int =					benchmark.run()
  self.check_results_dict_not_empty(results.time_train_result			)
  self.check_results_dict_not_empty(results.memory_train_result			)

 def 						SCREAMING_SNAKE_CASE__   ( self	:							Union[str, Any]			)   ->						Dict:

  """simple docstring"""





  UpperCamelCase_					:						Tuple =					'patrickvonplaten/t5-tiny-random'
  UpperCamelCase_					:						List[str] =					AutoConfig.from_pretrained(snake_case			)
  UpperCamelCase_					:						List[str] =					TensorFlowBenchmarkArguments(
      models=[MODEL_ID]   ,      training=snake_case   ,      inference=snake_case   ,      sequence_lengths=[8]   ,      batch_sizes=[1]   ,      multi_process=snake_case   ,      )
  UpperCamelCase_					:						int =					TensorFlowBenchmark(snake_case   ,      configs=[config]			)
  UpperCamelCase_					:						Optional[Any] =					benchmark.run()
  self.check_results_dict_not_empty(results.time_inference_result			)
  self.check_results_dict_not_empty(results.memory_inference_result			)

 @unittest.skipIf(is_tf_available() and len(tf.config.list_physical_devices('GPU'			)			) == 0   ,      'Cannot do xla on CPU.'			)
 def 						SCREAMING_SNAKE_CASE__   ( self	:							Optional[int]			)   ->						Dict:

  """simple docstring"""





  UpperCamelCase_					:						int =					'sshleifer/tiny-gpt2'
  UpperCamelCase_					:						Union[str, Any] =					TensorFlowBenchmarkArguments(
      models=[MODEL_ID]   ,      training=snake_case   ,      inference=snake_case   ,      sequence_lengths=[8]   ,      batch_sizes=[1]   ,      use_xla=snake_case   ,      multi_process=snake_case   ,      )
  UpperCamelCase_					:						Union[str, Any] =					TensorFlowBenchmark(snake_case			)
  UpperCamelCase_					:						List[str] =					benchmark.run()
  self.check_results_dict_not_empty(results.time_inference_result			)
  self.check_results_dict_not_empty(results.memory_inference_result			)

 def 						SCREAMING_SNAKE_CASE__   ( self	:							List[str]			)   ->						Optional[int]:

  """simple docstring"""





  UpperCamelCase_					:						List[Any] =					'sshleifer/tiny-gpt2'
  with tempfile.TemporaryDirectory() as tmp_dir:
   UpperCamelCase_					:						List[Any] =					TensorFlowBenchmarkArguments(
       models=[MODEL_ID]   ,      inference=snake_case   ,      save_to_csv=snake_case   ,      sequence_lengths=[8]   ,      batch_sizes=[1]   ,      inference_time_csv_file=os.path.join(snake_case   ,      'inf_time.csv'			)   ,      inference_memory_csv_file=os.path.join(snake_case   ,      'inf_mem.csv'			)   ,      env_info_csv_file=os.path.join(snake_case   ,      'env.csv'			)   ,      multi_process=snake_case   ,      )
   UpperCamelCase_					:						List[str] =					TensorFlowBenchmark(snake_case			)
   benchmark.run()
   self.assertTrue(Path(os.path.join(snake_case   ,      'inf_time.csv'			)			).exists()			)
   self.assertTrue(Path(os.path.join(snake_case   ,      'inf_mem.csv'			)			).exists()			)
   self.assertTrue(Path(os.path.join(snake_case   ,      'env.csv'			)			).exists()			)


 def 						SCREAMING_SNAKE_CASE__   ( self	:							List[str]			)   ->						str:

  """simple docstring"""





  UpperCamelCase_					:						Optional[Any] =					'sshleifer/tiny-gpt2'

  def _check_summary_is_not_empty(snake_case	:							Union[str, Any]			):
   self.assertTrue(hasattr(snake_case   ,      'sequential'			)			)
   self.assertTrue(hasattr(snake_case   ,      'cumulative'			)			)
   self.assertTrue(hasattr(snake_case   ,      'current'			)			)
   self.assertTrue(hasattr(snake_case   ,      'total'			)			)

  with tempfile.TemporaryDirectory() as tmp_dir:
   UpperCamelCase_					:						str =					TensorFlowBenchmarkArguments(
       models=[MODEL_ID]   ,      inference=snake_case   ,      sequence_lengths=[8]   ,      batch_sizes=[1]   ,      log_filename=os.path.join(snake_case   ,      'log.txt'			)   ,      log_print=snake_case   ,      trace_memory_line_by_line=snake_case   ,      eager_mode=snake_case   ,      multi_process=snake_case   ,      )
   UpperCamelCase_					:						Tuple =					TensorFlowBenchmark(snake_case			)
   UpperCamelCase_					:						Union[str, Any] =					benchmark.run()
   _check_summary_is_not_empty(result.inference_summary			)
   self.assertTrue(Path(os.path.join(snake_case   ,      'log.txt'			)			).exists()			)



