"""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 				_A		( unittest.TestCase			):

      def        A__ (		self	, __lowerCAmelCase		):







            """simple docstring"""



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

      def        A__ (		self		):







            """simple docstring"""



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

      def        A__ (		self		):







            """simple docstring"""



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

      def        A__ (		self		):







            """simple docstring"""



            lowercase														=			"""sshleifer/tiny-gpt2"""
            lowercase														=			PyTorchBenchmarkArguments(
                models=[MODEL_ID]	, training=__lowerCAmelCase	, inference=__lowerCAmelCase	, torchscript=__lowerCAmelCase	, sequence_lengths=[8]	, batch_sizes=[1]	, multi_process=__lowerCAmelCase	, )
            lowercase														=			PyTorchBenchmark(__lowerCAmelCase		)
            lowercase														=			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        A__ (		self		):







            """simple docstring"""



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

      def        A__ (		self		):







            """simple docstring"""



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

      def        A__ (		self		):







            """simple docstring"""



            lowercase														=			"""sshleifer/tiny-gpt2"""
            lowercase														=			PyTorchBenchmarkArguments(
                models=[MODEL_ID]	, training=__lowerCAmelCase	, inference=__lowerCAmelCase	, sequence_lengths=[8]	, batch_sizes=[1]	, multi_process=__lowerCAmelCase	, )
            lowercase														=			PyTorchBenchmark(__lowerCAmelCase		)
            lowercase														=			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        A__ (		self		):







            """simple docstring"""



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

      def        A__ (		self		):







            """simple docstring"""



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

      def        A__ (		self		):







            """simple docstring"""



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

      def        A__ (		self		):







            """simple docstring"""



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

      def        A__ (		self		):







            """simple docstring"""



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

      def        A__ (		self		):







            """simple docstring"""



            lowercase														=			"""sshleifer/tiny-gpt2"""
            with tempfile.TemporaryDirectory() as tmp_dir:
                  lowercase														=			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	, )
                  lowercase														=			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        A__ (		self		):







            """simple docstring"""



            lowercase														=			"""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:
                  lowercase														=			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	, )
                  lowercase														=			PyTorchBenchmark(__lowerCAmelCase		)
                  lowercase														=			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()		)




"""simple docstring"""






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


__lowerCAmelCase					: Any        =logging.get_logger(__name__)

__lowerCAmelCase					: Union[str, Any]        ={
    """facebook/timesformer""": """https://huggingface.co/facebook/timesformer/resolve/main/config.json""",
}





class 				_A		( lowerCAmelCase			):
      snake_case__    :     Optional[Any]													=			'timesformer'

      def __init__(		self	, __lowerCAmelCase=224	, __lowerCAmelCase=16	, __lowerCAmelCase=3	, __lowerCAmelCase=8	, __lowerCAmelCase=768	, __lowerCAmelCase=12	, __lowerCAmelCase=12	, __lowerCAmelCase=3072	, __lowerCAmelCase="gelu"	, __lowerCAmelCase=0.0	, __lowerCAmelCase=0.0	, __lowerCAmelCase=0.0_2	, __lowerCAmelCase=1E-6	, __lowerCAmelCase=True	, __lowerCAmelCase="divided_space_time"	, __lowerCAmelCase=0	, **__lowerCAmelCase	, ):







            """simple docstring"""



            super().__init__(**__lowerCAmelCase		)

            lowercase														=			image_size
            lowercase														=			patch_size
            lowercase														=			num_channels
            lowercase														=			num_frames

            lowercase														=			hidden_size
            lowercase														=			num_hidden_layers
            lowercase														=			num_attention_heads
            lowercase														=			intermediate_size
            lowercase														=			hidden_act
            lowercase														=			hidden_dropout_prob
            lowercase														=			attention_probs_dropout_prob
            lowercase														=			initializer_range
            lowercase														=			layer_norm_eps
            lowercase														=			qkv_bias

            lowercase														=			attention_type
            lowercase														=			drop_path_rate



