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


__lowerCAmelCase					:			Union[str, Any]			      =		logging.get_logger(__name__)

__lowerCAmelCase					:			Tuple			      =		{
    "shi-labs/dinat-mini-in1k-224": "https://huggingface.co/shi-labs/dinat-mini-in1k-224/resolve/main/config.json",
    # See all Dinat models at https://huggingface.co/models?filter=dinat
}


class 						__lowerCAmelCase	(	lowerCAmelCase_ , lowerCAmelCase_      ):



      """simple docstring"""







      A__	:			int        =    '''dinat'''

      A__	:			Tuple        =    {
          '''num_attention_heads''': '''num_heads''',
          '''num_hidden_layers''': '''num_layers''',
      }




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

          __lowercase		:			Optional[Any]	    =       patch_size
          __lowercase		:			Any	    =       num_channels
          __lowercase		:			Optional[Any]	    =       embed_dim
          __lowercase		:			Dict	    =       depths
          __lowercase		:			List[str]	    =       len(_snake_case				)
          __lowercase		:			int	    =       num_heads
          __lowercase		:			Union[str, Any]	    =       kernel_size
          __lowercase		:			Union[str, Any]	    =       dilations
          __lowercase		:			Any	    =       mlp_ratio
          __lowercase		:			Dict	    =       qkv_bias
          __lowercase		:			Union[str, Any]	    =       hidden_dropout_prob
          __lowercase		:			Optional[int]	    =       attention_probs_dropout_prob
          __lowercase		:			Union[str, Any]	    =       drop_path_rate
          __lowercase		:			str	    =       hidden_act
          __lowercase		:			Tuple	    =       layer_norm_eps
          __lowercase		:			Any	    =       initializer_range
          # we set the hidden_size attribute in order to make Dinat work with VisionEncoderDecoderModel
          # this indicates the channel dimension after the last stage of the model
          __lowercase		:			int	    =       int(embed_dim * 2 ** (len(_snake_case				) - 1)				)
          __lowercase		:			Optional[int]	    =       layer_scale_init_value
          __lowercase		:			Union[str, Any]	    =       ['''stem'''] + [F'stage{idx}' for idx in range(1				,       len(_snake_case				) + 1				)]
          __lowercase    ,      __lowercase		:			Dict	    =       get_aligned_output_features_output_indices(
              out_features=_snake_case				,       out_indices=_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 						__lowerCAmelCase	(	unittest.TestCase      ):



      """simple docstring"""







      def 		snake_case_			(      self		:       Optional[Any]				):
          __lowercase		:			Union[str, Any]	    =       torch.tensor([-100, -1, -0.1, 0, 0.1, 1.0, 100]				)
          __lowercase		:			Any	    =       get_activation('''gelu'''				)
          self.assertTrue(torch.allclose(gelu_python(_snake_case				)				,       torch_builtin(_snake_case				)				)				)
          self.assertFalse(torch.allclose(gelu_python(_snake_case				)				,       gelu_new(_snake_case				)				)				)




      def 		snake_case_			(      self		:       Dict				):
          __lowercase		:			Any	    =       torch.tensor([-100, -1, -0.1, 0, 0.1, 1.0, 100]				)
          __lowercase		:			List[str]	    =       get_activation('''gelu'''				)
          __lowercase		:			Optional[Any]	    =       get_activation('''gelu_10'''				)

          __lowercase		:			Tuple	    =       torch_builtin(_snake_case				)
          __lowercase		:			List[Any]	    =       geluaa(_snake_case				)

          __lowercase		:			Tuple	    =       torch.where(y_gelu_aa < 10.0				,       1				,       0				)

          self.assertTrue(torch.max(_snake_case				).item() == 10.0				)
          self.assertTrue(torch.allclose(y_gelu * clipped_mask				,       y_gelu_aa * clipped_mask				)				)




      def 		snake_case_			(      self		:       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(_snake_case				):
              get_activation('''bogus'''				)
          with self.assertRaises(_snake_case				):
              get_activation(_snake_case				)




      def 		snake_case_			(      self		:       Dict				):
          __lowercase		:			Union[str, Any]	    =       get_activation('''gelu'''				)
          __lowercase		:			List[str]	    =       1
          __lowercase		:			Union[str, Any]	    =       get_activation('''gelu'''				)
          self.assertEqual(acta.a				,       1				)
          with self.assertRaises(_snake_case				):
              __lowercase		:			Tuple	    =       acta.a


