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


lowercase__							:							int													=	logging.get_logger(__name__)

lowercase__							:							List[Any]													=	{
    "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__			(							lowerCamelCase_      ,						lowerCamelCase_			):

							"""simple docstring"""






							_snake_case   						=     'nat'

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



							def __init__(     self   ,		SCREAMING_SNAKE_CASE_=4   ,		SCREAMING_SNAKE_CASE_=3   ,		SCREAMING_SNAKE_CASE_=64   ,		SCREAMING_SNAKE_CASE_=[3, 4, 6, 5]   ,		SCREAMING_SNAKE_CASE_=[2, 4, 8, 16]   ,		SCREAMING_SNAKE_CASE_=7   ,		SCREAMING_SNAKE_CASE_=3.0   ,		SCREAMING_SNAKE_CASE_=True   ,		SCREAMING_SNAKE_CASE_=0.0   ,		SCREAMING_SNAKE_CASE_=0.0   ,		SCREAMING_SNAKE_CASE_=0.1   ,		SCREAMING_SNAKE_CASE_="gelu"   ,		SCREAMING_SNAKE_CASE_=0.0_2   ,		SCREAMING_SNAKE_CASE_=1E-5   ,		SCREAMING_SNAKE_CASE_=0.0   ,		SCREAMING_SNAKE_CASE_=None   ,		SCREAMING_SNAKE_CASE_=None   ,		**SCREAMING_SNAKE_CASE_   ,		)->      Optional[Any]:





													'''simple docstring'''






													super().__init__(**__SCREAMING_SNAKE_CASE	)

													__UpperCamelCase        =	patch_size
													__UpperCamelCase        =	num_channels
													__UpperCamelCase        =	embed_dim
													__UpperCamelCase        =	depths
													__UpperCamelCase        =	len(__SCREAMING_SNAKE_CASE	)
													__UpperCamelCase        =	num_heads
													__UpperCamelCase        =	kernel_size
													__UpperCamelCase        =	mlp_ratio
													__UpperCamelCase        =	qkv_bias
													__UpperCamelCase        =	hidden_dropout_prob
													__UpperCamelCase        =	attention_probs_dropout_prob
													__UpperCamelCase        =	drop_path_rate
													__UpperCamelCase        =	hidden_act
													__UpperCamelCase        =	layer_norm_eps
													__UpperCamelCase        =	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
													__UpperCamelCase        =	int(embed_dim * 2 ** (len(__SCREAMING_SNAKE_CASE	) - 1)	)
													__UpperCamelCase        =	layer_scale_init_value
													__UpperCamelCase        =	['''stem'''] + [F"stage{idx}" for idx in range(1   ,		len(__SCREAMING_SNAKE_CASE	) + 1	)]
													__UpperCamelCase        =	get_aligned_output_features_output_indices(
													    out_features=__SCREAMING_SNAKE_CASE   ,		out_indices=__SCREAMING_SNAKE_CASE   ,		stage_names=self.stage_names	)






'''simple docstring'''







import json
import os
import tempfile

from transformers.testing_utils import check_json_file_has_correct_format






class  lowerCAmelCase__   :
					lowerCAmelCase_        =     None






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     Tuple													=       self.feature_extraction_class(**self.feat_extract_dict		)
											lowercase_	:     Any													=       json.loads(feat_extract.to_json_string()		)
											for key, value in self.feat_extract_dict.items():
																	self.assertEqual(obj[key]				,							__SCREAMING_SNAKE_CASE		)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     str													=       self.feature_extraction_class(**self.feat_extract_dict		)

											with tempfile.TemporaryDirectory() as tmpdirname:
																	lowercase_	:     str													=       os.path.join(__SCREAMING_SNAKE_CASE				,							'''feat_extract.json'''		)
																	feat_extract_first.to_json_file(__SCREAMING_SNAKE_CASE		)
																	lowercase_	:     str													=       self.feature_extraction_class.from_json_file(__SCREAMING_SNAKE_CASE		)

											self.assertEqual(feat_extract_second.to_dict()				,							feat_extract_first.to_dict()		)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     Tuple													=       self.feature_extraction_class(**self.feat_extract_dict		)

											with tempfile.TemporaryDirectory() as tmpdirname:
																	lowercase_	:     Union[str, Any]													=       feat_extract_first.save_pretrained(__SCREAMING_SNAKE_CASE		)[0]
																	check_json_file_has_correct_format(__SCREAMING_SNAKE_CASE		)
																	lowercase_	:     str													=       self.feature_extraction_class.from_pretrained(__SCREAMING_SNAKE_CASE		)

											self.assertEqual(feat_extract_second.to_dict()				,							feat_extract_first.to_dict()		)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     Optional[Any]													=       self.feature_extraction_class()
											self.assertIsNotNone(__SCREAMING_SNAKE_CASE		)



