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




					"""simple docstring"""

					def 		__lowerCAmelCase						(				self   :	Union[str, Any]    ,lowerCamelCase__   :	Optional[Any]			):
									for model_result in results.values():
													for batch_size, sequence_length in zip(model_result['bs']    ,model_result['ss']			):
																	UpperCAmelCase__             =							model_result['result'][batch_size][sequence_length]
																	self.assertIsNotNone(_A			)







					def 		__lowerCAmelCase						(				self   :	List[str]			):
									UpperCAmelCase__             =							'sshleifer/tiny-gpt2'
									UpperCAmelCase__             =							TensorFlowBenchmarkArguments(
									    models=[MODEL_ID]    ,training=_A    ,inference=_A    ,sequence_lengths=[8]    ,batch_sizes=[1]    ,eager_mode=_A    ,multi_process=_A    ,)
									UpperCAmelCase__             =							TensorFlowBenchmark(_A			)
									UpperCAmelCase__             =							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   :	List[Any]			):
									UpperCAmelCase__             =							'sgugger/tiny-distilbert-classification'
									UpperCAmelCase__             =							TensorFlowBenchmarkArguments(
									    models=[MODEL_ID]    ,training=_A    ,inference=_A    ,sequence_lengths=[8]    ,batch_sizes=[1]    ,multi_process=_A    ,only_pretrain_model=_A    ,)
									UpperCAmelCase__             =							TensorFlowBenchmark(_A			)
									UpperCAmelCase__             =							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   :	Tuple			):
									UpperCAmelCase__             =							'sshleifer/tiny-gpt2'
									UpperCAmelCase__             =							TensorFlowBenchmarkArguments(
									    models=[MODEL_ID]    ,training=_A    ,inference=_A    ,sequence_lengths=[8]    ,batch_sizes=[1]    ,multi_process=_A    ,)
									UpperCAmelCase__             =							TensorFlowBenchmark(_A			)
									UpperCAmelCase__             =							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   :	Union[str, Any]			):
									UpperCAmelCase__             =							'sshleifer/tiny-gpt2'
									UpperCAmelCase__             =							AutoConfig.from_pretrained(_A			)
									UpperCAmelCase__             =							TensorFlowBenchmarkArguments(
									    models=[MODEL_ID]    ,training=_A    ,inference=_A    ,sequence_lengths=[8]    ,batch_sizes=[1]    ,eager_mode=_A    ,multi_process=_A    ,)
									UpperCAmelCase__             =							TensorFlowBenchmark(_A    ,[config]			)
									UpperCAmelCase__             =							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   :	Tuple			):
									UpperCAmelCase__             =							'sshleifer/tiny-gpt2'
									UpperCAmelCase__             =							AutoConfig.from_pretrained(_A			)
									UpperCAmelCase__             =							TensorFlowBenchmarkArguments(
									    models=[MODEL_ID]    ,training=_A    ,inference=_A    ,sequence_lengths=[8]    ,batch_sizes=[1]    ,multi_process=_A    ,)
									UpperCAmelCase__             =							TensorFlowBenchmark(_A    ,[config]			)
									UpperCAmelCase__             =							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			):
									UpperCAmelCase__             =							'sshleifer/tiny-gpt2'
									UpperCAmelCase__             =							TensorFlowBenchmarkArguments(
									    models=[MODEL_ID]    ,training=_A    ,inference=_A    ,sequence_lengths=[8]    ,batch_sizes=[1]    ,multi_process=_A    ,)
									UpperCAmelCase__             =							TensorFlowBenchmark(_A			)
									UpperCAmelCase__             =							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			):
									UpperCAmelCase__             =							'sshleifer/tiny-gpt2'
									UpperCAmelCase__             =							AutoConfig.from_pretrained(_A			)
									UpperCAmelCase__             =							TensorFlowBenchmarkArguments(
									    models=[MODEL_ID]    ,training=_A    ,inference=_A    ,sequence_lengths=[8]    ,batch_sizes=[1]    ,multi_process=_A    ,)
									UpperCAmelCase__             =							TensorFlowBenchmark(_A    ,[config]			)
									UpperCAmelCase__             =							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			):
									UpperCAmelCase__             =							'patrickvonplaten/t5-tiny-random'
									UpperCAmelCase__             =							AutoConfig.from_pretrained(_A			)
									UpperCAmelCase__             =							TensorFlowBenchmarkArguments(
									    models=[MODEL_ID]    ,training=_A    ,inference=_A    ,sequence_lengths=[8]    ,batch_sizes=[1]    ,multi_process=_A    ,)
									UpperCAmelCase__             =							TensorFlowBenchmark(_A    ,configs=[config]			)
									UpperCAmelCase__             =							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 		__lowerCAmelCase						(				self   :	Tuple			):
									UpperCAmelCase__             =							'sshleifer/tiny-gpt2'
									UpperCAmelCase__             =							TensorFlowBenchmarkArguments(
									    models=[MODEL_ID]    ,training=_A    ,inference=_A    ,sequence_lengths=[8]    ,batch_sizes=[1]    ,use_xla=_A    ,multi_process=_A    ,)
									UpperCAmelCase__             =							TensorFlowBenchmark(_A			)
									UpperCAmelCase__             =							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[int]			):
									UpperCAmelCase__             =							'sshleifer/tiny-gpt2'
									with tempfile.TemporaryDirectory() as tmp_dir:
													UpperCAmelCase__             =							TensorFlowBenchmarkArguments(
													    models=[MODEL_ID]    ,inference=_A    ,save_to_csv=_A    ,sequence_lengths=[8]    ,batch_sizes=[1]    ,inference_time_csv_file=os.path.join(_A    ,'inf_time.csv'			)    ,inference_memory_csv_file=os.path.join(_A    ,'inf_mem.csv'			)    ,env_info_csv_file=os.path.join(_A    ,'env.csv'			)    ,multi_process=_A    ,)
													UpperCAmelCase__             =							TensorFlowBenchmark(_A			)
													benchmark.run()
													self.assertTrue(Path(os.path.join(_A    ,'inf_time.csv'			)			).exists()			)
													self.assertTrue(Path(os.path.join(_A    ,'inf_mem.csv'			)			).exists()			)
													self.assertTrue(Path(os.path.join(_A    ,'env.csv'			)			).exists()			)







					def 		__lowerCAmelCase						(				self   :	Optional[Any]			):
									UpperCAmelCase__             =							'sshleifer/tiny-gpt2'

									def _check_summary_is_not_empty(lowerCamelCase__   :	List[str]			):
													self.assertTrue(hasattr(_A    ,'sequential'			)			)
													self.assertTrue(hasattr(_A    ,'cumulative'			)			)
													self.assertTrue(hasattr(_A    ,'current'			)			)
													self.assertTrue(hasattr(_A    ,'total'			)			)

									with tempfile.TemporaryDirectory() as tmp_dir:
													UpperCAmelCase__             =							TensorFlowBenchmarkArguments(
													    models=[MODEL_ID]    ,inference=_A    ,sequence_lengths=[8]    ,batch_sizes=[1]    ,log_filename=os.path.join(_A    ,'log.txt'			)    ,log_print=_A    ,trace_memory_line_by_line=_A    ,eager_mode=_A    ,multi_process=_A    ,)
													UpperCAmelCase__             =							TensorFlowBenchmark(_A			)
													UpperCAmelCase__             =							benchmark.run()
													_check_summary_is_not_empty(result.inference_summary			)
													self.assertTrue(Path(os.path.join(_A    ,'log.txt'			)			).exists()			)










from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


UpperCAmelCase						:   Any			  =     {
    '''configuration_falcon''': ['''FALCON_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''FalconConfig'''],
}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCAmelCase						:   Any			  =     [
				    '''FALCON_PRETRAINED_MODEL_ARCHIVE_LIST''',
				    '''FalconForCausalLM''',
				    '''FalconModel''',
				    '''FalconPreTrainedModel''',
				    '''FalconForSequenceClassification''',
				    '''FalconForTokenClassification''',
				    '''FalconForQuestionAnswering''',
				]


if TYPE_CHECKING:
				from .configuration_falcon import FALCON_PRETRAINED_CONFIG_ARCHIVE_MAP, FalconConfig

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_falcon import (
								    FALCON_PRETRAINED_MODEL_ARCHIVE_LIST,
								    FalconForCausalLM,
								    FalconForQuestionAnswering,
								    FalconForSequenceClassification,
								    FalconForTokenClassification,
								    FalconModel,
								    FalconPreTrainedModel,
								)


else:
				import sys

				UpperCAmelCase						:   List[str]			  =     _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




