


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    UpperCAmelCase_	(							unittest.TestCase):
       '''simple docstring'''






       def  _lowercase   (     self ,					__SCREAMING_SNAKE_CASE						):




              """simple docstring"""




              for model_result in results.values():
                     for batch_size, sequence_length in zip(model_result['''bs'''] ,					model_result['''ss''']						):
                            UpperCamelCase    :	Union[str, Any]   	=		model_result['''result'''][batch_size][sequence_length]
                            self.assertIsNotNone(__SCREAMING_SNAKE_CASE						)






       def  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	Any   	=		'''sshleifer/tiny-gpt2'''
              UpperCamelCase    :	int   	=		PyTorchBenchmarkArguments(
                  models=[MODEL_ID] ,					training=__SCREAMING_SNAKE_CASE ,					inference=__SCREAMING_SNAKE_CASE ,					sequence_lengths=[8] ,					batch_sizes=[1] ,					multi_process=__SCREAMING_SNAKE_CASE ,					)
              UpperCamelCase    :	Optional[int]   	=		PyTorchBenchmark(__SCREAMING_SNAKE_CASE						)
              UpperCamelCase    :	List[Any]   	=		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						):




              """simple docstring"""




              UpperCamelCase    :	List[str]   	=		'''sgugger/tiny-distilbert-classification'''
              UpperCamelCase    :	Optional[Any]   	=		PyTorchBenchmarkArguments(
                  models=[MODEL_ID] ,					training=__SCREAMING_SNAKE_CASE ,					inference=__SCREAMING_SNAKE_CASE ,					sequence_lengths=[8] ,					batch_sizes=[1] ,					multi_process=__SCREAMING_SNAKE_CASE ,					only_pretrain_model=__SCREAMING_SNAKE_CASE ,					)
              UpperCamelCase    :	List[Any]   	=		PyTorchBenchmark(__SCREAMING_SNAKE_CASE						)
              UpperCamelCase    :	List[Any]   	=		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						):




              """simple docstring"""




              UpperCamelCase    :	List[str]   	=		'''sshleifer/tiny-gpt2'''
              UpperCamelCase    :	List[Any]   	=		PyTorchBenchmarkArguments(
                  models=[MODEL_ID] ,					training=__SCREAMING_SNAKE_CASE ,					inference=__SCREAMING_SNAKE_CASE ,					torchscript=__SCREAMING_SNAKE_CASE ,					sequence_lengths=[8] ,					batch_sizes=[1] ,					multi_process=__SCREAMING_SNAKE_CASE ,					)
              UpperCamelCase    :	List[Any]   	=		PyTorchBenchmark(__SCREAMING_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						)






       @unittest.skipIf(torch_device == '''cpu''' ,					'''Cant do half precision'''						)
       def  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	Dict   	=		'''sshleifer/tiny-gpt2'''
              UpperCamelCase    :	str   	=		PyTorchBenchmarkArguments(
                  models=[MODEL_ID] ,					training=__SCREAMING_SNAKE_CASE ,					inference=__SCREAMING_SNAKE_CASE ,					fpaa=__SCREAMING_SNAKE_CASE ,					sequence_lengths=[8] ,					batch_sizes=[1] ,					multi_process=__SCREAMING_SNAKE_CASE ,					)
              UpperCamelCase    :	List[str]   	=		PyTorchBenchmark(__SCREAMING_SNAKE_CASE						)
              UpperCamelCase    :	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  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	str   	=		'''sshleifer/tiny-gpt2'''
              UpperCamelCase    :	Optional[int]   	=		AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE						)
              # set architectures equal to `None`
              UpperCamelCase    :	Optional[int]   	=		None
              UpperCamelCase    :	Optional[int]   	=		PyTorchBenchmarkArguments(
                  models=[MODEL_ID] ,					training=__SCREAMING_SNAKE_CASE ,					inference=__SCREAMING_SNAKE_CASE ,					sequence_lengths=[8] ,					batch_sizes=[1] ,					multi_process=__SCREAMING_SNAKE_CASE ,					)
              UpperCamelCase    :	str   	=		PyTorchBenchmark(__SCREAMING_SNAKE_CASE ,					configs=[config]						)
              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  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	Optional[Any]   	=		'''sshleifer/tiny-gpt2'''
              UpperCamelCase    :	List[str]   	=		PyTorchBenchmarkArguments(
                  models=[MODEL_ID] ,					training=__SCREAMING_SNAKE_CASE ,					inference=__SCREAMING_SNAKE_CASE ,					sequence_lengths=[8] ,					batch_sizes=[1] ,					multi_process=__SCREAMING_SNAKE_CASE ,					)
              UpperCamelCase    :	str   	=		PyTorchBenchmark(__SCREAMING_SNAKE_CASE						)
              UpperCamelCase    :	Optional[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  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	Optional[Any]   	=		'''sshleifer/tiny-gpt2'''
              UpperCamelCase    :	List[Any]   	=		PyTorchBenchmarkArguments(
                  models=[MODEL_ID] ,					training=__SCREAMING_SNAKE_CASE ,					inference=__SCREAMING_SNAKE_CASE ,					sequence_lengths=[8] ,					batch_sizes=[1] ,					fpaa=__SCREAMING_SNAKE_CASE ,					multi_process=__SCREAMING_SNAKE_CASE ,					)
              UpperCamelCase    :	Optional[Any]   	=		PyTorchBenchmark(__SCREAMING_SNAKE_CASE						)
              UpperCamelCase    :	List[Any]   	=		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						):




              """simple docstring"""




              UpperCamelCase    :	Tuple   	=		'''sshleifer/tiny-gpt2'''
              UpperCamelCase    :	str   	=		AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE						)
              UpperCamelCase    :	Optional[int]   	=		PyTorchBenchmarkArguments(
                  models=[MODEL_ID] ,					training=__SCREAMING_SNAKE_CASE ,					inference=__SCREAMING_SNAKE_CASE ,					sequence_lengths=[8] ,					batch_sizes=[1] ,					multi_process=__SCREAMING_SNAKE_CASE ,					)
              UpperCamelCase    :	int   	=		PyTorchBenchmark(__SCREAMING_SNAKE_CASE ,					configs=[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  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	str   	=		'''sshleifer/tinier_bart'''
              UpperCamelCase    :	List[Any]   	=		AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE						)
              UpperCamelCase    :	List[Any]   	=		PyTorchBenchmarkArguments(
                  models=[MODEL_ID] ,					training=__SCREAMING_SNAKE_CASE ,					inference=__SCREAMING_SNAKE_CASE ,					sequence_lengths=[8] ,					batch_sizes=[1] ,					multi_process=__SCREAMING_SNAKE_CASE ,					)
              UpperCamelCase    :	List[Any]   	=		PyTorchBenchmark(__SCREAMING_SNAKE_CASE ,					configs=[config]						)
              UpperCamelCase    :	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  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	Tuple   	=		'''sshleifer/tiny-gpt2'''
              UpperCamelCase    :	Any   	=		AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE						)
              UpperCamelCase    :	int   	=		PyTorchBenchmarkArguments(
                  models=[MODEL_ID] ,					training=__SCREAMING_SNAKE_CASE ,					inference=__SCREAMING_SNAKE_CASE ,					sequence_lengths=[8] ,					batch_sizes=[1] ,					multi_process=__SCREAMING_SNAKE_CASE ,					)
              UpperCamelCase    :	Tuple   	=		PyTorchBenchmark(__SCREAMING_SNAKE_CASE ,					configs=[config]						)
              UpperCamelCase    :	Any   	=		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						):




              """simple docstring"""




              UpperCamelCase    :	Any   	=		'''sshleifer/tinier_bart'''
              UpperCamelCase    :	Any   	=		AutoConfig.from_pretrained(__SCREAMING_SNAKE_CASE						)
              UpperCamelCase    :	List[Any]   	=		PyTorchBenchmarkArguments(
                  models=[MODEL_ID] ,					training=__SCREAMING_SNAKE_CASE ,					inference=__SCREAMING_SNAKE_CASE ,					sequence_lengths=[8] ,					batch_sizes=[1] ,					multi_process=__SCREAMING_SNAKE_CASE ,					)
              UpperCamelCase    :	Optional[Any]   	=		PyTorchBenchmark(__SCREAMING_SNAKE_CASE ,					configs=[config]						)
              UpperCamelCase    :	Any   	=		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						):




              """simple docstring"""




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






       def  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	List[str]   	=		'''sshleifer/tiny-gpt2'''

              def _check_summary_is_not_empty(__SCREAMING_SNAKE_CASE						):
                     self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE ,					'''sequential'''						)						)
                     self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE ,					'''cumulative'''						)						)
                     self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE ,					'''current'''						)						)
                     self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE ,					'''total'''						)						)

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





def      a	(							SCREAMING_SNAKE_CASE_      :		int							,			SCREAMING_SNAKE_CASE_      :		int       ):






       """simple docstring"""





       if a < 0 or b < 0:
              raise ValueError('''the value of both inputs must be positive'''       )
       UpperCamelCase    :	int   	=		str(bin(SCREAMING_SNAKE_CASE_       )       )[2:]  # remove the leading "0b"
       UpperCamelCase    :	List[str]   	=		str(bin(SCREAMING_SNAKE_CASE_       )       )[2:]
       UpperCamelCase    :	Tuple   	=		max(len(SCREAMING_SNAKE_CASE_       )							,			len(SCREAMING_SNAKE_CASE_       )       )
       return "0b" + "".join(
           str(int('''1''' in (char_a, char_b)       )       )
           for char_a, char_b in zip(a_binary.zfill(SCREAMING_SNAKE_CASE_       )							,			b_binary.zfill(SCREAMING_SNAKE_CASE_       )       )       )


if __name__ == "__main__":
  import doctest

  doctest.testmod()

