


import collections.abc
from typing import Optional, Tuple, Union

import torch
import torch.utils.checkpoint
from torch import nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...modeling_outputs import BaseModelOutputWithNoAttention, ImageClassifierOutputWithNoAttention
from ...modeling_utils import PreTrainedModel
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_poolformer import PoolFormerConfig


lowerCAmelCase__    :Optional[int]       =				logging.get_logger(__name__)

# General docstring
lowerCAmelCase__    :List[Any]       =				'''PoolFormerConfig'''

# Base docstring
lowerCAmelCase__    :Tuple       =				'''sail/poolformer_s12'''
lowerCAmelCase__    :List[Any]       =				[1, 5_1_2, 7, 7]

# Image classification docstring
lowerCAmelCase__    :Optional[Any]       =				'''sail/poolformer_s12'''
lowerCAmelCase__    :Any       =				'''tabby, tabby cat'''

lowerCAmelCase__    :Dict       =				[
    '''sail/poolformer_s12''',
    # See all PoolFormer models at https://huggingface.co/models?filter=poolformer
]

def 			lowerCAmelCase__					(     a__:						List[Any]     ,    a__:						float = 0.0     ,    a__:						bool = False			)    ->						Optional[Any]:


							'''simple docstring'''





							if drop_prob == 0.0 or not training:
														return input
							_UpperCAmelCase											=     1 - drop_prob
							_UpperCAmelCase											=     (input.shape[0],) + (1,) * (input.ndim - 1)  # work with diff dim tensors, not just 2D ConvNets
							_UpperCAmelCase											=     keep_prob + torch.rand(a__     ,    dtype=input.dtype     ,    device=input.device			)
							random_tensor.floor_()  # binarize
							_UpperCAmelCase											=     input.div(a__			) * random_tensor
							return output

class 						__a (							nn.Module     ):
		def __init__(     self     ,       _SCREAMING_SNAKE_CASE = None		)					->			None:




									"""simple docstring"""





									super().__init__()
									_UpperCAmelCase											=     drop_prob
		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE		)					->			torch.Tensor:




									"""simple docstring"""





									return drop_path(_SCREAMING_SNAKE_CASE     ,       self.drop_prob     ,       self.training		)






		def       UpperCAmelCase__							(     self		)					->			str:




									"""simple docstring"""





									return "p={}".format(self.drop_prob		)



class 						__a (							nn.Module     ):
		def __init__(     self     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE=None		)					->			List[str]:




									"""simple docstring"""





									super().__init__()
									_UpperCAmelCase											=     patch_size if isinstance(_SCREAMING_SNAKE_CASE     ,       collections.abc.Iterable		) else (patch_size, patch_size)
									_UpperCAmelCase											=     stride if isinstance(_SCREAMING_SNAKE_CASE     ,       collections.abc.Iterable		) else (stride, stride)
									_UpperCAmelCase											=     padding if isinstance(_SCREAMING_SNAKE_CASE     ,       collections.abc.Iterable		) else (padding, padding)

									_UpperCAmelCase											=     nn.Convad(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       kernel_size=_SCREAMING_SNAKE_CASE     ,       stride=_SCREAMING_SNAKE_CASE     ,       padding=_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     norm_layer(_SCREAMING_SNAKE_CASE		) if norm_layer else nn.Identity()






		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE		)					->			Optional[int]:




									"""simple docstring"""





									_UpperCAmelCase											=     self.projection(_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     self.norm(_SCREAMING_SNAKE_CASE		)
									return embeddings



class 						__a (							nn.GroupNorm     ):
		def __init__(     self     ,       _SCREAMING_SNAKE_CASE     ,       **_SCREAMING_SNAKE_CASE		)					->			Dict:




									"""simple docstring"""





									super().__init__(1     ,       _SCREAMING_SNAKE_CASE     ,       **_SCREAMING_SNAKE_CASE		)



class 						__a (							nn.Module     ):
		def __init__(     self     ,       _SCREAMING_SNAKE_CASE		)					->			Any:




									"""simple docstring"""





									super().__init__()
									_UpperCAmelCase											=     nn.AvgPoolad(_SCREAMING_SNAKE_CASE     ,       stride=1     ,       padding=pool_size // 2     ,       count_include_pad=_SCREAMING_SNAKE_CASE		)






		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE		)					->			int:




									"""simple docstring"""





									return self.pool(_SCREAMING_SNAKE_CASE		) - hidden_states



class 						__a (							nn.Module     ):
		def __init__(     self     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE		)					->			Union[str, Any]:




									"""simple docstring"""





									super().__init__()
									_UpperCAmelCase											=     nn.Convad(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       1		)
									_UpperCAmelCase											=     nn.Convad(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       1		)
									_UpperCAmelCase											=     PoolFormerDropPath(_SCREAMING_SNAKE_CASE		)
									if isinstance(config.hidden_act     ,       _SCREAMING_SNAKE_CASE		):
																_UpperCAmelCase											=     ACTaFN[config.hidden_act]
									else:
																_UpperCAmelCase											=     config.hidden_act






		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE		)					->			int:




									"""simple docstring"""





									_UpperCAmelCase											=     self.conva(_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     self.act_fn(_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     self.drop(_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     self.conva(_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     self.drop(_SCREAMING_SNAKE_CASE		)

									return hidden_states



class 						__a (							nn.Module     ):
		def __init__(     self     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE		)					->			Dict:




									"""simple docstring"""





									super().__init__()
									_UpperCAmelCase											=     PoolFormerPooling(_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     PoolFormerOutput(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     PoolFormerGroupNorm(_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     PoolFormerGroupNorm(_SCREAMING_SNAKE_CASE		)

									# Useful for training neural nets
									_UpperCAmelCase											=     PoolFormerDropPath(_SCREAMING_SNAKE_CASE		) if drop_path > 0.0 else nn.Identity()
									_UpperCAmelCase											=     config.use_layer_scale
									if config.use_layer_scale:
																_UpperCAmelCase											=     nn.Parameter(
																    config.layer_scale_init_value * torch.ones((_SCREAMING_SNAKE_CASE)		)     ,       requires_grad=_SCREAMING_SNAKE_CASE		)
																_UpperCAmelCase											=     nn.Parameter(
																    config.layer_scale_init_value * torch.ones((_SCREAMING_SNAKE_CASE)		)     ,       requires_grad=_SCREAMING_SNAKE_CASE		)






		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE		)					->			List[Any]:




									"""simple docstring"""





									if self.use_layer_scale:
																_UpperCAmelCase											=     self.pooling(self.before_norm(_SCREAMING_SNAKE_CASE		)		)
																_UpperCAmelCase											=     self.layer_scale_a.unsqueeze(-1		).unsqueeze(-1		) * pooling_output
																# First residual connection
																_UpperCAmelCase											=     hidden_states + self.drop_path(_SCREAMING_SNAKE_CASE		)
																_UpperCAmelCase											=     ()

																_UpperCAmelCase											=     self.output(self.after_norm(_SCREAMING_SNAKE_CASE		)		)
																_UpperCAmelCase											=     self.layer_scale_a.unsqueeze(-1		).unsqueeze(-1		) * layer_output
																# Second residual connection
																_UpperCAmelCase											=     hidden_states + self.drop_path(_SCREAMING_SNAKE_CASE		)

																_UpperCAmelCase											=     (output,) + outputs
																return outputs

									else:
																_UpperCAmelCase											=     self.drop_path(self.pooling(self.before_norm(_SCREAMING_SNAKE_CASE		)		)		)
																# First residual connection
																_UpperCAmelCase											=     pooling_output + hidden_states
																_UpperCAmelCase											=     ()

																# Second residual connection inside the PoolFormerOutput block
																_UpperCAmelCase											=     self.drop_path(self.output(self.after_norm(_SCREAMING_SNAKE_CASE		)		)		)
																_UpperCAmelCase											=     hidden_states + layer_output

																_UpperCAmelCase											=     (output,) + outputs
																return outputs



class 						__a (							nn.Module     ):
		def __init__(     self     ,       _SCREAMING_SNAKE_CASE		)					->			Optional[Any]:




									"""simple docstring"""





									super().__init__()
									_UpperCAmelCase											=     config
									# stochastic depth decay rule
									_UpperCAmelCase											=     [x.item() for x in torch.linspace(0     ,       config.drop_path_rate     ,       sum(config.depths		)		)]

									# patch embeddings
									_UpperCAmelCase											=     []
									for i in range(config.num_encoder_blocks		):
																embeddings.append(
																    PoolFormerEmbeddings(
																        patch_size=config.patch_sizes[i]     ,       stride=config.strides[i]     ,       padding=config.padding[i]     ,       num_channels=config.num_channels if i == 0 else config.hidden_sizes[i - 1]     ,       hidden_size=config.hidden_sizes[i]     ,       )		)
									_UpperCAmelCase											=     nn.ModuleList(_SCREAMING_SNAKE_CASE		)

									# Transformer blocks
									_UpperCAmelCase											=     []
									_UpperCAmelCase											=     0
									for i in range(config.num_encoder_blocks		):
																# each block consists of layers
																_UpperCAmelCase											=     []
																if i != 0:
																							cur += config.depths[i - 1]
																for j in range(config.depths[i]		):
																							layers.append(
																							    PoolFormerLayer(
																							        _SCREAMING_SNAKE_CASE     ,       num_channels=config.hidden_sizes[i]     ,       pool_size=config.pool_size     ,       hidden_size=config.hidden_sizes[i]     ,       intermediate_size=int(config.hidden_sizes[i] * config.mlp_ratio		)     ,       drop_path=dpr[cur + j]     ,       )		)
																blocks.append(nn.ModuleList(_SCREAMING_SNAKE_CASE		)		)

									_UpperCAmelCase											=     nn.ModuleList(_SCREAMING_SNAKE_CASE		)






		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE=False     ,       _SCREAMING_SNAKE_CASE=True		)					->			Union[str, Any]:




									"""simple docstring"""





									_UpperCAmelCase											=     () if output_hidden_states else None

									_UpperCAmelCase											=     pixel_values
									for idx, layers in enumerate(zip(self.patch_embeddings     ,       self.block		)		):
																_UpperCAmelCase						,			_UpperCAmelCase											=     layers
																# Get patch embeddings from hidden_states
																_UpperCAmelCase											=     embedding_layer(_SCREAMING_SNAKE_CASE		)
																# Send the embeddings through the blocks
																for _, blk in enumerate(_SCREAMING_SNAKE_CASE		):
																							_UpperCAmelCase											=     blk(_SCREAMING_SNAKE_CASE		)
																							_UpperCAmelCase											=     layer_outputs[0]

																if output_hidden_states:
																							_UpperCAmelCase											=     all_hidden_states + (hidden_states,)

									if not return_dict:
																return tuple(v for v in [hidden_states, all_hidden_states] if v is not None		)

									return BaseModelOutputWithNoAttention(last_hidden_state=_SCREAMING_SNAKE_CASE     ,       hidden_states=_SCREAMING_SNAKE_CASE		)



class 						__a (							UpperCAmelCase     ):
		_a      :    Optional[int]           =      PoolFormerConfig
		_a      :    List[Any]           =      'poolformer'
		_a      :    Optional[int]           =      'pixel_values'
		_a      :    Tuple           =      True
		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE		)					->			str:




									"""simple docstring"""





									if isinstance(_SCREAMING_SNAKE_CASE     ,       (nn.Linear, nn.Convad)		):
																module.weight.data.normal_(mean=0.0     ,       std=self.config.initializer_range		)
																if module.bias is not None:
																							module.bias.data.zero_()
									elif isinstance(_SCREAMING_SNAKE_CASE     ,       nn.LayerNorm		):
																module.bias.data.zero_()
																module.weight.data.fill_(1.0		)






		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE=False		)					->			int:




									"""simple docstring"""





									if isinstance(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE		):
																_UpperCAmelCase											=     value



lowerCAmelCase__    :Optional[int]       =				R'''
    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use
    it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
    behavior.

    Parameters:
        config ([`PoolFormerConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
'''

lowerCAmelCase__    :Optional[Any]       =				R'''
    Args:
        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See
            [`PoolFormerImageProcessor.__call__`] for details.
'''

@add_start_docstrings(
    'The bare PoolFormer Model transformer outputting raw hidden-states without any specific head on top.'       , UpperCAmelCase       , )
class 						__a (							UpperCAmelCase     ):
		def __init__(     self     ,       _SCREAMING_SNAKE_CASE		)					->			Tuple:




									"""simple docstring"""





									super().__init__(_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     config

									_UpperCAmelCase											=     PoolFormerEncoder(_SCREAMING_SNAKE_CASE		)

									# Initialize weights and apply final processing
									self.post_init()
		def       UpperCAmelCase__							(     self		)					->			str:




									"""simple docstring"""





									return self.embeddings.patch_embeddings






		@add_start_docstrings_to_model_forward(_SCREAMING_SNAKE_CASE		)
		@add_code_sample_docstrings(
		    checkpoint=_CHECKPOINT_FOR_DOC     ,       output_type=_SCREAMING_SNAKE_CASE     ,       config_class=_CONFIG_FOR_DOC     ,       modality='vision'     ,       expected_output=_EXPECTED_OUTPUT_SHAPE     ,       )
		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE = None     ,       _SCREAMING_SNAKE_CASE = None     ,       _SCREAMING_SNAKE_CASE = None     ,       )					->			Union[Tuple, BaseModelOutputWithNoAttention]:




									"""simple docstring"""





									_UpperCAmelCase											=     (
									    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
									)
									_UpperCAmelCase											=     return_dict if return_dict is not None else self.config.use_return_dict

									if pixel_values is None:
																raise ValueError('You have to specify pixel_values'		)

									_UpperCAmelCase											=     self.encoder(
									    _SCREAMING_SNAKE_CASE     ,       output_hidden_states=_SCREAMING_SNAKE_CASE     ,       return_dict=_SCREAMING_SNAKE_CASE     ,       )
									_UpperCAmelCase											=     encoder_outputs[0]

									if not return_dict:
																return (sequence_output, None) + encoder_outputs[1:]

									return BaseModelOutputWithNoAttention(
									    last_hidden_state=_SCREAMING_SNAKE_CASE     ,       hidden_states=encoder_outputs.hidden_states     ,       )



class 						__a (							nn.Module     ):
		def __init__(     self     ,       _SCREAMING_SNAKE_CASE		)					->			Tuple:




									"""simple docstring"""





									super().__init__()
									_UpperCAmelCase											=     nn.Linear(config.hidden_size     ,       config.hidden_size		)






		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE		)					->			str:




									"""simple docstring"""





									_UpperCAmelCase											=     self.dense(_SCREAMING_SNAKE_CASE		)
									return output



@add_start_docstrings(
    '\n    PoolFormer Model transformer with an image classification head on top\n    '       , UpperCAmelCase       , )
class 						__a (							UpperCAmelCase     ):
		def __init__(     self     ,       _SCREAMING_SNAKE_CASE		)					->			str:




									"""simple docstring"""





									super().__init__(_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     config.num_labels
									_UpperCAmelCase											=     PoolFormerModel(_SCREAMING_SNAKE_CASE		)

									# Final norm
									_UpperCAmelCase											=     PoolFormerGroupNorm(config.hidden_sizes[-1]		)
									# Classifier head
									_UpperCAmelCase											=     (
									    nn.Linear(config.hidden_sizes[-1]     ,       config.num_labels		) if config.num_labels > 0 else nn.Identity()
									)

									# Initialize weights and apply final processing
									self.post_init()






		@add_start_docstrings_to_model_forward(_SCREAMING_SNAKE_CASE		)
		@add_code_sample_docstrings(
		    checkpoint=_IMAGE_CLASS_CHECKPOINT     ,       output_type=_SCREAMING_SNAKE_CASE     ,       config_class=_CONFIG_FOR_DOC     ,       expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT     ,       )
		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE = None     ,       _SCREAMING_SNAKE_CASE = None     ,       _SCREAMING_SNAKE_CASE = None     ,       _SCREAMING_SNAKE_CASE = None     ,       )					->			Union[Tuple, ImageClassifierOutputWithNoAttention]:




									"""simple docstring"""





									_UpperCAmelCase											=     return_dict if return_dict is not None else self.config.use_return_dict

									_UpperCAmelCase											=     self.poolformer(
									    _SCREAMING_SNAKE_CASE     ,       output_hidden_states=_SCREAMING_SNAKE_CASE     ,       return_dict=_SCREAMING_SNAKE_CASE     ,       )

									_UpperCAmelCase											=     outputs[0]

									_UpperCAmelCase											=     self.classifier(self.norm(_SCREAMING_SNAKE_CASE		).mean([-2, -1]		)		)

									_UpperCAmelCase											=     None
									if labels is not None:
																if self.config.problem_type is None:
																							if self.num_labels == 1:
																														_UpperCAmelCase											=     'regression'
																							elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
																														_UpperCAmelCase											=     'single_label_classification'
																							else:
																														_UpperCAmelCase											=     'multi_label_classification'

																if self.config.problem_type == "regression":
																							_UpperCAmelCase											=     MSELoss()
																							if self.num_labels == 1:
																														_UpperCAmelCase											=     loss_fct(logits.squeeze()     ,       labels.squeeze()		)
																							else:
																														_UpperCAmelCase											=     loss_fct(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE		)
																elif self.config.problem_type == "single_label_classification":
																							_UpperCAmelCase											=     CrossEntropyLoss()
																							_UpperCAmelCase											=     loss_fct(logits.view(-1     ,       self.num_labels		)     ,       labels.view(-1		)		)
																elif self.config.problem_type == "multi_label_classification":
																							_UpperCAmelCase											=     BCEWithLogitsLoss()
																							_UpperCAmelCase											=     loss_fct(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE		)

									if not return_dict:
																_UpperCAmelCase											=     (logits,) + outputs[2:]
																return ((loss,) + output) if loss is not None else output

									return ImageClassifierOutputWithNoAttention(loss=_SCREAMING_SNAKE_CASE     ,       logits=_SCREAMING_SNAKE_CASE     ,       hidden_states=outputs.hidden_states		)




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 						__a (							unittest.TestCase     ):
		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE		)					->			List[str]:




									"""simple docstring"""





									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(_SCREAMING_SNAKE_CASE		)
		def       UpperCAmelCase__							(     self		)					->			Optional[int]:




									"""simple docstring"""





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




									"""simple docstring"""





									_UpperCAmelCase											=     'sgugger/tiny-distilbert-classification'
									_UpperCAmelCase											=     TensorFlowBenchmarkArguments(
									    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											=     TensorFlowBenchmark(_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     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		)					->			List[Any]:




									"""simple docstring"""





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




									"""simple docstring"""





									_UpperCAmelCase											=     'sshleifer/tiny-gpt2'
									_UpperCAmelCase											=     AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     TensorFlowBenchmarkArguments(
									    models=[MODEL_ID]     ,       training=_SCREAMING_SNAKE_CASE     ,       inference=_SCREAMING_SNAKE_CASE     ,       sequence_lengths=[8]     ,       batch_sizes=[1]     ,       eager_mode=_SCREAMING_SNAKE_CASE     ,       multi_process=_SCREAMING_SNAKE_CASE     ,       )
									_UpperCAmelCase											=     TensorFlowBenchmark(_SCREAMING_SNAKE_CASE     ,       [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       UpperCAmelCase__							(     self		)					->			List[Any]:




									"""simple docstring"""





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




									"""simple docstring"""





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




									"""simple docstring"""





									_UpperCAmelCase											=     'sshleifer/tiny-gpt2'
									_UpperCAmelCase											=     AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     TensorFlowBenchmarkArguments(
									    models=[MODEL_ID]     ,       training=_SCREAMING_SNAKE_CASE     ,       inference=_SCREAMING_SNAKE_CASE     ,       sequence_lengths=[8]     ,       batch_sizes=[1]     ,       multi_process=_SCREAMING_SNAKE_CASE     ,       )
									_UpperCAmelCase											=     TensorFlowBenchmark(_SCREAMING_SNAKE_CASE     ,       [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       UpperCAmelCase__							(     self		)					->			Any:




									"""simple docstring"""





									_UpperCAmelCase											=     'patrickvonplaten/t5-tiny-random'
									_UpperCAmelCase											=     AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     TensorFlowBenchmarkArguments(
									    models=[MODEL_ID]     ,       training=_SCREAMING_SNAKE_CASE     ,       inference=_SCREAMING_SNAKE_CASE     ,       sequence_lengths=[8]     ,       batch_sizes=[1]     ,       multi_process=_SCREAMING_SNAKE_CASE     ,       )
									_UpperCAmelCase											=     TensorFlowBenchmark(_SCREAMING_SNAKE_CASE     ,       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       UpperCAmelCase__							(     self		)					->			int:




									"""simple docstring"""





									_UpperCAmelCase											=     'sshleifer/tiny-gpt2'
									_UpperCAmelCase											=     TensorFlowBenchmarkArguments(
									    models=[MODEL_ID]     ,       training=_SCREAMING_SNAKE_CASE     ,       inference=_SCREAMING_SNAKE_CASE     ,       sequence_lengths=[8]     ,       batch_sizes=[1]     ,       use_xla=_SCREAMING_SNAKE_CASE     ,       multi_process=_SCREAMING_SNAKE_CASE     ,       )
									_UpperCAmelCase											=     TensorFlowBenchmark(_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     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		)					->			str:




									"""simple docstring"""





									_UpperCAmelCase											=     'sshleifer/tiny-gpt2'
									with tempfile.TemporaryDirectory() as tmp_dir:
																_UpperCAmelCase											=     TensorFlowBenchmarkArguments(
																    models=[MODEL_ID]     ,       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'		)     ,       inference_memory_csv_file=os.path.join(_SCREAMING_SNAKE_CASE     ,       'inf_mem.csv'		)     ,       env_info_csv_file=os.path.join(_SCREAMING_SNAKE_CASE     ,       'env.csv'		)     ,       multi_process=_SCREAMING_SNAKE_CASE     ,       )
																_UpperCAmelCase											=     TensorFlowBenchmark(_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     ,       'inf_mem.csv'		)		).exists()		)
																self.assertTrue(Path(os.path.join(_SCREAMING_SNAKE_CASE     ,       'env.csv'		)		).exists()		)






		def       UpperCAmelCase__							(     self		)					->			Tuple:




									"""simple docstring"""





									_UpperCAmelCase											=     '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											=     TensorFlowBenchmarkArguments(
																    models=[MODEL_ID]     ,       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     ,       eager_mode=_SCREAMING_SNAKE_CASE     ,       multi_process=_SCREAMING_SNAKE_CASE     ,       )
																_UpperCAmelCase											=     TensorFlowBenchmark(_SCREAMING_SNAKE_CASE		)
																_UpperCAmelCase											=     benchmark.run()
																_check_summary_is_not_empty(result.inference_summary		)
																self.assertTrue(Path(os.path.join(_SCREAMING_SNAKE_CASE     ,       'log.txt'		)		).exists()		)
