



'''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      ):







	def 	_a (     self			,					_lowerCAmelCase    )     ->     Dict:
							'''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    )     ->     str:
							'''simple docstring'''






							lowercase   =				"""sshleifer/tiny-gpt2"""
							lowercase   =				TensorFlowBenchmarkArguments(
							    models=[MODEL_ID]			,					training=lowerCamelCase_			,					inference=lowerCamelCase_			,					sequence_lengths=[8]			,					batch_sizes=[1]			,					eager_mode=lowerCamelCase_			,					multi_process=lowerCamelCase_			,					)
							lowercase   =				TensorFlowBenchmark(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    )     ->     int:
							'''simple docstring'''






							lowercase   =				"""sgugger/tiny-distilbert-classification"""
							lowercase   =				TensorFlowBenchmarkArguments(
							    models=[MODEL_ID]			,					training=lowerCamelCase_			,					inference=lowerCamelCase_			,					sequence_lengths=[8]			,					batch_sizes=[1]			,					multi_process=lowerCamelCase_			,					only_pretrain_model=lowerCamelCase_			,					)
							lowercase   =				TensorFlowBenchmark(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    )     ->     int:
							'''simple docstring'''






							lowercase   =				"""sshleifer/tiny-gpt2"""
							lowercase   =				TensorFlowBenchmarkArguments(
							    models=[MODEL_ID]			,					training=lowerCamelCase_			,					inference=lowerCamelCase_			,					sequence_lengths=[8]			,					batch_sizes=[1]			,					multi_process=lowerCamelCase_			,					)
							lowercase   =				TensorFlowBenchmark(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    )     ->     List[Any]:
							'''simple docstring'''






							lowercase   =				"""sshleifer/tiny-gpt2"""
							lowercase   =				AutoConfig.from_pretrained(lowerCamelCase_    )
							lowercase   =				TensorFlowBenchmarkArguments(
							    models=[MODEL_ID]			,					training=lowerCamelCase_			,					inference=lowerCamelCase_			,					sequence_lengths=[8]			,					batch_sizes=[1]			,					eager_mode=lowerCamelCase_			,					multi_process=lowerCamelCase_			,					)
							lowercase   =				TensorFlowBenchmark(lowerCamelCase_			,					[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    )     ->     Tuple:
							'''simple docstring'''






							lowercase   =				"""sshleifer/tiny-gpt2"""
							lowercase   =				AutoConfig.from_pretrained(lowerCamelCase_    )
							lowercase   =				TensorFlowBenchmarkArguments(
							    models=[MODEL_ID]			,					training=lowerCamelCase_			,					inference=lowerCamelCase_			,					sequence_lengths=[8]			,					batch_sizes=[1]			,					multi_process=lowerCamelCase_			,					)
							lowercase   =				TensorFlowBenchmark(lowerCamelCase_			,					[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    )     ->     Tuple:
							'''simple docstring'''






							lowercase   =				"""sshleifer/tiny-gpt2"""
							lowercase   =				TensorFlowBenchmarkArguments(
							    models=[MODEL_ID]			,					training=lowerCamelCase_			,					inference=lowerCamelCase_			,					sequence_lengths=[8]			,					batch_sizes=[1]			,					multi_process=lowerCamelCase_			,					)
							lowercase   =				TensorFlowBenchmark(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    )     ->     Any:
							'''simple docstring'''






							lowercase   =				"""sshleifer/tiny-gpt2"""
							lowercase   =				AutoConfig.from_pretrained(lowerCamelCase_    )
							lowercase   =				TensorFlowBenchmarkArguments(
							    models=[MODEL_ID]			,					training=lowerCamelCase_			,					inference=lowerCamelCase_			,					sequence_lengths=[8]			,					batch_sizes=[1]			,					multi_process=lowerCamelCase_			,					)
							lowercase   =				TensorFlowBenchmark(lowerCamelCase_			,					[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    )     ->     List[Any]:
							'''simple docstring'''






							lowercase   =				"""patrickvonplaten/t5-tiny-random"""
							lowercase   =				AutoConfig.from_pretrained(lowerCamelCase_    )
							lowercase   =				TensorFlowBenchmarkArguments(
							    models=[MODEL_ID]			,					training=lowerCamelCase_			,					inference=lowerCamelCase_			,					sequence_lengths=[8]			,					batch_sizes=[1]			,					multi_process=lowerCamelCase_			,					)
							lowercase   =				TensorFlowBenchmark(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    )







	@unittest.skipIf(is_tf_available() and len(tf.config.list_physical_devices("""GPU"""    )    ) == 0			,					"""Cannot do xla on CPU."""    )
	def 	_a (     self    )     ->     str:
							'''simple docstring'''






							lowercase   =				"""sshleifer/tiny-gpt2"""
							lowercase   =				TensorFlowBenchmarkArguments(
							    models=[MODEL_ID]			,					training=lowerCamelCase_			,					inference=lowerCamelCase_			,					sequence_lengths=[8]			,					batch_sizes=[1]			,					use_xla=lowerCamelCase_			,					multi_process=lowerCamelCase_			,					)
							lowercase   =				TensorFlowBenchmark(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    )     ->     int:
							'''simple docstring'''






							lowercase   =				"""sshleifer/tiny-gpt2"""
							with tempfile.TemporaryDirectory() as tmp_dir:
													lowercase   =				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_			,					)
													lowercase   =				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 	_a (     self    )     ->     str:
							'''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   =				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_			,					)
													lowercase   =				TensorFlowBenchmark(lowerCamelCase_    )
													lowercase   =				benchmark.run()
													_check_summary_is_not_empty(result.inference_summary    )
													self.assertTrue(Path(os.path.join(lowerCamelCase_			,					"""log.txt"""    )    ).exists()    )



from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


_SCREAMING_SNAKE_CASE 		=      logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE 		=      {
    """sail/poolformer_s12""": """https://huggingface.co/sail/poolformer_s12/resolve/main/config.json""",
    # See all PoolFormer models at https://huggingface.co/models?filter=poolformer
}
class SCREAMING_SNAKE_CASE_		(      __lowerCAmelCase		):
   __lowerCAmelCase           =				"""poolformer"""







   def __init__(     self						:						str   ,   lowerCamelCase_						:						Any=3   ,   lowerCamelCase_						:						Any=16   ,   lowerCamelCase_						:						Any=16   ,   lowerCamelCase_						:						Optional[Any]=3   ,   lowerCamelCase_						:						List[str]=4.0   ,   lowerCamelCase_						:						Tuple=[2, 2, 6, 2]   ,   lowerCamelCase_						:						Optional[Any]=[64, 128, 320, 512]   ,   lowerCamelCase_						:						Tuple=[7, 3, 3, 3]   ,   lowerCamelCase_						:						Optional[Any]=[4, 2, 2, 2]   ,   lowerCamelCase_						:						Dict=[2, 1, 1, 1]   ,   lowerCamelCase_						:						Tuple=4   ,   lowerCamelCase_						:						Optional[int]=0.0   ,   lowerCamelCase_						:						Union[str, Any]="gelu"   ,   lowerCamelCase_						:						Union[str, Any]=True   ,   lowerCamelCase_						:						Union[str, Any]=1E-5   ,   lowerCamelCase_						:						int=0.0_2   ,   **lowerCamelCase_						:						str   ,   ):





    """simple docstring"""


    UpperCamelCase			  =      num_channels
    UpperCamelCase			  =      patch_size
    UpperCamelCase			  =      stride
    UpperCamelCase			  =      padding
    UpperCamelCase			  =      pool_size
    UpperCamelCase			  =      hidden_sizes
    UpperCamelCase			  =      mlp_ratio
    UpperCamelCase			  =      depths
    UpperCamelCase			  =      patch_sizes
    UpperCamelCase			  =      strides
    UpperCamelCase			  =      num_encoder_blocks
    UpperCamelCase			  =      drop_path_rate
    UpperCamelCase			  =      hidden_act
    UpperCamelCase			  =      use_layer_scale
    UpperCamelCase			  =      layer_scale_init_value
    UpperCamelCase			  =      initializer_range
    super().__init__(**lowerCamelCase_				)





class SCREAMING_SNAKE_CASE_		(      __lowerCAmelCase		):
   __lowerCAmelCase           =				version.parse("""1.11"""		)







   @property
   def 						lowerCamelCase_	(     self						:						Any				):





    """simple docstring"""


    return OrderedDict(
        [
            ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
        ]				)







   @property
   def 						lowerCamelCase_	(     self						:						Any				):





    """simple docstring"""


    return 2E-3
