






'''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   __SCREAMING_SNAKE_CASE       (unittest.TestCase       ):


  """simple docstring"""


  def    _a       (			self   ,	UpperCamelCase__	):






         """simple docstring"""


         for model_result in results.values():
                for batch_size, sequence_length in zip(model_result['bs']   ,	model_result['ss']	):
                       a_						     =			model_result['result'][batch_size][sequence_length]
                       self.assertIsNotNone(UpperCamelCase__	)







  def    _a       (			self	):






         """simple docstring"""


         a_						     =			'sshleifer/tiny-gpt2'
         a_						     =			PyTorchBenchmarkArguments(
             models=[MODEL_ID]   ,	training=UpperCamelCase__   ,	inference=UpperCamelCase__   ,	sequence_lengths=[8]   ,	batch_sizes=[1]   ,	multi_process=UpperCamelCase__   ,	)
         a_						     =			PyTorchBenchmark(UpperCamelCase__	)
         a_						     =			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"""


         a_						     =			'sgugger/tiny-distilbert-classification'
         a_						     =			PyTorchBenchmarkArguments(
             models=[MODEL_ID]   ,	training=UpperCamelCase__   ,	inference=UpperCamelCase__   ,	sequence_lengths=[8]   ,	batch_sizes=[1]   ,	multi_process=UpperCamelCase__   ,	only_pretrain_model=UpperCamelCase__   ,	)
         a_						     =			PyTorchBenchmark(UpperCamelCase__	)
         a_						     =			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"""


         a_						     =			'sshleifer/tiny-gpt2'
         a_						     =			PyTorchBenchmarkArguments(
             models=[MODEL_ID]   ,	training=UpperCamelCase__   ,	inference=UpperCamelCase__   ,	torchscript=UpperCamelCase__   ,	sequence_lengths=[8]   ,	batch_sizes=[1]   ,	multi_process=UpperCamelCase__   ,	)
         a_						     =			PyTorchBenchmark(UpperCamelCase__	)
         a_						     =			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"""


         a_						     =			'sshleifer/tiny-gpt2'
         a_						     =			PyTorchBenchmarkArguments(
             models=[MODEL_ID]   ,	training=UpperCamelCase__   ,	inference=UpperCamelCase__   ,	fpaa=UpperCamelCase__   ,	sequence_lengths=[8]   ,	batch_sizes=[1]   ,	multi_process=UpperCamelCase__   ,	)
         a_						     =			PyTorchBenchmark(UpperCamelCase__	)
         a_						     =			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"""


         a_						     =			'sshleifer/tiny-gpt2'
         a_						     =			AutoConfig.from_pretrained(UpperCamelCase__	)
         # set architectures equal to `None`
         a_						     =			None
         a_						     =			PyTorchBenchmarkArguments(
             models=[MODEL_ID]   ,	training=UpperCamelCase__   ,	inference=UpperCamelCase__   ,	sequence_lengths=[8]   ,	batch_sizes=[1]   ,	multi_process=UpperCamelCase__   ,	)
         a_						     =			PyTorchBenchmark(UpperCamelCase__   ,	configs=[config]	)
         a_						     =			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"""


         a_						     =			'sshleifer/tiny-gpt2'
         a_						     =			PyTorchBenchmarkArguments(
             models=[MODEL_ID]   ,	training=UpperCamelCase__   ,	inference=UpperCamelCase__   ,	sequence_lengths=[8]   ,	batch_sizes=[1]   ,	multi_process=UpperCamelCase__   ,	)
         a_						     =			PyTorchBenchmark(UpperCamelCase__	)
         a_						     =			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"""


         a_						     =			'sshleifer/tiny-gpt2'
         a_						     =			PyTorchBenchmarkArguments(
             models=[MODEL_ID]   ,	training=UpperCamelCase__   ,	inference=UpperCamelCase__   ,	sequence_lengths=[8]   ,	batch_sizes=[1]   ,	fpaa=UpperCamelCase__   ,	multi_process=UpperCamelCase__   ,	)
         a_						     =			PyTorchBenchmark(UpperCamelCase__	)
         a_						     =			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"""


         a_						     =			'sshleifer/tiny-gpt2'
         a_						     =			AutoConfig.from_pretrained(UpperCamelCase__	)
         a_						     =			PyTorchBenchmarkArguments(
             models=[MODEL_ID]   ,	training=UpperCamelCase__   ,	inference=UpperCamelCase__   ,	sequence_lengths=[8]   ,	batch_sizes=[1]   ,	multi_process=UpperCamelCase__   ,	)
         a_						     =			PyTorchBenchmark(UpperCamelCase__   ,	configs=[config]	)
         a_						     =			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"""


         a_						     =			'sshleifer/tinier_bart'
         a_						     =			AutoConfig.from_pretrained(UpperCamelCase__	)
         a_						     =			PyTorchBenchmarkArguments(
             models=[MODEL_ID]   ,	training=UpperCamelCase__   ,	inference=UpperCamelCase__   ,	sequence_lengths=[8]   ,	batch_sizes=[1]   ,	multi_process=UpperCamelCase__   ,	)
         a_						     =			PyTorchBenchmark(UpperCamelCase__   ,	configs=[config]	)
         a_						     =			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"""


         a_						     =			'sshleifer/tiny-gpt2'
         a_						     =			AutoConfig.from_pretrained(UpperCamelCase__	)
         a_						     =			PyTorchBenchmarkArguments(
             models=[MODEL_ID]   ,	training=UpperCamelCase__   ,	inference=UpperCamelCase__   ,	sequence_lengths=[8]   ,	batch_sizes=[1]   ,	multi_process=UpperCamelCase__   ,	)
         a_						     =			PyTorchBenchmark(UpperCamelCase__   ,	configs=[config]	)
         a_						     =			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"""


         a_						     =			'sshleifer/tinier_bart'
         a_						     =			AutoConfig.from_pretrained(UpperCamelCase__	)
         a_						     =			PyTorchBenchmarkArguments(
             models=[MODEL_ID]   ,	training=UpperCamelCase__   ,	inference=UpperCamelCase__   ,	sequence_lengths=[8]   ,	batch_sizes=[1]   ,	multi_process=UpperCamelCase__   ,	)
         a_						     =			PyTorchBenchmark(UpperCamelCase__   ,	configs=[config]	)
         a_						     =			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"""


         a_						     =			'sshleifer/tiny-gpt2'
         with tempfile.TemporaryDirectory() as tmp_dir:
                a_						     =			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__   ,	)
                a_						     =			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    _a       (			self	):






         """simple docstring"""


         a_						     =			'sshleifer/tiny-gpt2'

         def _check_summary_is_not_empty(UpperCamelCase__	):
                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:
                a_						     =			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__   ,	)
                a_						     =			PyTorchBenchmark(UpperCamelCase__	)
                a_						     =			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'''







import os
import sys
import unittest


__lowerCAmelCase        =							os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, "utils"))

import get_test_info  # noqa: E402
from get_test_info import (  # noqa: E402
    get_model_to_test_mapping,
    get_model_to_tester_mapping,
    get_test_to_tester_mapping,
)


__lowerCAmelCase        =							os.path.join("tests", "models", "bert", "test_modeling_bert.py")
__lowerCAmelCase        =							os.path.join("tests", "models", "blip", "test_modeling_blip.py")




class   __SCREAMING_SNAKE_CASE       (unittest.TestCase       ):


  """simple docstring"""


  def    _a       (			self	):






         """simple docstring"""


         a_						     =			get_test_to_tester_mapping(UpperCamelCase__	)
         a_						     =			get_test_to_tester_mapping(UpperCamelCase__	)

         a_						     =			{'BertModelTest': 'BertModelTester'}

         a_						     =			{
             'BlipModelTest': 'BlipModelTester',
             'BlipTextImageModelTest': 'BlipTextImageModelsModelTester',
             'BlipTextModelTest': 'BlipTextModelTester',
             'BlipTextRetrievalModelTest': 'BlipTextRetrievalModelTester',
             'BlipVQAModelTest': 'BlipVQAModelTester',
             'BlipVisionModelTest': 'BlipVisionModelTester',
         }

         self.assertEqual(get_test_info.to_json(UpperCamelCase__	)   ,	UpperCamelCase__	)
         self.assertEqual(get_test_info.to_json(UpperCamelCase__	)   ,	UpperCamelCase__	)







  def    _a       (			self	):






         """simple docstring"""


         a_						     =			get_model_to_test_mapping(UpperCamelCase__	)
         a_						     =			get_model_to_test_mapping(UpperCamelCase__	)

         a_						     =			{
             'BertForMaskedLM': ['BertModelTest'],
             'BertForMultipleChoice': ['BertModelTest'],
             'BertForNextSentencePrediction': ['BertModelTest'],
             'BertForPreTraining': ['BertModelTest'],
             'BertForQuestionAnswering': ['BertModelTest'],
             'BertForSequenceClassification': ['BertModelTest'],
             'BertForTokenClassification': ['BertModelTest'],
             'BertLMHeadModel': ['BertModelTest'],
             'BertModel': ['BertModelTest'],
         }

         a_						     =			{
             'BlipForConditionalGeneration': ['BlipTextImageModelTest'],
             'BlipForImageTextRetrieval': ['BlipTextRetrievalModelTest'],
             'BlipForQuestionAnswering': ['BlipVQAModelTest'],
             'BlipModel': ['BlipModelTest'],
             'BlipTextModel': ['BlipTextModelTest'],
             'BlipVisionModel': ['BlipVisionModelTest'],
         }

         self.assertEqual(get_test_info.to_json(UpperCamelCase__	)   ,	UpperCamelCase__	)
         self.assertEqual(get_test_info.to_json(UpperCamelCase__	)   ,	UpperCamelCase__	)







  def    _a       (			self	):






         """simple docstring"""


         a_						     =			get_model_to_tester_mapping(UpperCamelCase__	)
         a_						     =			get_model_to_tester_mapping(UpperCamelCase__	)

         a_						     =			{
             'BertForMaskedLM': ['BertModelTester'],
             'BertForMultipleChoice': ['BertModelTester'],
             'BertForNextSentencePrediction': ['BertModelTester'],
             'BertForPreTraining': ['BertModelTester'],
             'BertForQuestionAnswering': ['BertModelTester'],
             'BertForSequenceClassification': ['BertModelTester'],
             'BertForTokenClassification': ['BertModelTester'],
             'BertLMHeadModel': ['BertModelTester'],
             'BertModel': ['BertModelTester'],
         }

         a_						     =			{
             'BlipForConditionalGeneration': ['BlipTextImageModelsModelTester'],
             'BlipForImageTextRetrieval': ['BlipTextRetrievalModelTester'],
             'BlipForQuestionAnswering': ['BlipVQAModelTester'],
             'BlipModel': ['BlipModelTester'],
             'BlipTextModel': ['BlipTextModelTester'],
             'BlipVisionModel': ['BlipVisionModelTester'],
         }

         self.assertEqual(get_test_info.to_json(UpperCamelCase__	)   ,	UpperCamelCase__	)
         self.assertEqual(get_test_info.to_json(UpperCamelCase__	)   ,	UpperCamelCase__	)




