


"""simple docstring"""


from collections import OrderedDict
from typing import Mapping

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


A     :   Union[str, Any]			    =			logging.get_logger(__name__)

A     :   Dict			    =			{
    "facebook/xlm-roberta-xl": "https://huggingface.co/facebook/xlm-roberta-xl/resolve/main/config.json",
    "facebook/xlm-roberta-xxl": "https://huggingface.co/facebook/xlm-roberta-xxl/resolve/main/config.json",
    # See all XLM-RoBERTa-XL models at https://huggingface.co/models?filter=xlm-roberta-xl
}
class   _UpperCamelCase  (   lowerCAmelCase__		):
							'''simple docstring'''







							__UpperCAmelCase						:    Optional[int]				      ="""xlm-roberta-xl"""

							def __init__(     self    ,   __a=25_08_80    ,   __a=25_60    ,   __a=36    ,   __a=32    ,   __a=1_02_40    ,   __a="gelu"    ,   __a=0.1    ,   __a=0.1    ,   __a=5_14    ,   __a=1    ,   __a=0.0_2    ,   __a=1e-0_5    ,   __a=1    ,   __a=0    ,   __a=2    ,   __a="absolute"    ,   __a=True    ,   __a=None    ,   **__a    ,   ):
										super().__init__(pad_token_id=__lowerCamelCase    ,   bos_token_id=__lowerCamelCase    ,   eos_token_id=__lowerCamelCase    ,   **__lowerCamelCase	)
										__lowerCAmelCase				    =			vocab_size
										__lowerCAmelCase				    =			hidden_size
										__lowerCAmelCase				    =			num_hidden_layers
										__lowerCAmelCase				    =			num_attention_heads
										__lowerCAmelCase				    =			hidden_act
										__lowerCAmelCase				    =			intermediate_size
										__lowerCAmelCase				    =			hidden_dropout_prob
										__lowerCAmelCase				    =			attention_probs_dropout_prob
										__lowerCAmelCase				    =			max_position_embeddings
										__lowerCAmelCase				    =			type_vocab_size
										__lowerCAmelCase				    =			initializer_range
										__lowerCAmelCase				    =			layer_norm_eps
										__lowerCAmelCase				    =			position_embedding_type
										__lowerCAmelCase				    =			use_cache
										__lowerCAmelCase				    =			classifier_dropout
class   _UpperCamelCase  (   lowerCAmelCase__		):
							'''simple docstring'''







							@property
							def 			snake_case				(     self	):
										if self.task == "multiple-choice":
													__lowerCAmelCase				    =			{0: "batch", 1: "choice", 2: "sequence"}
										else:
													__lowerCAmelCase				    =			{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_torch_available
from transformers.testing_utils import require_torch, torch_device


if is_torch_available():
    from transformers import PyTorchBenchmark, PyTorchBenchmarkArguments







@require_torch
class      lowerCAmelCase__       (				unittest.TestCase):




     '''simple docstring'''


     def  _lowerCamelCase (						self ,						__lowerCamelCase)			->				Dict:
            for model_result in results.values():
                   for batch_size, sequence_length in zip(model_result["bs"] ,						model_result["ss"]):
                          _A      :       Optional[int]				    = model_result["result"][batch_size][sequence_length]
                          self.assertIsNotNone(__lowerCamelCase)


     def  _lowerCamelCase (						self)			->				int:
            _A      :       Optional[int]				    = "sshleifer/tiny-gpt2"
            _A      :       int				    = PyTorchBenchmarkArguments(
                models=[MODEL_ID] ,						training=__lowerCamelCase ,						inference=__lowerCamelCase ,						sequence_lengths=[8] ,						batch_sizes=[1] ,						multi_process=__lowerCamelCase ,						)
            _A      :       List[str]				    = PyTorchBenchmark(__lowerCamelCase)
            _A      :       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  _lowerCamelCase (						self)			->				Dict:
            _A      :       int				    = "sgugger/tiny-distilbert-classification"
            _A      :       str				    = PyTorchBenchmarkArguments(
                models=[MODEL_ID] ,						training=__lowerCamelCase ,						inference=__lowerCamelCase ,						sequence_lengths=[8] ,						batch_sizes=[1] ,						multi_process=__lowerCamelCase ,						only_pretrain_model=__lowerCamelCase ,						)
            _A      :       Dict				    = PyTorchBenchmark(__lowerCamelCase)
            _A      :       Union[str, Any]				    = benchmark.run()
            self.check_results_dict_not_empty(results.time_inference_result)
            self.check_results_dict_not_empty(results.memory_inference_result)


     def  _lowerCamelCase (						self)			->				Optional[Any]:
            _A      :       Tuple				    = "sshleifer/tiny-gpt2"
            _A      :       Optional[Any]				    = PyTorchBenchmarkArguments(
                models=[MODEL_ID] ,						training=__lowerCamelCase ,						inference=__lowerCamelCase ,						torchscript=__lowerCamelCase ,						sequence_lengths=[8] ,						batch_sizes=[1] ,						multi_process=__lowerCamelCase ,						)
            _A      :       Union[str, Any]				    = PyTorchBenchmark(__lowerCamelCase)
            _A      :       List[str]				    = 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  _lowerCamelCase (						self)			->				int:
            _A      :       Any				    = "sshleifer/tiny-gpt2"
            _A      :       Tuple				    = PyTorchBenchmarkArguments(
                models=[MODEL_ID] ,						training=__lowerCamelCase ,						inference=__lowerCamelCase ,						fpaa=__lowerCamelCase ,						sequence_lengths=[8] ,						batch_sizes=[1] ,						multi_process=__lowerCamelCase ,						)
            _A      :       Any				    = PyTorchBenchmark(__lowerCamelCase)
            _A      :       Union[str, Any]				    = benchmark.run()
            self.check_results_dict_not_empty(results.time_inference_result)
            self.check_results_dict_not_empty(results.memory_inference_result)


     def  _lowerCamelCase (						self)			->				Any:
            _A      :       Union[str, Any]				    = "sshleifer/tiny-gpt2"
            _A      :       Any				    = AutoConfig.from_pretrained(__lowerCamelCase)
            # set architectures equal to `None`
            _A      :       Dict				    = None
            _A      :       Any				    = PyTorchBenchmarkArguments(
                models=[MODEL_ID] ,						training=__lowerCamelCase ,						inference=__lowerCamelCase ,						sequence_lengths=[8] ,						batch_sizes=[1] ,						multi_process=__lowerCamelCase ,						)
            _A      :       Union[str, Any]				    = PyTorchBenchmark(__lowerCamelCase ,						configs=[config])
            _A      :       int				    = benchmark.run()
            self.check_results_dict_not_empty(results.time_inference_result)
            self.check_results_dict_not_empty(results.memory_inference_result)


     def  _lowerCamelCase (						self)			->				int:
            _A      :       List[Any]				    = "sshleifer/tiny-gpt2"
            _A      :       int				    = PyTorchBenchmarkArguments(
                models=[MODEL_ID] ,						training=__lowerCamelCase ,						inference=__lowerCamelCase ,						sequence_lengths=[8] ,						batch_sizes=[1] ,						multi_process=__lowerCamelCase ,						)
            _A      :       Optional[Any]				    = PyTorchBenchmark(__lowerCamelCase)
            _A      :       int				    = 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  _lowerCamelCase (						self)			->				Optional[Any]:
            _A      :       Any				    = "sshleifer/tiny-gpt2"
            _A      :       Tuple				    = PyTorchBenchmarkArguments(
                models=[MODEL_ID] ,						training=__lowerCamelCase ,						inference=__lowerCamelCase ,						sequence_lengths=[8] ,						batch_sizes=[1] ,						fpaa=__lowerCamelCase ,						multi_process=__lowerCamelCase ,						)
            _A      :       List[Any]				    = PyTorchBenchmark(__lowerCamelCase)
            _A      :       Tuple				    = benchmark.run()
            self.check_results_dict_not_empty(results.time_train_result)
            self.check_results_dict_not_empty(results.memory_train_result)


     def  _lowerCamelCase (						self)			->				str:
            _A      :       List[str]				    = "sshleifer/tiny-gpt2"
            _A      :       Union[str, Any]				    = AutoConfig.from_pretrained(__lowerCamelCase)
            _A      :       Any				    = PyTorchBenchmarkArguments(
                models=[MODEL_ID] ,						training=__lowerCamelCase ,						inference=__lowerCamelCase ,						sequence_lengths=[8] ,						batch_sizes=[1] ,						multi_process=__lowerCamelCase ,						)
            _A      :       Optional[Any]				    = PyTorchBenchmark(__lowerCamelCase ,						configs=[config])
            _A      :       Tuple				    = benchmark.run()
            self.check_results_dict_not_empty(results.time_inference_result)
            self.check_results_dict_not_empty(results.memory_inference_result)


     def  _lowerCamelCase (						self)			->				int:
            _A      :       Tuple				    = "sshleifer/tinier_bart"
            _A      :       Optional[Any]				    = AutoConfig.from_pretrained(__lowerCamelCase)
            _A      :       Optional[int]				    = PyTorchBenchmarkArguments(
                models=[MODEL_ID] ,						training=__lowerCamelCase ,						inference=__lowerCamelCase ,						sequence_lengths=[8] ,						batch_sizes=[1] ,						multi_process=__lowerCamelCase ,						)
            _A      :       Dict				    = PyTorchBenchmark(__lowerCamelCase ,						configs=[config])
            _A      :       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  _lowerCamelCase (						self)			->				str:
            _A      :       List[Any]				    = "sshleifer/tiny-gpt2"
            _A      :       Optional[Any]				    = AutoConfig.from_pretrained(__lowerCamelCase)
            _A      :       Optional[Any]				    = PyTorchBenchmarkArguments(
                models=[MODEL_ID] ,						training=__lowerCamelCase ,						inference=__lowerCamelCase ,						sequence_lengths=[8] ,						batch_sizes=[1] ,						multi_process=__lowerCamelCase ,						)
            _A      :       List[str]				    = PyTorchBenchmark(__lowerCamelCase ,						configs=[config])
            _A      :       Dict				    = benchmark.run()
            self.check_results_dict_not_empty(results.time_train_result)
            self.check_results_dict_not_empty(results.memory_train_result)


     def  _lowerCamelCase (						self)			->				int:
            _A      :       int				    = "sshleifer/tinier_bart"
            _A      :       str				    = AutoConfig.from_pretrained(__lowerCamelCase)
            _A      :       Tuple				    = PyTorchBenchmarkArguments(
                models=[MODEL_ID] ,						training=__lowerCamelCase ,						inference=__lowerCamelCase ,						sequence_lengths=[8] ,						batch_sizes=[1] ,						multi_process=__lowerCamelCase ,						)
            _A      :       Tuple				    = PyTorchBenchmark(__lowerCamelCase ,						configs=[config])
            _A      :       Union[str, Any]				    = benchmark.run()
            self.check_results_dict_not_empty(results.time_train_result)
            self.check_results_dict_not_empty(results.memory_train_result)


     def  _lowerCamelCase (						self)			->				Dict:
            _A      :       List[str]				    = "sshleifer/tiny-gpt2"
            with tempfile.TemporaryDirectory() as tmp_dir:
                   _A      :       Optional[Any]				    = PyTorchBenchmarkArguments(
                       models=[MODEL_ID] ,						training=__lowerCamelCase ,						inference=__lowerCamelCase ,						save_to_csv=__lowerCamelCase ,						sequence_lengths=[8] ,						batch_sizes=[1] ,						inference_time_csv_file=os.path.join(__lowerCamelCase ,						"inf_time.csv") ,						train_memory_csv_file=os.path.join(__lowerCamelCase ,						"train_mem.csv") ,						inference_memory_csv_file=os.path.join(__lowerCamelCase ,						"inf_mem.csv") ,						train_time_csv_file=os.path.join(__lowerCamelCase ,						"train_time.csv") ,						env_info_csv_file=os.path.join(__lowerCamelCase ,						"env.csv") ,						multi_process=__lowerCamelCase ,						)
                   _A      :       Tuple				    = PyTorchBenchmark(__lowerCamelCase)
                   benchmark.run()
                   self.assertTrue(Path(os.path.join(__lowerCamelCase ,						"inf_time.csv")).exists())
                   self.assertTrue(Path(os.path.join(__lowerCamelCase ,						"train_time.csv")).exists())
                   self.assertTrue(Path(os.path.join(__lowerCamelCase ,						"inf_mem.csv")).exists())
                   self.assertTrue(Path(os.path.join(__lowerCamelCase ,						"train_mem.csv")).exists())
                   self.assertTrue(Path(os.path.join(__lowerCamelCase ,						"env.csv")).exists())


     def  _lowerCamelCase (						self)			->				int:
            _A      :       Dict				    = "sshleifer/tiny-gpt2"

            def _check_summary_is_not_empty(__lowerCamelCase):
                   self.assertTrue(hasattr(__lowerCamelCase ,						"sequential"))
                   self.assertTrue(hasattr(__lowerCamelCase ,						"cumulative"))
                   self.assertTrue(hasattr(__lowerCamelCase ,						"current"))
                   self.assertTrue(hasattr(__lowerCamelCase ,						"total"))

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