






'''simple docstring'''







import shutil
import tempfile
import unittest

from transformers import (
    SPIECE_UNDERLINE,
    AddedToken,
    BatchEncoding,
    NllbTokenizer,
    NllbTokenizerFast,
    is_torch_available,
)
from transformers.testing_utils import (
    get_tests_dir,
    nested_simplify,
    require_sentencepiece,
    require_tokenizers,
    require_torch,
)

from ...test_tokenization_common import TokenizerTesterMixin


UpperCamelCase    :      Optional[int]  			=		get_tests_dir('fixtures/test_sentencepiece.model')


if is_torch_available():
							from transformers.models.mam_aaa.modeling_mam_aaa import shift_tokens_right

UpperCamelCase    :      List[Any]  			=		25_60_47
UpperCamelCase    :      Dict  			=		25_61_45




@require_sentencepiece
@require_tokenizers
class 		UpperCamelCase__    (a   ,unittest.TestCase			):




		'''simple docstring'''





		_UpperCamelCase				  =					NllbTokenizer
		_UpperCamelCase				  =					NllbTokenizerFast
		_UpperCamelCase				  =					True
		_UpperCamelCase				  =					True
		_UpperCamelCase				  =					{}






		def 			UpperCamelCase_					(      self       ):
								super().setUp()

								# We have a SentencePiece fixture for testing
								lowerCamelCase__         =  NllbTokenizer(_lowerCAmelCase   ,keep_accents=_lowerCAmelCase       )
								tokenizer.save_pretrained(self.tmpdirname       )






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  NllbTokenizer(_lowerCAmelCase   ,keep_accents=_lowerCAmelCase       )

								lowerCamelCase__         =  tokenizer.tokenize("""This is a test"""       )
								self.assertListEqual(_lowerCAmelCase   ,["""▁This""", """▁is""", """▁a""", """▁t""", """est"""]       )

								self.assertListEqual(
								    tokenizer.convert_tokens_to_ids(_lowerCAmelCase       )   ,[value + tokenizer.fairseq_offset for value in [2_85, 46, 10, 1_70, 3_82]]   ,)

								lowerCamelCase__         =  tokenizer.tokenize("""I was born in 92000, and this is falsé."""       )
								self.assertListEqual(
								    _lowerCAmelCase   ,[
								        SPIECE_UNDERLINE + """I""",
								        SPIECE_UNDERLINE + """was""",
								        SPIECE_UNDERLINE + """b""",
								        """or""",
								        """n""",
								        SPIECE_UNDERLINE + """in""",
								        SPIECE_UNDERLINE + """""",
								        """9""",
								        """2""",
								        """0""",
								        """0""",
								        """0""",
								        """,""",
								        SPIECE_UNDERLINE + """and""",
								        SPIECE_UNDERLINE + """this""",
								        SPIECE_UNDERLINE + """is""",
								        SPIECE_UNDERLINE + """f""",
								        """al""",
								        """s""",
								        """é""",
								        """.""",
								    ]   ,)
								lowerCamelCase__         =  tokenizer.convert_tokens_to_ids(_lowerCAmelCase       )
								self.assertListEqual(
								    _lowerCAmelCase   ,[
								        value + tokenizer.fairseq_offset
								        for value in [8, 21, 84, 55, 24, 19, 7, 2, 6_02, 3_47, 3_47, 3_47, 3, 12, 66, 46, 72, 80, 6, 2, 4]
								    ]   ,)

								lowerCamelCase__         =  tokenizer.convert_ids_to_tokens(_lowerCAmelCase       )
								self.assertListEqual(
								    _lowerCAmelCase   ,[
								        SPIECE_UNDERLINE + """I""",
								        SPIECE_UNDERLINE + """was""",
								        SPIECE_UNDERLINE + """b""",
								        """or""",
								        """n""",
								        SPIECE_UNDERLINE + """in""",
								        SPIECE_UNDERLINE + """""",
								        """<unk>""",
								        """2""",
								        """0""",
								        """0""",
								        """0""",
								        """,""",
								        SPIECE_UNDERLINE + """and""",
								        SPIECE_UNDERLINE + """this""",
								        SPIECE_UNDERLINE + """is""",
								        SPIECE_UNDERLINE + """f""",
								        """al""",
								        """s""",
								        """<unk>""",
								        """.""",
								    ]   ,)






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  (self.rust_tokenizer_class, """hf-internal-testing/tiny-random-nllb""", {})
								for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
														with self.subTest(F'''{tokenizer.__class__.__name__} ({pretrained_name})'''       ):
																				lowerCamelCase__         =  self.rust_tokenizer_class.from_pretrained(_lowerCAmelCase   ,**_lowerCAmelCase       )
																				lowerCamelCase__         =  self.tokenizer_class.from_pretrained(_lowerCAmelCase   ,**_lowerCAmelCase       )

																				lowerCamelCase__         =  tempfile.mkdtemp()

																				lowerCamelCase__         =  tokenizer_r.save_pretrained(_lowerCAmelCase       )
																				lowerCamelCase__         =  tokenizer_p.save_pretrained(_lowerCAmelCase       )

																				# Checks it save with the same files + the tokenizer.json file for the fast one
																				self.assertTrue(any("""tokenizer.json""" in f for f in tokenizer_r_files       )       )
																				lowerCamelCase__         =  tuple(f for f in tokenizer_r_files if """tokenizer.json""" not in f       )
																				self.assertSequenceEqual(_lowerCAmelCase   ,_lowerCAmelCase       )

																				# Checks everything loads correctly in the same way
																				lowerCamelCase__         =  tokenizer_r.from_pretrained(_lowerCAmelCase       )
																				lowerCamelCase__         =  tokenizer_p.from_pretrained(_lowerCAmelCase       )

																				# Check special tokens are set accordingly on Rust and Python
																				for key in tokenizer_pp.special_tokens_map:
																										self.assertTrue(hasattr(_lowerCAmelCase   ,_lowerCAmelCase       )       )

																				shutil.rmtree(_lowerCAmelCase       )

																				# Save tokenizer rust, legacy_format=True
																				lowerCamelCase__         =  tempfile.mkdtemp()

																				lowerCamelCase__         =  tokenizer_r.save_pretrained(_lowerCAmelCase   ,legacy_format=_lowerCAmelCase       )
																				lowerCamelCase__         =  tokenizer_p.save_pretrained(_lowerCAmelCase       )

																				# Checks it save with the same files
																				self.assertSequenceEqual(_lowerCAmelCase   ,_lowerCAmelCase       )

																				# Checks everything loads correctly in the same way
																				lowerCamelCase__         =  tokenizer_r.from_pretrained(_lowerCAmelCase       )
																				lowerCamelCase__         =  tokenizer_p.from_pretrained(_lowerCAmelCase       )

																				# Check special tokens are set accordingly on Rust and Python
																				for key in tokenizer_pp.special_tokens_map:
																										self.assertTrue(hasattr(_lowerCAmelCase   ,_lowerCAmelCase       )       )

																				shutil.rmtree(_lowerCAmelCase       )

																				# Save tokenizer rust, legacy_format=False
																				lowerCamelCase__         =  tempfile.mkdtemp()

																				lowerCamelCase__         =  tokenizer_r.save_pretrained(_lowerCAmelCase   ,legacy_format=_lowerCAmelCase       )
																				lowerCamelCase__         =  tokenizer_p.save_pretrained(_lowerCAmelCase       )

																				# Checks it saved the tokenizer.json file
																				self.assertTrue(any("""tokenizer.json""" in f for f in tokenizer_r_files       )       )

																				# Checks everything loads correctly in the same way
																				lowerCamelCase__         =  tokenizer_r.from_pretrained(_lowerCAmelCase       )
																				lowerCamelCase__         =  tokenizer_p.from_pretrained(_lowerCAmelCase       )

																				# Check special tokens are set accordingly on Rust and Python
																				for key in tokenizer_pp.special_tokens_map:
																										self.assertTrue(hasattr(_lowerCAmelCase   ,_lowerCAmelCase       )       )

																				shutil.rmtree(_lowerCAmelCase       )






		@require_torch
		def 			UpperCamelCase_					(      self       ):
								if not self.test_seqaseq:
														return

								lowerCamelCase__         =  self.get_tokenizers()
								for tokenizer in tokenizers:
														with self.subTest(F'''{tokenizer.__class__.__name__}'''       ):
																				# Longer text that will definitely require truncation.
																				lowerCamelCase__         =  [
																				    """ UN Chief Says There Is No Military Solution in Syria""",
																				    """ Secretary-General Ban Ki-moon says his response to Russia's stepped up military support for"""
																				    """ Syria is that 'there is no military solution' to the nearly five-year conflict and more weapons"""
																				    """ will only worsen the violence and misery for millions of people.""",
																				]
																				lowerCamelCase__         =  [
																				    """Şeful ONU declară că nu există o soluţie militară în Siria""",
																				    """Secretarul General Ban Ki-moon declară că răspunsul său la intensificarea sprijinului militar al"""
																				    """ Rusiei pentru Siria este că \"nu există o soluţie militară\" la conflictul de aproape cinci ani şi"""
																				    """ că noi arme nu vor face decât să înrăutăţească violenţele şi mizeria pentru milioane de oameni.""",
																				]
																				try:
																										lowerCamelCase__         =  tokenizer.prepare_seqaseq_batch(
																										    src_texts=_lowerCAmelCase   ,tgt_texts=_lowerCAmelCase   ,max_length=3   ,max_target_length=10   ,return_tensors="""pt"""   ,src_lang="""eng_Latn"""   ,tgt_lang="""ron_Latn"""   ,)
																				except NotImplementedError:
																										return
																				self.assertEqual(batch.input_ids.shape[1]   ,3       )
																				self.assertEqual(batch.labels.shape[1]   ,10       )
																				# max_target_length will default to max_length if not specified
																				lowerCamelCase__         =  tokenizer.prepare_seqaseq_batch(
																				    _lowerCAmelCase   ,tgt_texts=_lowerCAmelCase   ,max_length=3   ,return_tensors="""pt"""       )
																				self.assertEqual(batch.input_ids.shape[1]   ,3       )
																				self.assertEqual(batch.labels.shape[1]   ,3       )

																				lowerCamelCase__         =  tokenizer.prepare_seqaseq_batch(
																				    src_texts=_lowerCAmelCase   ,max_length=3   ,max_target_length=10   ,return_tensors="""pt"""       )
																				self.assertEqual(batch_encoder_only.input_ids.shape[1]   ,3       )
																				self.assertEqual(batch_encoder_only.attention_mask.shape[1]   ,3       )
																				self.assertNotIn("""decoder_input_ids"""   ,_lowerCAmelCase       )






		@unittest.skip("""Unfortunately way too slow to build a BPE with SentencePiece."""       )
		def 			UpperCamelCase_					(      self       ):
								pass






		def 			UpperCamelCase_					(      self       ):
								for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
														with self.subTest(F'''{tokenizer.__class__.__name__} ({pretrained_name})'''       ):
																				lowerCamelCase__         =  [AddedToken("""<special>"""   ,lstrip=_lowerCAmelCase       )]

																				lowerCamelCase__         =  self.rust_tokenizer_class.from_pretrained(
																				    _lowerCAmelCase   ,additional_special_tokens=_lowerCAmelCase   ,**_lowerCAmelCase       )
																				lowerCamelCase__         =  tokenizer_r.encode("""Hey this is a <special> token"""       )

																				lowerCamelCase__         =  tokenizer_r.encode("""<special>"""   ,add_special_tokens=_lowerCAmelCase       )[0]

																				self.assertTrue(special_token_id in r_output       )

																				if self.test_slow_tokenizer:
																										lowerCamelCase__         =  self.rust_tokenizer_class.from_pretrained(
																										    _lowerCAmelCase   ,additional_special_tokens=_lowerCAmelCase   ,**_lowerCAmelCase   ,)
																										lowerCamelCase__         =  self.tokenizer_class.from_pretrained(
																										    _lowerCAmelCase   ,additional_special_tokens=_lowerCAmelCase   ,**_lowerCAmelCase       )

																										lowerCamelCase__         =  tokenizer_p.encode("""Hey this is a <special> token"""       )

																										lowerCamelCase__         =  tokenizer_cr.encode("""Hey this is a <special> token"""       )

																										self.assertEqual(_lowerCAmelCase   ,_lowerCAmelCase       )
																										self.assertEqual(_lowerCAmelCase   ,_lowerCAmelCase       )
																										self.assertTrue(special_token_id in p_output       )
																										self.assertTrue(special_token_id in cr_output       )




@require_torch
@require_sentencepiece
@require_tokenizers
class 		UpperCamelCase__    (unittest.TestCase			):




		'''simple docstring'''





		_UpperCamelCase				  =					'facebook/nllb-200-distilled-600M'
		_UpperCamelCase				  =					[
		    ' UN Chief Says There Is No Military Solution in Syria',
		    ' Secretary-General Ban Ki-moon says his response to Russia\'s stepped up military support for Syria is that "there is no military solution" to the nearly five-year conflict and more weapons will only worsen the violence and misery for millions of people.',
		]
		_UpperCamelCase				  =					[
		    'Şeful ONU declară că nu există o soluţie militară în Siria',
		    'Secretarul General Ban Ki-moon declară că răspunsul său la intensificarea sprijinului militar al Rusiei'
		    ' pentru Siria este că "nu există o soluţie militară" la conflictul de aproape cinci ani şi că noi arme nu vor'
		    ' face decât să înrăutăţească violenţele şi mizeria pentru milioane de oameni.',
		]
		_UpperCamelCase				  =					[
		    256047,
		    16297,
		    134408,
		    8165,
		    248066,
		    14734,
		    950,
		    1135,
		    105721,
		    3573,
		    83,
		    27352,
		    108,
		    49486,
		    2,
		]






		@classmethod
		def 			UpperCamelCase_					(      cls       ):
								lowerCamelCase__         =  NllbTokenizer.from_pretrained(
								    cls.checkpoint_name   ,src_lang="""eng_Latn"""   ,tgt_lang="""ron_Latn"""       )
								lowerCamelCase__         =  1
								return cls






		def 			UpperCamelCase_					(      self       ):
								self.assertEqual(self.tokenizer.fairseq_tokens_to_ids["""ace_Arab"""]   ,25_60_01       )
								self.assertEqual(self.tokenizer.fairseq_tokens_to_ids["""ace_Latn"""]   ,25_60_02       )
								self.assertEqual(self.tokenizer.fairseq_tokens_to_ids["""fra_Latn"""]   ,25_60_57       )






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  self.tokenizer.batch_encode_plus(self.src_text       ).input_ids[0]
								self.assertListEqual(self.expected_src_tokens   ,_lowerCAmelCase       )






		def 			UpperCamelCase_					(      self       ):
								self.assertIn(_lowerCAmelCase   ,self.tokenizer.all_special_ids       )
								# fmt: off
								lowerCamelCase__         =  [RO_CODE, 42_54, 9_80_68, 11_29_23, 3_90_72, 39_09, 7_13, 10_27_67, 26, 1_73_14, 3_56_42, 1_46_83, 3_31_18, 20_22, 6_69_87, 2, 25_60_47]
								# fmt: on

								lowerCamelCase__         =  self.tokenizer.decode(_lowerCAmelCase   ,skip_special_tokens=_lowerCAmelCase       )
								lowerCamelCase__         =  self.tokenizer.decode(generated_ids[1:]   ,skip_special_tokens=_lowerCAmelCase       )
								self.assertEqual(_lowerCAmelCase   ,_lowerCAmelCase       )
								self.assertNotIn(self.tokenizer.eos_token   ,_lowerCAmelCase       )






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  ["""this is gunna be a long sentence """ * 20]
								assert isinstance(src_text[0]   ,_lowerCAmelCase       )
								lowerCamelCase__         =  10
								lowerCamelCase__         =  self.tokenizer(_lowerCAmelCase   ,max_length=_lowerCAmelCase   ,truncation=_lowerCAmelCase       ).input_ids[0]
								self.assertEqual(ids[-1]   ,2       )
								self.assertEqual(ids[0]   ,_lowerCAmelCase       )
								self.assertEqual(len(_lowerCAmelCase       )   ,_lowerCAmelCase       )






		def 			UpperCamelCase_					(      self       ):
								self.assertListEqual(self.tokenizer.convert_tokens_to_ids(["""<mask>""", """ar_AR"""]       )   ,[25_62_03, 3]       )






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  tempfile.mkdtemp()
								lowerCamelCase__         =  self.tokenizer.fairseq_tokens_to_ids
								self.tokenizer.save_pretrained(_lowerCAmelCase       )
								lowerCamelCase__         =  NllbTokenizer.from_pretrained(_lowerCAmelCase       )
								self.assertDictEqual(new_tok.fairseq_tokens_to_ids   ,_lowerCAmelCase       )






		@require_torch
		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  self.tokenizer(
								    self.src_text   ,text_target=self.tgt_text   ,padding=_lowerCAmelCase   ,truncation=_lowerCAmelCase   ,max_length=len(self.expected_src_tokens       )   ,return_tensors="""pt"""   ,)
								lowerCamelCase__         =  shift_tokens_right(
								    batch["""labels"""]   ,self.tokenizer.pad_token_id   ,self.tokenizer.lang_code_to_id["""ron_Latn"""]       )

								self.assertIsInstance(_lowerCAmelCase   ,_lowerCAmelCase       )

								self.assertEqual((2, 15)   ,batch.input_ids.shape       )
								self.assertEqual((2, 15)   ,batch.attention_mask.shape       )
								lowerCamelCase__         =  batch.input_ids.tolist()[0]
								self.assertListEqual(self.expected_src_tokens   ,_lowerCAmelCase       )
								self.assertEqual(_lowerCAmelCase   ,batch.decoder_input_ids[0, 0]       )  # EOS
								# Test that special tokens are reset
								self.assertEqual(self.tokenizer.prefix_tokens   ,[EN_CODE]       )
								self.assertEqual(self.tokenizer.suffix_tokens   ,[self.tokenizer.eos_token_id]       )






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  self.tokenizer(self.src_text   ,padding=_lowerCAmelCase   ,truncation=_lowerCAmelCase   ,max_length=3   ,return_tensors="""pt"""       )
								lowerCamelCase__         =  self.tokenizer(
								    text_target=self.tgt_text   ,padding=_lowerCAmelCase   ,truncation=_lowerCAmelCase   ,max_length=10   ,return_tensors="""pt"""       )
								lowerCamelCase__         =  targets["""input_ids"""]
								lowerCamelCase__         =  shift_tokens_right(
								    _lowerCAmelCase   ,self.tokenizer.pad_token_id   ,decoder_start_token_id=self.tokenizer.lang_code_to_id[self.tokenizer.tgt_lang]   ,)

								self.assertEqual(batch.input_ids.shape[1]   ,3       )
								self.assertEqual(batch.decoder_input_ids.shape[1]   ,10       )






		@require_torch
		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  self.tokenizer._build_translation_inputs(
								    """A test"""   ,return_tensors="""pt"""   ,src_lang="""eng_Latn"""   ,tgt_lang="""fra_Latn"""       )

								self.assertEqual(
								    nested_simplify(_lowerCAmelCase       )   ,{
								        # A, test, EOS, en_XX
								        """input_ids""": [[25_60_47, 70, 73_56, 2]],
								        """attention_mask""": [[1, 1, 1, 1]],
								        # ar_AR
								        """forced_bos_token_id""": 25_60_57,
								    }   ,)






		@require_torch
		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  True
								lowerCamelCase__         =  self.tokenizer(
								    """UN Chief says there is no military solution in Syria"""   ,src_lang="""eng_Latn"""   ,tgt_lang="""fra_Latn"""       )
								self.assertEqual(
								    inputs.input_ids   ,[1_62_97, 13_44_08, 2_56_53, 63_70, 2_48, 2_54, 10_39_29, 9_49_95, 1_08, 4_94_86, 2, 25_60_47]       )

								lowerCamelCase__         =  False
								lowerCamelCase__         =  self.tokenizer(
								    """UN Chief says there is no military solution in Syria"""   ,src_lang="""eng_Latn"""   ,tgt_lang="""fra_Latn"""       )
								self.assertEqual(
								    inputs.input_ids   ,[25_60_47, 1_62_97, 13_44_08, 2_56_53, 63_70, 2_48, 2_54, 10_39_29, 9_49_95, 1_08, 4_94_86, 2]       )









'''simple docstring'''







import os
import tempfile
import unittest
from pathlib import Path

from transformers import AutoConfig, is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
							import tensorflow as tf

							from transformers import TensorFlowBenchmark, TensorFlowBenchmarkArguments




@require_tf
class 		UpperCamelCase__    (unittest.TestCase			):




		'''simple docstring'''





		def 			UpperCamelCase_					(      self   ,_lowerCAmelCase       ):
								for model_result in results.values():
														for batch_size, sequence_length in zip(model_result["""bs"""]   ,model_result["""ss"""]       ):
																				lowerCamelCase__         =  model_result["""result"""][batch_size][sequence_length]
																				self.assertIsNotNone(_lowerCAmelCase       )






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  """sshleifer/tiny-gpt2"""
								lowerCamelCase__         =  TensorFlowBenchmarkArguments(
								    models=[MODEL_ID]   ,training=_lowerCAmelCase   ,inference=_lowerCAmelCase   ,sequence_lengths=[8]   ,batch_sizes=[1]   ,eager_mode=_lowerCAmelCase   ,multi_process=_lowerCAmelCase   ,)
								lowerCamelCase__         =  TensorFlowBenchmark(_lowerCAmelCase       )
								lowerCamelCase__         =  benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result       )
								self.check_results_dict_not_empty(results.memory_inference_result       )






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  """sgugger/tiny-distilbert-classification"""
								lowerCamelCase__         =  TensorFlowBenchmarkArguments(
								    models=[MODEL_ID]   ,training=_lowerCAmelCase   ,inference=_lowerCAmelCase   ,sequence_lengths=[8]   ,batch_sizes=[1]   ,multi_process=_lowerCAmelCase   ,only_pretrain_model=_lowerCAmelCase   ,)
								lowerCamelCase__         =  TensorFlowBenchmark(_lowerCAmelCase       )
								lowerCamelCase__         =  benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result       )
								self.check_results_dict_not_empty(results.memory_inference_result       )






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  """sshleifer/tiny-gpt2"""
								lowerCamelCase__         =  TensorFlowBenchmarkArguments(
								    models=[MODEL_ID]   ,training=_lowerCAmelCase   ,inference=_lowerCAmelCase   ,sequence_lengths=[8]   ,batch_sizes=[1]   ,multi_process=_lowerCAmelCase   ,)
								lowerCamelCase__         =  TensorFlowBenchmark(_lowerCAmelCase       )
								lowerCamelCase__         =  benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result       )
								self.check_results_dict_not_empty(results.memory_inference_result       )






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  """sshleifer/tiny-gpt2"""
								lowerCamelCase__         =  AutoConfig.from_pretrained(_lowerCAmelCase       )
								lowerCamelCase__         =  TensorFlowBenchmarkArguments(
								    models=[MODEL_ID]   ,training=_lowerCAmelCase   ,inference=_lowerCAmelCase   ,sequence_lengths=[8]   ,batch_sizes=[1]   ,eager_mode=_lowerCAmelCase   ,multi_process=_lowerCAmelCase   ,)
								lowerCamelCase__         =  TensorFlowBenchmark(_lowerCAmelCase   ,[config]       )
								lowerCamelCase__         =  benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result       )
								self.check_results_dict_not_empty(results.memory_inference_result       )






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  """sshleifer/tiny-gpt2"""
								lowerCamelCase__         =  AutoConfig.from_pretrained(_lowerCAmelCase       )
								lowerCamelCase__         =  TensorFlowBenchmarkArguments(
								    models=[MODEL_ID]   ,training=_lowerCAmelCase   ,inference=_lowerCAmelCase   ,sequence_lengths=[8]   ,batch_sizes=[1]   ,multi_process=_lowerCAmelCase   ,)
								lowerCamelCase__         =  TensorFlowBenchmark(_lowerCAmelCase   ,[config]       )
								lowerCamelCase__         =  benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result       )
								self.check_results_dict_not_empty(results.memory_inference_result       )






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  """sshleifer/tiny-gpt2"""
								lowerCamelCase__         =  TensorFlowBenchmarkArguments(
								    models=[MODEL_ID]   ,training=_lowerCAmelCase   ,inference=_lowerCAmelCase   ,sequence_lengths=[8]   ,batch_sizes=[1]   ,multi_process=_lowerCAmelCase   ,)
								lowerCamelCase__         =  TensorFlowBenchmark(_lowerCAmelCase       )
								lowerCamelCase__         =  benchmark.run()
								self.check_results_dict_not_empty(results.time_train_result       )
								self.check_results_dict_not_empty(results.memory_train_result       )






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  """sshleifer/tiny-gpt2"""
								lowerCamelCase__         =  AutoConfig.from_pretrained(_lowerCAmelCase       )
								lowerCamelCase__         =  TensorFlowBenchmarkArguments(
								    models=[MODEL_ID]   ,training=_lowerCAmelCase   ,inference=_lowerCAmelCase   ,sequence_lengths=[8]   ,batch_sizes=[1]   ,multi_process=_lowerCAmelCase   ,)
								lowerCamelCase__         =  TensorFlowBenchmark(_lowerCAmelCase   ,[config]       )
								lowerCamelCase__         =  benchmark.run()
								self.check_results_dict_not_empty(results.time_train_result       )
								self.check_results_dict_not_empty(results.memory_train_result       )






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  """patrickvonplaten/t5-tiny-random"""
								lowerCamelCase__         =  AutoConfig.from_pretrained(_lowerCAmelCase       )
								lowerCamelCase__         =  TensorFlowBenchmarkArguments(
								    models=[MODEL_ID]   ,training=_lowerCAmelCase   ,inference=_lowerCAmelCase   ,sequence_lengths=[8]   ,batch_sizes=[1]   ,multi_process=_lowerCAmelCase   ,)
								lowerCamelCase__         =  TensorFlowBenchmark(_lowerCAmelCase   ,configs=[config]       )
								lowerCamelCase__         =  benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result       )
								self.check_results_dict_not_empty(results.memory_inference_result       )






		@unittest.skipIf(is_tf_available() and len(tf.config.list_physical_devices("""GPU"""       )       ) == 0   ,"""Cannot do xla on CPU."""       )
		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  """sshleifer/tiny-gpt2"""
								lowerCamelCase__         =  TensorFlowBenchmarkArguments(
								    models=[MODEL_ID]   ,training=_lowerCAmelCase   ,inference=_lowerCAmelCase   ,sequence_lengths=[8]   ,batch_sizes=[1]   ,use_xla=_lowerCAmelCase   ,multi_process=_lowerCAmelCase   ,)
								lowerCamelCase__         =  TensorFlowBenchmark(_lowerCAmelCase       )
								lowerCamelCase__         =  benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result       )
								self.check_results_dict_not_empty(results.memory_inference_result       )






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  """sshleifer/tiny-gpt2"""
								with tempfile.TemporaryDirectory() as tmp_dir:
														lowerCamelCase__         =  TensorFlowBenchmarkArguments(
														    models=[MODEL_ID]   ,inference=_lowerCAmelCase   ,save_to_csv=_lowerCAmelCase   ,sequence_lengths=[8]   ,batch_sizes=[1]   ,inference_time_csv_file=os.path.join(_lowerCAmelCase   ,"""inf_time.csv"""       )   ,inference_memory_csv_file=os.path.join(_lowerCAmelCase   ,"""inf_mem.csv"""       )   ,env_info_csv_file=os.path.join(_lowerCAmelCase   ,"""env.csv"""       )   ,multi_process=_lowerCAmelCase   ,)
														lowerCamelCase__         =  TensorFlowBenchmark(_lowerCAmelCase       )
														benchmark.run()
														self.assertTrue(Path(os.path.join(_lowerCAmelCase   ,"""inf_time.csv"""       )       ).exists()       )
														self.assertTrue(Path(os.path.join(_lowerCAmelCase   ,"""inf_mem.csv"""       )       ).exists()       )
														self.assertTrue(Path(os.path.join(_lowerCAmelCase   ,"""env.csv"""       )       ).exists()       )






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  """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:
														lowerCamelCase__         =  TensorFlowBenchmarkArguments(
														    models=[MODEL_ID]   ,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   ,eager_mode=_lowerCAmelCase   ,multi_process=_lowerCAmelCase   ,)
														lowerCamelCase__         =  TensorFlowBenchmark(_lowerCAmelCase       )
														lowerCamelCase__         =  benchmark.run()
														_check_summary_is_not_empty(result.inference_summary       )
														self.assertTrue(Path(os.path.join(_lowerCAmelCase   ,"""log.txt"""       )       ).exists()       )

