



'''simple docstring'''





from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


_lowerCAmelCase      						=	logging.get_logger(__name__)

_lowerCAmelCase      						=	{
    '''facebook/xmod-base''': '''https://huggingface.co/facebook/xmod-base/resolve/main/config.json''',
    '''facebook/xmod-large-prenorm''': '''https://huggingface.co/facebook/xmod-large-prenorm/resolve/main/config.json''',
    '''facebook/xmod-base-13-125k''': '''https://huggingface.co/facebook/xmod-base-13-125k/resolve/main/config.json''',
    '''facebook/xmod-base-30-125k''': '''https://huggingface.co/facebook/xmod-base-30-125k/resolve/main/config.json''',
    '''facebook/xmod-base-30-195k''': '''https://huggingface.co/facebook/xmod-base-30-195k/resolve/main/config.json''',
    '''facebook/xmod-base-60-125k''': '''https://huggingface.co/facebook/xmod-base-60-125k/resolve/main/config.json''',
    '''facebook/xmod-base-60-265k''': '''https://huggingface.co/facebook/xmod-base-60-265k/resolve/main/config.json''',
    '''facebook/xmod-base-75-125k''': '''https://huggingface.co/facebook/xmod-base-75-125k/resolve/main/config.json''',
    '''facebook/xmod-base-75-269k''': '''https://huggingface.co/facebook/xmod-base-75-269k/resolve/main/config.json''',
}






class        lowerCAmelCase_(				SCREAMING_SNAKE_CASE_     ):
  '''simple docstring'''




  __lowercase							:      Optional[int]				=      '''xmod'''




  def __init__(    self  ,__UpperCAmelCase=3_0522  ,__UpperCAmelCase=768  ,__UpperCAmelCase=12  ,__UpperCAmelCase=12  ,__UpperCAmelCase=3072  ,__UpperCAmelCase="gelu"  ,__UpperCAmelCase=0.1  ,__UpperCAmelCase=0.1  ,__UpperCAmelCase=512  ,__UpperCAmelCase=2  ,__UpperCAmelCase=0.0_2  ,__UpperCAmelCase=1E-12  ,__UpperCAmelCase=1  ,__UpperCAmelCase=0  ,__UpperCAmelCase=2  ,__UpperCAmelCase="absolute"  ,__UpperCAmelCase=True  ,__UpperCAmelCase=None  ,__UpperCAmelCase=False  ,__UpperCAmelCase=2  ,__UpperCAmelCase=False  ,__UpperCAmelCase=True  ,__UpperCAmelCase=True  ,__UpperCAmelCase=("en_XX",)  ,__UpperCAmelCase=None  ,**__UpperCAmelCase  ,)    ->		List[Any]:
      super().__init__(pad_token_id=__UpperCAmelCase  ,bos_token_id=__UpperCAmelCase  ,eos_token_id=__UpperCAmelCase  ,**__UpperCAmelCase      )

      lowerCAmelCase__ :  Dict							      =					vocab_size
      lowerCAmelCase__ :  Optional[int]							      =					hidden_size
      lowerCAmelCase__ :  Union[str, Any]							      =					num_hidden_layers
      lowerCAmelCase__ :  List[Any]							      =					num_attention_heads
      lowerCAmelCase__ :  int							      =					hidden_act
      lowerCAmelCase__ :  str							      =					intermediate_size
      lowerCAmelCase__ :  List[Any]							      =					hidden_dropout_prob
      lowerCAmelCase__ :  Union[str, Any]							      =					attention_probs_dropout_prob
      lowerCAmelCase__ :  Optional[Any]							      =					max_position_embeddings
      lowerCAmelCase__ :  Tuple							      =					type_vocab_size
      lowerCAmelCase__ :  Optional[int]							      =					initializer_range
      lowerCAmelCase__ :  Dict							      =					layer_norm_eps
      lowerCAmelCase__ :  List[Any]							      =					position_embedding_type
      lowerCAmelCase__ :  Dict							      =					use_cache
      lowerCAmelCase__ :  Tuple							      =					classifier_dropout
      lowerCAmelCase__ :  Union[str, Any]							      =					pre_norm
      lowerCAmelCase__ :  Union[str, Any]							      =					adapter_reduction_factor
      lowerCAmelCase__ :  List[str]							      =					adapter_layer_norm
      lowerCAmelCase__ :  Optional[Any]							      =					adapter_reuse_layer_norm
      lowerCAmelCase__ :  int							      =					ln_before_adapter
      lowerCAmelCase__ :  Any							      =					list(__UpperCAmelCase      )
      lowerCAmelCase__ :  Optional[int]							      =					default_language







class        lowerCAmelCase_(				SCREAMING_SNAKE_CASE_     ):
  '''simple docstring'''




  @property
  def 							UpperCAmelCase_	(    self      )    ->		Mapping[str, Mapping[int, str]]:
      if self.task == "multiple-choice":
          lowerCAmelCase__ :  List[str]							      =					{0: """batch""", 1: """choice""", 2: """sequence"""}
      else:
          lowerCAmelCase__ :  Optional[Any]							      =					{0: """batch""", 1: """sequence"""}
      return OrderedDict(
          [
              ("""input_ids""", dynamic_axis),
              ("""attention_mask""", dynamic_axis),
          ]      )



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()			)



