


"""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__					={
    "microsoft/focalnet-tiny": "https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json",
}





class  lowerCamelCase__    (		_a      , _a     ):
      a			:  Optional[int]           =		"""focalnet"""
      def __init__(		self						:						List[Any]   ,							A_						:						List[Any]=2_2_4   ,							A_						:						Any=4   ,							A_						:						str=3   ,							A_						:						Dict=9_6   ,							A_						:						Dict=False   ,							A_						:						int=[1_9_2, 3_8_4, 7_6_8, 7_6_8]   ,							A_						:						Optional[int]=[2, 2, 6, 2]   ,							A_						:						Tuple=[2, 2, 2, 2]   ,							A_						:						str=[3, 3, 3, 3]   ,							A_						:						str="gelu"   ,							A_						:						List[Any]=4.0   ,							A_						:						Optional[Any]=0.0   ,							A_						:						str=0.1   ,							A_						:						Union[str, Any]=False   ,							A_						:						List[Any]=1e-4   ,							A_						:						str=False   ,							A_						:						Tuple=False   ,							A_						:						Tuple=False   ,							A_						:						Tuple=0.02   ,							A_						:						List[Any]=1e-5   ,							A_						:						Any=3_2   ,							A_						:						Optional[Any]=None   ,							A_						:						Union[str, Any]=None   ,							**A_						:						Union[str, Any]   ,							):






       '''simple docstring'''


       super().__init__(**A_				)

       __lowercase						=						image_size
       __lowercase						=						patch_size
       __lowercase						=						num_channels
       __lowercase						=						embed_dim
       __lowercase						=						use_conv_embed
       __lowercase						=						hidden_sizes
       __lowercase						=						depths
       __lowercase						=						focal_levels
       __lowercase						=						focal_windows
       __lowercase						=						hidden_act
       __lowercase						=						mlp_ratio
       __lowercase						=						hidden_dropout_prob
       __lowercase						=						drop_path_rate
       __lowercase						=						use_layerscale
       __lowercase						=						layerscale_value
       __lowercase						=						use_post_layernorm
       __lowercase						=						use_post_layernorm_in_modulation
       __lowercase						=						normalize_modulator
       __lowercase						=						initializer_range
       __lowercase						=						layer_norm_eps
       __lowercase						=						encoder_stride
       __lowercase						=						["""stem"""] + [F'''stage{idx}''' for idx in range(1   ,							len(self.depths				) + 1				)]
       __lowercase				,		__lowercase						=						get_aligned_output_features_output_indices(
           out_features=A_   ,							out_indices=A_   ,							stage_names=self.stage_names				)




"""simple docstring"""

import unittest

import numpy as np

from transformers.testing_utils import require_flax, require_tf, require_torch
from transformers.utils import (
    expand_dims,
    flatten_dict,
    is_flax_available,
    is_tf_available,
    is_torch_available,
    reshape,
    squeeze,
    transpose,
)


if is_flax_available():
       import jax.numpy as jnp

if is_tf_available():
       import tensorflow as tf

if is_torch_available():
       import torch





class  lowerCamelCase__    (		unittest.TestCase     ):
      def SCREAMING_SNAKE_CASE_						(		self						:						Any				):






       '''simple docstring'''


       __lowercase						=						{
           """task_specific_params""": {
               """summarization""": {"""length_penalty""": 1.0, """max_length""": 1_2_8, """min_length""": 1_2, """num_beams""": 4},
               """summarization_cnn""": {"""length_penalty""": 2.0, """max_length""": 1_4_2, """min_length""": 5_6, """num_beams""": 4},
               """summarization_xsum""": {"""length_penalty""": 1.0, """max_length""": 6_2, """min_length""": 1_1, """num_beams""": 6},
           }
       }
       __lowercase						=						{
           """task_specific_params.summarization.length_penalty""": 1.0,
           """task_specific_params.summarization.max_length""": 1_2_8,
           """task_specific_params.summarization.min_length""": 1_2,
           """task_specific_params.summarization.num_beams""": 4,
           """task_specific_params.summarization_cnn.length_penalty""": 2.0,
           """task_specific_params.summarization_cnn.max_length""": 1_4_2,
           """task_specific_params.summarization_cnn.min_length""": 5_6,
           """task_specific_params.summarization_cnn.num_beams""": 4,
           """task_specific_params.summarization_xsum.length_penalty""": 1.0,
           """task_specific_params.summarization_xsum.max_length""": 6_2,
           """task_specific_params.summarization_xsum.min_length""": 1_1,
           """task_specific_params.summarization_xsum.num_beams""": 6,
       }

       self.assertEqual(flatten_dict(A_				)   ,							A_				)
      def SCREAMING_SNAKE_CASE_						(		self						:						Union[str, Any]				):






       '''simple docstring'''


       __lowercase						=						np.random.randn(3   ,							4				)
       self.assertTrue(np.allclose(transpose(A_				)   ,							x.transpose()				)				)

       __lowercase						=						np.random.randn(3   ,							4   ,							5				)
       self.assertTrue(np.allclose(transpose(A_   ,							axes=(1, 2, 0)				)   ,							x.transpose((1, 2, 0)				)				)				)
      @require_torch
      def SCREAMING_SNAKE_CASE_						(		self						:						Tuple				):






       '''simple docstring'''


       __lowercase						=						np.random.randn(3   ,							4				)
       __lowercase						=						torch.tensor(A_				)
       self.assertTrue(np.allclose(transpose(A_				)   ,							transpose(A_				).numpy()				)				)

       __lowercase						=						np.random.randn(3   ,							4   ,							5				)
       __lowercase						=						torch.tensor(A_				)
       self.assertTrue(np.allclose(transpose(A_   ,							axes=(1, 2, 0)				)   ,							transpose(A_   ,							axes=(1, 2, 0)				).numpy()				)				)
      @require_tf
      def SCREAMING_SNAKE_CASE_						(		self						:						int				):






       '''simple docstring'''


       __lowercase						=						np.random.randn(3   ,							4				)
       __lowercase						=						tf.constant(A_				)
       self.assertTrue(np.allclose(transpose(A_				)   ,							transpose(A_				).numpy()				)				)

       __lowercase						=						np.random.randn(3   ,							4   ,							5				)
       __lowercase						=						tf.constant(A_				)
       self.assertTrue(np.allclose(transpose(A_   ,							axes=(1, 2, 0)				)   ,							transpose(A_   ,							axes=(1, 2, 0)				).numpy()				)				)
      @require_flax
      def SCREAMING_SNAKE_CASE_						(		self						:						Optional[int]				):






       '''simple docstring'''


       __lowercase						=						np.random.randn(3   ,							4				)
       __lowercase						=						jnp.array(A_				)
       self.assertTrue(np.allclose(transpose(A_				)   ,							np.asarray(transpose(A_				)				)				)				)

       __lowercase						=						np.random.randn(3   ,							4   ,							5				)
       __lowercase						=						jnp.array(A_				)
       self.assertTrue(np.allclose(transpose(A_   ,							axes=(1, 2, 0)				)   ,							np.asarray(transpose(A_   ,							axes=(1, 2, 0)				)				)				)				)
      def SCREAMING_SNAKE_CASE_						(		self						:						Tuple				):






       '''simple docstring'''


       __lowercase						=						np.random.randn(3   ,							4				)
       self.assertTrue(np.allclose(reshape(A_   ,							(4, 3)				)   ,							np.reshape(A_   ,							(4, 3)				)				)				)

       __lowercase						=						np.random.randn(3   ,							4   ,							5				)
       self.assertTrue(np.allclose(reshape(A_   ,							(1_2, 5)				)   ,							np.reshape(A_   ,							(1_2, 5)				)				)				)
      @require_torch
      def SCREAMING_SNAKE_CASE_						(		self						:						Dict				):






       '''simple docstring'''


       __lowercase						=						np.random.randn(3   ,							4				)
       __lowercase						=						torch.tensor(A_				)
       self.assertTrue(np.allclose(reshape(A_   ,							(4, 3)				)   ,							reshape(A_   ,							(4, 3)				).numpy()				)				)

       __lowercase						=						np.random.randn(3   ,							4   ,							5				)
       __lowercase						=						torch.tensor(A_				)
       self.assertTrue(np.allclose(reshape(A_   ,							(1_2, 5)				)   ,							reshape(A_   ,							(1_2, 5)				).numpy()				)				)
      @require_tf
      def SCREAMING_SNAKE_CASE_						(		self						:						Optional[int]				):






       '''simple docstring'''


       __lowercase						=						np.random.randn(3   ,							4				)
       __lowercase						=						tf.constant(A_				)
       self.assertTrue(np.allclose(reshape(A_   ,							(4, 3)				)   ,							reshape(A_   ,							(4, 3)				).numpy()				)				)

       __lowercase						=						np.random.randn(3   ,							4   ,							5				)
       __lowercase						=						tf.constant(A_				)
       self.assertTrue(np.allclose(reshape(A_   ,							(1_2, 5)				)   ,							reshape(A_   ,							(1_2, 5)				).numpy()				)				)
      @require_flax
      def SCREAMING_SNAKE_CASE_						(		self						:						str				):






       '''simple docstring'''


       __lowercase						=						np.random.randn(3   ,							4				)
       __lowercase						=						jnp.array(A_				)
       self.assertTrue(np.allclose(reshape(A_   ,							(4, 3)				)   ,							np.asarray(reshape(A_   ,							(4, 3)				)				)				)				)

       __lowercase						=						np.random.randn(3   ,							4   ,							5				)
       __lowercase						=						jnp.array(A_				)
       self.assertTrue(np.allclose(reshape(A_   ,							(1_2, 5)				)   ,							np.asarray(reshape(A_   ,							(1_2, 5)				)				)				)				)
      def SCREAMING_SNAKE_CASE_						(		self						:						Dict				):






       '''simple docstring'''


       __lowercase						=						np.random.randn(1   ,							3   ,							4				)
       self.assertTrue(np.allclose(squeeze(A_				)   ,							np.squeeze(A_				)				)				)

       __lowercase						=						np.random.randn(1   ,							4   ,							1   ,							5				)
       self.assertTrue(np.allclose(squeeze(A_   ,							axis=2				)   ,							np.squeeze(A_   ,							axis=2				)				)				)
      @require_torch
      def SCREAMING_SNAKE_CASE_						(		self						:						List[Any]				):






       '''simple docstring'''


       __lowercase						=						np.random.randn(1   ,							3   ,							4				)
       __lowercase						=						torch.tensor(A_				)
       self.assertTrue(np.allclose(squeeze(A_				)   ,							squeeze(A_				).numpy()				)				)

       __lowercase						=						np.random.randn(1   ,							4   ,							1   ,							5				)
       __lowercase						=						torch.tensor(A_				)
       self.assertTrue(np.allclose(squeeze(A_   ,							axis=2				)   ,							squeeze(A_   ,							axis=2				).numpy()				)				)
      @require_tf
      def SCREAMING_SNAKE_CASE_						(		self						:						Tuple				):






       '''simple docstring'''


       __lowercase						=						np.random.randn(1   ,							3   ,							4				)
       __lowercase						=						tf.constant(A_				)
       self.assertTrue(np.allclose(squeeze(A_				)   ,							squeeze(A_				).numpy()				)				)

       __lowercase						=						np.random.randn(1   ,							4   ,							1   ,							5				)
       __lowercase						=						tf.constant(A_				)
       self.assertTrue(np.allclose(squeeze(A_   ,							axis=2				)   ,							squeeze(A_   ,							axis=2				).numpy()				)				)
      @require_flax
      def SCREAMING_SNAKE_CASE_						(		self						:						List[Any]				):






       '''simple docstring'''


       __lowercase						=						np.random.randn(1   ,							3   ,							4				)
       __lowercase						=						jnp.array(A_				)
       self.assertTrue(np.allclose(squeeze(A_				)   ,							np.asarray(squeeze(A_				)				)				)				)

       __lowercase						=						np.random.randn(1   ,							4   ,							1   ,							5				)
       __lowercase						=						jnp.array(A_				)
       self.assertTrue(np.allclose(squeeze(A_   ,							axis=2				)   ,							np.asarray(squeeze(A_   ,							axis=2				)				)				)				)
      def SCREAMING_SNAKE_CASE_						(		self						:						Tuple				):






       '''simple docstring'''


       __lowercase						=						np.random.randn(3   ,							4				)
       self.assertTrue(np.allclose(expand_dims(A_   ,							axis=1				)   ,							np.expand_dims(A_   ,							axis=1				)				)				)
      @require_torch
      def SCREAMING_SNAKE_CASE_						(		self						:						Optional[int]				):






       '''simple docstring'''


       __lowercase						=						np.random.randn(3   ,							4				)
       __lowercase						=						torch.tensor(A_				)
       self.assertTrue(np.allclose(expand_dims(A_   ,							axis=1				)   ,							expand_dims(A_   ,							axis=1				).numpy()				)				)
      @require_tf
      def SCREAMING_SNAKE_CASE_						(		self						:						Optional[Any]				):






       '''simple docstring'''


       __lowercase						=						np.random.randn(3   ,							4				)
       __lowercase						=						tf.constant(A_				)
       self.assertTrue(np.allclose(expand_dims(A_   ,							axis=1				)   ,							expand_dims(A_   ,							axis=1				).numpy()				)				)






      @require_flax
      def SCREAMING_SNAKE_CASE_						(		self						:						List[str]				):






       '''simple docstring'''


       __lowercase						=						np.random.randn(3   ,							4				)
       __lowercase						=						jnp.array(A_				)
       self.assertTrue(np.allclose(expand_dims(A_   ,							axis=1				)   ,							np.asarray(expand_dims(A_   ,							axis=1				)				)				)				)
