




import dataclasses
import json
import warnings
from dataclasses import dataclass, field
from time import time
from typing import List

from ..utils import logging


__lowerCamelCase   :						int				=			logging.get_logger(__name__)







def 		lowercase__   (		__A:	Any=None							,__A:	int=None				):





					'''simple docstring'''






					return field(default_factory=lambda: default							,metadata=__A				)


@dataclass
class    lowerCamelCase    :






			'''simple docstring'''





			UpperCamelCase__								=list_field(
			    default=[]				,metadata={
			        '''help''': (
			            '''Model checkpoints to be provided to the AutoModel classes. Leave blank to benchmark the base version'''
			            ''' of all available models'''
			        )
			    }				,)

			UpperCamelCase__								=list_field(
			    default=[8]				,metadata={'''help''': '''List of batch sizes for which memory and time performance will be evaluated'''}						)

			UpperCamelCase__								=list_field(
			    default=[8, 3_2, 1_2_8, 5_1_2]				,metadata={'''help''': '''List of sequence lengths for which memory and time performance will be evaluated'''}				,)

			UpperCamelCase__								=field(
			    default=_lowerCamelCase				,metadata={'''help''': '''Whether to benchmark inference of model. Inference can be disabled via --no-inference.'''}				,)
			UpperCamelCase__								=field(
			    default=_lowerCamelCase				,metadata={'''help''': '''Whether to run on available cuda devices. Cuda can be disabled via --no-cuda.'''}				,)
			UpperCamelCase__								=field(
			    default=_lowerCamelCase				,metadata={'''help''': '''Whether to run on available tpu devices. TPU can be disabled via --no-tpu.'''}						)
			UpperCamelCase__								=field(default=_lowerCamelCase				,metadata={'''help''': '''Use FP16 to accelerate inference.'''}						)
			UpperCamelCase__								=field(default=_lowerCamelCase				,metadata={'''help''': '''Benchmark training of model'''}						)
			UpperCamelCase__								=field(default=_lowerCamelCase				,metadata={'''help''': '''Verbose memory tracing'''}						)
			UpperCamelCase__								=field(
			    default=_lowerCamelCase				,metadata={'''help''': '''Whether to perform speed measurements. Speed measurements can be disabled via --no-speed.'''}				,)
			UpperCamelCase__								=field(
			    default=_lowerCamelCase				,metadata={
			        '''help''': '''Whether to perform memory measurements. Memory measurements can be disabled via --no-memory'''
			    }				,)
			UpperCamelCase__								=field(default=_lowerCamelCase				,metadata={'''help''': '''Trace memory line by line'''}						)
			UpperCamelCase__								=field(default=_lowerCamelCase				,metadata={'''help''': '''Save result to a CSV file'''}						)
			UpperCamelCase__								=field(default=_lowerCamelCase				,metadata={'''help''': '''Save all print statements in a log file'''}						)
			UpperCamelCase__								=field(default=_lowerCamelCase				,metadata={'''help''': '''Whether to print environment information'''}						)
			UpperCamelCase__								=field(
			    default=_lowerCamelCase				,metadata={
			        '''help''': (
			            '''Whether to use multiprocessing for memory and speed measurement. It is highly recommended to use'''
			            ''' multiprocessing for accurate CPU and GPU memory measurements. This option should only be disabled'''
			            ''' for debugging / testing and on TPU.'''
			        )
			    }				,)
			UpperCamelCase__								=field(
			    default=F'inference_time_{round(time()						)}.csv'				,metadata={'''help''': '''CSV filename used if saving time results to csv.'''}				,)
			UpperCamelCase__								=field(
			    default=F'inference_memory_{round(time()						)}.csv'				,metadata={'''help''': '''CSV filename used if saving memory results to csv.'''}				,)
			UpperCamelCase__								=field(
			    default=F'train_time_{round(time()						)}.csv'				,metadata={'''help''': '''CSV filename used if saving time results to csv for training.'''}				,)
			UpperCamelCase__								=field(
			    default=F'train_memory_{round(time()						)}.csv'				,metadata={'''help''': '''CSV filename used if saving memory results to csv for training.'''}				,)
			UpperCamelCase__								=field(
			    default=F'env_info_{round(time()						)}.csv'				,metadata={'''help''': '''CSV filename used if saving environment information.'''}				,)
			UpperCamelCase__								=field(
			    default=F'log_{round(time()						)}.csv'				,metadata={'''help''': '''Log filename used if print statements are saved in log.'''}				,)
			UpperCamelCase__								=field(default=3				,metadata={'''help''': '''Times an experiment will be run.'''}						)
			UpperCamelCase__								=field(
			    default=_lowerCamelCase				,metadata={
			        '''help''': (
			            '''Instead of loading the model as defined in `config.architectures` if exists, just load the pretrain'''
			            ''' model weights.'''
			        )
			    }				,)

			def 							UpperCAmelCase__       ( self			:   List[str]  )						->   Tuple:
								warnings.warn(
								    F'''The class {self.__class__} is deprecated. Hugging Face Benchmarking utils'''
								    ''' are deprecated in general and it is advised to use external Benchmarking libraries '''
								    ''' to benchmark Transformer models.'''       ,						lowerCamelCase_       ,						)

			def 							UpperCAmelCase__       ( self			:   int  )						->   List[Any]:
								return json.dumps(dataclasses.asdict(self  )       ,						indent=2  )

			@property
			def 							UpperCAmelCase__       ( self			:   Any  )						->   List[str]:
								if len(self.models  ) <= 0:
													raise ValueError(
													    '''Please make sure you provide at least one model name / model identifier, *e.g.* `--models'''
													    ''' bert-base-cased` or `args.models = [\'bert-base-cased\'].'''  )
								return self.models


			@property
			def 							UpperCAmelCase__       ( self			:   Tuple  )						->   List[Any]:
								if not self.multi_process:
													return False
								elif self.is_tpu:
													logger.info('''Multiprocessing is currently not possible on TPU.'''  )
													return False
								else:
													return True









from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


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

__lowerCamelCase   :						Tuple				=			{
    '''shi-labs/nat-mini-in1k-224''': '''https://huggingface.co/shi-labs/nat-mini-in1k-224/resolve/main/config.json''',
    # See all Nat models at https://huggingface.co/models?filter=nat
}


class    lowerCamelCase    (		_lowerCamelCase				,_lowerCamelCase						):






			'''simple docstring'''





			UpperCamelCase__								='''nat'''

			UpperCamelCase__								={
			    '''num_attention_heads''': '''num_heads''',
			    '''num_hidden_layers''': '''num_layers''',
			}

			def __init__( self			:   Union[str, Any]       ,						lowerCamelCase_			:   Dict=4       ,						lowerCamelCase_			:   Union[str, Any]=3       ,						lowerCamelCase_			:   List[str]=64       ,						lowerCamelCase_			:   Union[str, Any]=[3, 4, 6, 5]       ,						lowerCamelCase_			:   List[Any]=[2, 4, 8, 16]       ,						lowerCamelCase_			:   List[Any]=7       ,						lowerCamelCase_			:   Union[str, Any]=3.0       ,						lowerCamelCase_			:   int=True       ,						lowerCamelCase_			:   str=0.0       ,						lowerCamelCase_			:   int=0.0       ,						lowerCamelCase_			:   Dict=0.1       ,						lowerCamelCase_			:   Optional[int]="gelu"       ,						lowerCamelCase_			:   Tuple=0.0_2       ,						lowerCamelCase_			:   Tuple=1E-5       ,						lowerCamelCase_			:   List[Any]=0.0       ,						lowerCamelCase_			:   str=None       ,						lowerCamelCase_			:   Tuple=None       ,						**lowerCamelCase_			:   Any       ,						)						->   Any:
								super().__init__(**lowerCamelCase_  )

								__magic_name__							:	List[Any]    							=							patch_size
								__magic_name__							:	str    							=							num_channels
								__magic_name__							:	Union[str, Any]    							=							embed_dim
								__magic_name__							:	Dict    							=							depths
								__magic_name__							:	str    							=							len(lowerCamelCase_  )
								__magic_name__							:	List[str]    							=							num_heads
								__magic_name__							:	Optional[int]    							=							kernel_size
								__magic_name__							:	Any    							=							mlp_ratio
								__magic_name__							:	Any    							=							qkv_bias
								__magic_name__							:	Union[str, Any]    							=							hidden_dropout_prob
								__magic_name__							:	Any    							=							attention_probs_dropout_prob
								__magic_name__							:	List[str]    							=							drop_path_rate
								__magic_name__							:	str    							=							hidden_act
								__magic_name__							:	Tuple    							=							layer_norm_eps
								__magic_name__							:	Any    							=							initializer_range
								# we set the hidden_size attribute in order to make Nat work with VisionEncoderDecoderModel
								# this indicates the channel dimension after the last stage of the model
								__magic_name__							:	str    							=							int(embed_dim * 2 ** (len(lowerCamelCase_  ) - 1)  )
								__magic_name__							:	str    							=							layer_scale_init_value
								__magic_name__							:	Dict    							=							['''stem'''] + [F'''stage{idx}''' for idx in range(1       ,						len(lowerCamelCase_  ) + 1  )]
								__magic_name__							,    __magic_name__							:	int    							=							get_aligned_output_features_output_indices(
								    out_features=lowerCamelCase_       ,						out_indices=lowerCamelCase_       ,						stage_names=self.stage_names  )



