





"""simple docstring"""





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


_UpperCamelCase					      =   logging.get_logger(__name__)

_UpperCamelCase					      =   {
    '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 		SCREAMING_SNAKE_CASE_				(     snake_case__							,	snake_case__ ):
				"""simple docstring"""
				__snake_case :							Optional[int]									=		"""nat"""

				__snake_case :							str									=		{
				    """num_attention_heads""": """num_heads""",
				    """num_hidden_layers""": """num_layers""",
				}




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

											__lowerCamelCase   :   Dict       =patch_size
											__lowerCamelCase   :   Dict       =num_channels
											__lowerCamelCase   :   Any       =embed_dim
											__lowerCamelCase   :   List[Any]       =depths
											__lowerCamelCase   :   str       =len(__lowercase      )
											__lowerCamelCase   :   Union[str, Any]       =num_heads
											__lowerCamelCase   :   Optional[int]       =kernel_size
											__lowerCamelCase   :   Optional[Any]       =mlp_ratio
											__lowerCamelCase   :   List[str]       =qkv_bias
											__lowerCamelCase   :   List[str]       =hidden_dropout_prob
											__lowerCamelCase   :   Optional[int]       =attention_probs_dropout_prob
											__lowerCamelCase   :   Dict       =drop_path_rate
											__lowerCamelCase   :   str       =hidden_act
											__lowerCamelCase   :   Optional[Any]       =layer_norm_eps
											__lowerCamelCase   :   Optional[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
											__lowerCamelCase   :   Optional[Any]       =int(embed_dim * 2 ** (len(__lowercase      ) - 1)      )
											__lowerCamelCase   :   Union[str, Any]       =layer_scale_init_value
											__lowerCamelCase   :   Dict       =['''stem'''] + [f'stage{idx}' for idx in range(1    ,     len(__lowercase      ) + 1      )]
											__lowerCamelCase     ,    __lowerCamelCase   :   List[Any]       =get_aligned_output_features_output_indices(
											    out_features=__lowercase    ,     out_indices=__lowercase    ,     stage_names=self.stage_names      )











"""simple docstring"""





import inspect
import os
import unittest

import torch

import accelerate
from accelerate import debug_launcher
from accelerate.test_utils import (
    execute_subprocess_async,
    require_cpu,
    require_huggingface_suite,
    require_multi_gpu,
    require_single_gpu,
)
from accelerate.utils import patch_environment
@require_huggingface_suite
class 		SCREAMING_SNAKE_CASE_				(     unittest.TestCase ):
				"""simple docstring"""




				def        __lowercase	(  self	:Dict      ):
											__lowerCamelCase   :   Union[str, Any]       =inspect.getfile(accelerate.test_utils      )
											__lowerCamelCase   :   Union[str, Any]       =os.path.sep.join(
											    mod_file.split(os.path.sep      )[:-1] + ['''scripts''', '''external_deps''', '''test_metrics.py''']      )

											from accelerate.test_utils.scripts.external_deps import test_metrics  # noqa: F401

											__lowerCamelCase   :   List[str]       =test_metrics




				@require_cpu
				def        __lowercase	(  self	:Optional[Any]      ):
											debug_launcher(self.test_metrics.main    ,     num_processes=1      )




				@require_cpu
				def        __lowercase	(  self	:int      ):
											debug_launcher(self.test_metrics.main      )




				@require_single_gpu
				def        __lowercase	(  self	:int      ):
											self.test_metrics.main()




				@require_multi_gpu
				def        __lowercase	(  self	:Dict      ):
											print(f'Found {torch.cuda.device_count()} devices.'      )
											__lowerCamelCase   :   Union[str, Any]       =['''torchrun''', f'--nproc_per_node={torch.cuda.device_count()}', self.test_file_path]
											with patch_environment(omp_num_threads=1      ):
																		execute_subprocess_async(__lowercase    ,     env=os.environ.copy()      )




