


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


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

UpperCAmelCase_				:			str   =	{
    '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__  (    lowercase__						,   lowercase__      ):
      snake_case__    :					str					       =						'''nat'''

      snake_case__    :					List[Any]					       =						{
          '''num_attention_heads''': '''num_heads''',
          '''num_hidden_layers''': '''num_layers''',
      }
      def __init__(	self    :	List[Any]					,							SCREAMING_SNAKE_CASE__    :	Dict=4					,							SCREAMING_SNAKE_CASE__    :	str=3					,							SCREAMING_SNAKE_CASE__    :	List[str]=6_4					,							SCREAMING_SNAKE_CASE__    :	Any=[3, 4, 6, 5]					,							SCREAMING_SNAKE_CASE__    :	Any=[2, 4, 8, 1_6]					,							SCREAMING_SNAKE_CASE__    :	Optional[Any]=7					,							SCREAMING_SNAKE_CASE__    :	str=3.0					,							SCREAMING_SNAKE_CASE__    :	Dict=True					,							SCREAMING_SNAKE_CASE__    :	str=0.0					,							SCREAMING_SNAKE_CASE__    :	List[str]=0.0					,							SCREAMING_SNAKE_CASE__    :	Dict=0.1					,							SCREAMING_SNAKE_CASE__    :	List[Any]="gelu"					,							SCREAMING_SNAKE_CASE__    :	List[str]=0.02					,							SCREAMING_SNAKE_CASE__    :	Tuple=1E-5					,							SCREAMING_SNAKE_CASE__    :	Optional[Any]=0.0					,							SCREAMING_SNAKE_CASE__    :	List[str]=None					,							SCREAMING_SNAKE_CASE__    :	str=None					,							**SCREAMING_SNAKE_CASE__    :	Optional[Any]					,							)		->      int:
             super().__init__(**SCREAMING_SNAKE_CASE__					)

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








import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
   import torch

   from transformers.activations import gelu_new, gelu_python, get_activation
@require_torch
class 			SCREAMING_SNAKE_CASE__  (    unittest.TestCase      ):
      def 	SCREAMING_SNAKE_CASE							(	self    :	Dict					)		->      List[str]:
             a_ :		List[str]							=  torch.tensor([-1_0_0, -1, -0.1, 0, 0.1, 1.0, 1_0_0]					)
             a_ :		Union[str, Any]							=  get_activation('gelu'					)
             self.assertTrue(torch.allclose(gelu_python(SCREAMING_SNAKE_CASE__					)					,							torch_builtin(SCREAMING_SNAKE_CASE__					)					)					)
             self.assertFalse(torch.allclose(gelu_python(SCREAMING_SNAKE_CASE__					)					,							gelu_new(SCREAMING_SNAKE_CASE__					)					)					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Union[str, Any]					)		->      Any:
             a_ :		List[str]							=  torch.tensor([-1_0_0, -1, -0.1, 0, 0.1, 1.0, 1_0_0]					)
             a_ :		Union[str, Any]							=  get_activation('gelu'					)
             a_ :		str							=  get_activation('gelu_10'					)

             a_ :		Tuple							=  torch_builtin(SCREAMING_SNAKE_CASE__					)
             a_ :		str							=  geluaa(SCREAMING_SNAKE_CASE__					)

             a_ :		List[Any]							=  torch.where(y_gelu_aa < 10.0					,							1					,							0					)

             self.assertTrue(torch.max(SCREAMING_SNAKE_CASE__					).item() == 10.0					)
             self.assertTrue(torch.allclose(y_gelu * clipped_mask					,							y_gelu_aa * clipped_mask					)					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Dict					)		->      List[Any]:
             get_activation('gelu'					)
             get_activation('gelu_10'					)
             get_activation('gelu_fast'					)
             get_activation('gelu_new'					)
             get_activation('gelu_python'					)
             get_activation('gelu_pytorch_tanh'					)
             get_activation('linear'					)
             get_activation('mish'					)
             get_activation('quick_gelu'					)
             get_activation('relu'					)
             get_activation('sigmoid'					)
             get_activation('silu'					)
             get_activation('swish'					)
             get_activation('tanh'					)
             with self.assertRaises(SCREAMING_SNAKE_CASE__					):
                    get_activation('bogus'					)
             with self.assertRaises(SCREAMING_SNAKE_CASE__					):
                    get_activation(SCREAMING_SNAKE_CASE__					)

      def 	SCREAMING_SNAKE_CASE							(	self    :	str					)		->      str:
             a_ :		Any							=  get_activation('gelu'					)
             a_ :		Any							=  1
             a_ :		int							=  get_activation('gelu'					)
             self.assertEqual(acta.a					,							1					)
             with self.assertRaises(SCREAMING_SNAKE_CASE__					):
                    a_ :		Tuple							=  acta.a


