



"""simple docstring"""





import os
import tempfile
import unittest
from pathlib import Path

from transformers import AutoConfig, is_torch_available
from transformers.testing_utils import require_torch, torch_device


if is_torch_available():
  from transformers import PyTorchBenchmark, PyTorchBenchmarkArguments
@require_torch
class    lowercase__     (					unittest.TestCase   ):







       '''simple docstring'''


       def   lowercase__       (							self    :						Dict	,       _UpperCAmelCase    :						Dict					)				->		List[str]:


             '''simple docstring'''




             for model_result in results.values():
                   for batch_size, sequence_length in zip(model_result["bs"]	,       model_result["ss"]					):
                         UpperCAmelCase_    				=							model_result["result"][batch_size][sequence_length]
                         self.assertIsNotNone(_UpperCAmelCase					)



       def   lowercase__       (							self    :						Union[str, Any]					)				->		int:


             '''simple docstring'''




             UpperCAmelCase_    				=							"sshleifer/tiny-gpt2"
             UpperCAmelCase_    				=							PyTorchBenchmarkArguments(
                 models=[MODEL_ID]	,       training=_UpperCAmelCase	,       inference=_UpperCAmelCase	,       sequence_lengths=[8]	,       batch_sizes=[1]	,       multi_process=_UpperCAmelCase	,       )
             UpperCAmelCase_    				=							PyTorchBenchmark(_UpperCAmelCase					)
             UpperCAmelCase_    				=							benchmark.run()
             self.check_results_dict_not_empty(results.time_inference_result					)
             self.check_results_dict_not_empty(results.memory_inference_result					)



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


             '''simple docstring'''




             UpperCAmelCase_    				=							"sgugger/tiny-distilbert-classification"
             UpperCAmelCase_    				=							PyTorchBenchmarkArguments(
                 models=[MODEL_ID]	,       training=_UpperCAmelCase	,       inference=_UpperCAmelCase	,       sequence_lengths=[8]	,       batch_sizes=[1]	,       multi_process=_UpperCAmelCase	,       only_pretrain_model=_UpperCAmelCase	,       )
             UpperCAmelCase_    				=							PyTorchBenchmark(_UpperCAmelCase					)
             UpperCAmelCase_    				=							benchmark.run()
             self.check_results_dict_not_empty(results.time_inference_result					)
             self.check_results_dict_not_empty(results.memory_inference_result					)



       def   lowercase__       (							self    :						List[Any]					)				->		List[Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							"sshleifer/tiny-gpt2"
             UpperCAmelCase_    				=							PyTorchBenchmarkArguments(
                 models=[MODEL_ID]	,       training=_UpperCAmelCase	,       inference=_UpperCAmelCase	,       torchscript=_UpperCAmelCase	,       sequence_lengths=[8]	,       batch_sizes=[1]	,       multi_process=_UpperCAmelCase	,       )
             UpperCAmelCase_    				=							PyTorchBenchmark(_UpperCAmelCase					)
             UpperCAmelCase_    				=							benchmark.run()
             self.check_results_dict_not_empty(results.time_inference_result					)
             self.check_results_dict_not_empty(results.memory_inference_result					)



       @unittest.skipIf(torch_device == "cpu"	,       "Cant do half precision"					)
       def   lowercase__       (							self    :						Dict					)				->		Optional[int]:


             '''simple docstring'''




             UpperCAmelCase_    				=							"sshleifer/tiny-gpt2"
             UpperCAmelCase_    				=							PyTorchBenchmarkArguments(
                 models=[MODEL_ID]	,       training=_UpperCAmelCase	,       inference=_UpperCAmelCase	,       fpaa=_UpperCAmelCase	,       sequence_lengths=[8]	,       batch_sizes=[1]	,       multi_process=_UpperCAmelCase	,       )
             UpperCAmelCase_    				=							PyTorchBenchmark(_UpperCAmelCase					)
             UpperCAmelCase_    				=							benchmark.run()
             self.check_results_dict_not_empty(results.time_inference_result					)
             self.check_results_dict_not_empty(results.memory_inference_result					)



       def   lowercase__       (							self    :						str					)				->		str:


             '''simple docstring'''




             UpperCAmelCase_    				=							"sshleifer/tiny-gpt2"
             UpperCAmelCase_    				=							AutoConfig.from_pretrained(_UpperCAmelCase					)
             # set architectures equal to `None`
             UpperCAmelCase_    				=							None
             UpperCAmelCase_    				=							PyTorchBenchmarkArguments(
                 models=[MODEL_ID]	,       training=_UpperCAmelCase	,       inference=_UpperCAmelCase	,       sequence_lengths=[8]	,       batch_sizes=[1]	,       multi_process=_UpperCAmelCase	,       )
             UpperCAmelCase_    				=							PyTorchBenchmark(_UpperCAmelCase	,       configs=[config]					)
             UpperCAmelCase_    				=							benchmark.run()
             self.check_results_dict_not_empty(results.time_inference_result					)
             self.check_results_dict_not_empty(results.memory_inference_result					)



       def   lowercase__       (							self    :						List[Any]					)				->		Tuple:


             '''simple docstring'''




             UpperCAmelCase_    				=							"sshleifer/tiny-gpt2"
             UpperCAmelCase_    				=							PyTorchBenchmarkArguments(
                 models=[MODEL_ID]	,       training=_UpperCAmelCase	,       inference=_UpperCAmelCase	,       sequence_lengths=[8]	,       batch_sizes=[1]	,       multi_process=_UpperCAmelCase	,       )
             UpperCAmelCase_    				=							PyTorchBenchmark(_UpperCAmelCase					)
             UpperCAmelCase_    				=							benchmark.run()
             self.check_results_dict_not_empty(results.time_train_result					)
             self.check_results_dict_not_empty(results.memory_train_result					)



       @unittest.skipIf(torch_device == "cpu"	,       "Can't do half precision"					)
       def   lowercase__       (							self    :						List[Any]					)				->		Tuple:


             '''simple docstring'''




             UpperCAmelCase_    				=							"sshleifer/tiny-gpt2"
             UpperCAmelCase_    				=							PyTorchBenchmarkArguments(
                 models=[MODEL_ID]	,       training=_UpperCAmelCase	,       inference=_UpperCAmelCase	,       sequence_lengths=[8]	,       batch_sizes=[1]	,       fpaa=_UpperCAmelCase	,       multi_process=_UpperCAmelCase	,       )
             UpperCAmelCase_    				=							PyTorchBenchmark(_UpperCAmelCase					)
             UpperCAmelCase_    				=							benchmark.run()
             self.check_results_dict_not_empty(results.time_train_result					)
             self.check_results_dict_not_empty(results.memory_train_result					)



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


             '''simple docstring'''




             UpperCAmelCase_    				=							"sshleifer/tiny-gpt2"
             UpperCAmelCase_    				=							AutoConfig.from_pretrained(_UpperCAmelCase					)
             UpperCAmelCase_    				=							PyTorchBenchmarkArguments(
                 models=[MODEL_ID]	,       training=_UpperCAmelCase	,       inference=_UpperCAmelCase	,       sequence_lengths=[8]	,       batch_sizes=[1]	,       multi_process=_UpperCAmelCase	,       )
             UpperCAmelCase_    				=							PyTorchBenchmark(_UpperCAmelCase	,       configs=[config]					)
             UpperCAmelCase_    				=							benchmark.run()
             self.check_results_dict_not_empty(results.time_inference_result					)
             self.check_results_dict_not_empty(results.memory_inference_result					)



       def   lowercase__       (							self    :						Tuple					)				->		Tuple:


             '''simple docstring'''




             UpperCAmelCase_    				=							"sshleifer/tinier_bart"
             UpperCAmelCase_    				=							AutoConfig.from_pretrained(_UpperCAmelCase					)
             UpperCAmelCase_    				=							PyTorchBenchmarkArguments(
                 models=[MODEL_ID]	,       training=_UpperCAmelCase	,       inference=_UpperCAmelCase	,       sequence_lengths=[8]	,       batch_sizes=[1]	,       multi_process=_UpperCAmelCase	,       )
             UpperCAmelCase_    				=							PyTorchBenchmark(_UpperCAmelCase	,       configs=[config]					)
             UpperCAmelCase_    				=							benchmark.run()
             self.check_results_dict_not_empty(results.time_inference_result					)
             self.check_results_dict_not_empty(results.memory_inference_result					)



       def   lowercase__       (							self    :						str					)				->		Any:


             '''simple docstring'''




             UpperCAmelCase_    				=							"sshleifer/tiny-gpt2"
             UpperCAmelCase_    				=							AutoConfig.from_pretrained(_UpperCAmelCase					)
             UpperCAmelCase_    				=							PyTorchBenchmarkArguments(
                 models=[MODEL_ID]	,       training=_UpperCAmelCase	,       inference=_UpperCAmelCase	,       sequence_lengths=[8]	,       batch_sizes=[1]	,       multi_process=_UpperCAmelCase	,       )
             UpperCAmelCase_    				=							PyTorchBenchmark(_UpperCAmelCase	,       configs=[config]					)
             UpperCAmelCase_    				=							benchmark.run()
             self.check_results_dict_not_empty(results.time_train_result					)
             self.check_results_dict_not_empty(results.memory_train_result					)



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


             '''simple docstring'''




             UpperCAmelCase_    				=							"sshleifer/tinier_bart"
             UpperCAmelCase_    				=							AutoConfig.from_pretrained(_UpperCAmelCase					)
             UpperCAmelCase_    				=							PyTorchBenchmarkArguments(
                 models=[MODEL_ID]	,       training=_UpperCAmelCase	,       inference=_UpperCAmelCase	,       sequence_lengths=[8]	,       batch_sizes=[1]	,       multi_process=_UpperCAmelCase	,       )
             UpperCAmelCase_    				=							PyTorchBenchmark(_UpperCAmelCase	,       configs=[config]					)
             UpperCAmelCase_    				=							benchmark.run()
             self.check_results_dict_not_empty(results.time_train_result					)
             self.check_results_dict_not_empty(results.memory_train_result					)



       def   lowercase__       (							self    :						Optional[int]					)				->		Optional[int]:


             '''simple docstring'''




             UpperCAmelCase_    				=							"sshleifer/tiny-gpt2"
             with tempfile.TemporaryDirectory() as tmp_dir:
                   UpperCAmelCase_    				=							PyTorchBenchmarkArguments(
                       models=[MODEL_ID]	,       training=_UpperCAmelCase	,       inference=_UpperCAmelCase	,       save_to_csv=_UpperCAmelCase	,       sequence_lengths=[8]	,       batch_sizes=[1]	,       inference_time_csv_file=os.path.join(_UpperCAmelCase	,       "inf_time.csv"					)	,       train_memory_csv_file=os.path.join(_UpperCAmelCase	,       "train_mem.csv"					)	,       inference_memory_csv_file=os.path.join(_UpperCAmelCase	,       "inf_mem.csv"					)	,       train_time_csv_file=os.path.join(_UpperCAmelCase	,       "train_time.csv"					)	,       env_info_csv_file=os.path.join(_UpperCAmelCase	,       "env.csv"					)	,       multi_process=_UpperCAmelCase	,       )
                   UpperCAmelCase_    				=							PyTorchBenchmark(_UpperCAmelCase					)
                   benchmark.run()
                   self.assertTrue(Path(os.path.join(_UpperCAmelCase	,       "inf_time.csv"					)					).exists()					)
                   self.assertTrue(Path(os.path.join(_UpperCAmelCase	,       "train_time.csv"					)					).exists()					)
                   self.assertTrue(Path(os.path.join(_UpperCAmelCase	,       "inf_mem.csv"					)					).exists()					)
                   self.assertTrue(Path(os.path.join(_UpperCAmelCase	,       "train_mem.csv"					)					).exists()					)
                   self.assertTrue(Path(os.path.join(_UpperCAmelCase	,       "env.csv"					)					).exists()					)







       def   lowercase__       (							self    :						str					)				->		Dict:


             '''simple docstring'''




             UpperCAmelCase_    				=							"sshleifer/tiny-gpt2"

             def _check_summary_is_not_empty(_UpperCAmelCase    :						Optional[int]					):
                   self.assertTrue(hasattr(_UpperCAmelCase	,       "sequential"					)					)
                   self.assertTrue(hasattr(_UpperCAmelCase	,       "cumulative"					)					)
                   self.assertTrue(hasattr(_UpperCAmelCase	,       "current"					)					)
                   self.assertTrue(hasattr(_UpperCAmelCase	,       "total"					)					)

             with tempfile.TemporaryDirectory() as tmp_dir:
                   UpperCAmelCase_    				=							PyTorchBenchmarkArguments(
                       models=[MODEL_ID]	,       training=_UpperCAmelCase	,       inference=_UpperCAmelCase	,       sequence_lengths=[8]	,       batch_sizes=[1]	,       log_filename=os.path.join(_UpperCAmelCase	,       "log.txt"					)	,       log_print=_UpperCAmelCase	,       trace_memory_line_by_line=_UpperCAmelCase	,       multi_process=_UpperCAmelCase	,       )
                   UpperCAmelCase_    				=							PyTorchBenchmark(_UpperCAmelCase					)
                   UpperCAmelCase_    				=							benchmark.run()
                   _check_summary_is_not_empty(result.inference_summary					)
                   _check_summary_is_not_empty(result.train_summary					)
                   self.assertTrue(Path(os.path.join(_UpperCAmelCase	,       "log.txt"					)					).exists()					)









"""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      =		{
    """YituTech/conv-bert-base""": """https://huggingface.co/YituTech/conv-bert-base/resolve/main/config.json""",
    """YituTech/conv-bert-medium-small""": (
        """https://huggingface.co/YituTech/conv-bert-medium-small/resolve/main/config.json"""
    ),
    """YituTech/conv-bert-small""": """https://huggingface.co/YituTech/conv-bert-small/resolve/main/config.json""",
    # See all ConvBERT models at https://huggingface.co/models?filter=convbert
}
class    lowercase__     (					SCREAMING_SNAKE_CASE   ):







       '''simple docstring'''


       UpperCamelCase		=  '''convbert'''



       def __init__(							self    :						Any	,       _UpperCAmelCase    :						Optional[int]=30522	,       _UpperCAmelCase    :						Tuple=768	,       _UpperCAmelCase    :						Optional[int]=12	,       _UpperCAmelCase    :						Dict=12	,       _UpperCAmelCase    :						Any=3072	,       _UpperCAmelCase    :						Dict="gelu"	,       _UpperCAmelCase    :						Optional[int]=0.1	,       _UpperCAmelCase    :						str=0.1	,       _UpperCAmelCase    :						Tuple=512	,       _UpperCAmelCase    :						Optional[Any]=2	,       _UpperCAmelCase    :						Union[str, Any]=0.02	,       _UpperCAmelCase    :						Dict=1e-12	,       _UpperCAmelCase    :						Optional[int]=1	,       _UpperCAmelCase    :						int=0	,       _UpperCAmelCase    :						Optional[Any]=2	,       _UpperCAmelCase    :						List[Any]=768	,       _UpperCAmelCase    :						Optional[int]=2	,       _UpperCAmelCase    :						str=9	,       _UpperCAmelCase    :						List[Any]=1	,       _UpperCAmelCase    :						Optional[Any]=None	,       **_UpperCAmelCase    :						str	,       )				->		List[Any]:


             '''simple docstring'''




             super().__init__(
                 pad_token_id=_UpperCAmelCase	,       bos_token_id=_UpperCAmelCase	,       eos_token_id=_UpperCAmelCase	,       **_UpperCAmelCase	,       )

             UpperCAmelCase_    				=							vocab_size
             UpperCAmelCase_    				=							hidden_size
             UpperCAmelCase_    				=							num_hidden_layers
             UpperCAmelCase_    				=							num_attention_heads
             UpperCAmelCase_    				=							intermediate_size
             UpperCAmelCase_    				=							hidden_act
             UpperCAmelCase_    				=							hidden_dropout_prob
             UpperCAmelCase_    				=							attention_probs_dropout_prob
             UpperCAmelCase_    				=							max_position_embeddings
             UpperCAmelCase_    				=							type_vocab_size
             UpperCAmelCase_    				=							initializer_range
             UpperCAmelCase_    				=							layer_norm_eps
             UpperCAmelCase_    				=							embedding_size
             UpperCAmelCase_    				=							head_ratio
             UpperCAmelCase_    				=							conv_kernel_size
             UpperCAmelCase_    				=							num_groups
             UpperCAmelCase_    				=							classifier_dropout



class    lowercase__     (					SCREAMING_SNAKE_CASE   ):







       '''simple docstring'''


       @property
       def   lowercase__       (							self    :						Dict					)				->		Mapping[str, Mapping[int, str]]:


             '''simple docstring'''




             if self.task == "multiple-choice":
                   UpperCAmelCase_    				=							{0: "batch", 1: "choice", 2: "sequence"}
             else:
                   UpperCAmelCase_    				=							{0: "batch", 1: "sequence"}
             return OrderedDict(
                 [
                     ("input_ids", dynamic_axis),
                     ("attention_mask", dynamic_axis),
                     ("token_type_ids", dynamic_axis),
                 ]					)




