


from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowerCamelCase					:		Optional[Any]            =						logging.get_logger(__name__)

lowerCamelCase					:		List[Any]            =						{
    """sail/poolformer_s12""": """https://huggingface.co/sail/poolformer_s12/resolve/main/config.json""",
    # See all PoolFormer models at https://huggingface.co/models?filter=poolformer
}


class snake_case__			(    _UpperCAmelCase					):
       _lowerCAmelCase   ='poolformer'




       def __init__( self				:    List[str]    ,				_lowerCamelCase				:    Optional[Any]=3    ,				_lowerCamelCase				:    Optional[Any]=1_6    ,				_lowerCamelCase				:    Tuple=1_6    ,				_lowerCamelCase				:    int=3    ,				_lowerCamelCase				:    List[str]=4.0    ,				_lowerCamelCase				:    List[str]=[2, 2, 6, 2]    ,				_lowerCamelCase				:    Optional[int]=[6_4, 1_2_8, 3_2_0, 5_1_2]    ,				_lowerCamelCase				:    Tuple=[7, 3, 3, 3]    ,				_lowerCamelCase				:    str=[4, 2, 2, 2]    ,				_lowerCamelCase				:    Tuple=[2, 1, 1, 1]    ,				_lowerCamelCase				:    Any=4    ,				_lowerCamelCase				:    Tuple=0.0    ,				_lowerCamelCase				:    str="gelu"    ,				_lowerCamelCase				:    List[str]=True    ,				_lowerCamelCase				:    int=1E-5    ,				_lowerCamelCase				:    Optional[Any]=0.02    ,				**_lowerCamelCase				:    Dict    ,				):
              snake_case__ :       int	   =							num_channels
              snake_case__ :       Union[str, Any]	   =							patch_size
              snake_case__ :       Optional[Any]	   =							stride
              snake_case__ :       int	   =							padding
              snake_case__ :       List[Any]	   =							pool_size
              snake_case__ :       Dict	   =							hidden_sizes
              snake_case__ :       str	   =							mlp_ratio
              snake_case__ :       Tuple	   =							depths
              snake_case__ :       Union[str, Any]	   =							patch_sizes
              snake_case__ :       Dict	   =							strides
              snake_case__ :       int	   =							num_encoder_blocks
              snake_case__ :       Tuple	   =							drop_path_rate
              snake_case__ :       Union[str, Any]	   =							hidden_act
              snake_case__ :       List[Any]	   =							use_layer_scale
              snake_case__ :       Tuple	   =							layer_scale_init_value
              snake_case__ :       int	   =							initializer_range
              super().__init__(**SCREAMING_SNAKE_CASE_			)


class snake_case__			(    _UpperCAmelCase					):
       _lowerCAmelCase   =version.parse('1.11'					)




       @property
       def     UpperCAmelCase__    ( self				:    List[Any]			):
              return OrderedDict(
                  [
                      ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
                  ]			)




       @property
       def     UpperCAmelCase__    ( self				:    Union[str, Any]			):
              return 2E-3









'''simple docstring'''



import flax.linen as nn
import jax
import jax.numpy as jnp





class   UpperCAmelCase_    (nn.Module    ):





    """simple docstring"""






    lowerCamelCase    :   int
    lowerCamelCase    :   jnp.dtype					=     jnp.floataa







    def  lowercase_							(				self      )							->	Union[str, Any]:
         __lowerCamelCase  :      Optional[Any]														=						nn.Conv(
             self.out_channels     ,	kernel_size=(3, 3)     ,	strides=(1, 1)     ,	padding=((1, 1), (1, 1))     ,	dtype=self.dtype     ,	)







    def __call__(				self     ,	SCREAMING_SNAKE_CASE_      )							->	Any:
         __lowerCamelCase							,			__lowerCamelCase							,			__lowerCamelCase							,			__lowerCamelCase  :      Optional[int]														=						hidden_states.shape
         __lowerCamelCase  :      Dict														=						jax.image.resize(
             SCREAMING_SNAKE_CASE_     ,	shape=(batch, height * 2, width * 2, channels)     ,	method='nearest'     ,	)
         __lowerCamelCase  :      Optional[Any]														=						self.conv(SCREAMING_SNAKE_CASE_      )
         return hidden_states







class   UpperCAmelCase_    (nn.Module    ):





    """simple docstring"""






    lowerCamelCase    :   int
    lowerCamelCase    :   jnp.dtype					=     jnp.floataa







    def  lowercase_							(				self      )							->	List[str]:
         __lowerCamelCase  :      str														=						nn.Conv(
             self.out_channels     ,	kernel_size=(3, 3)     ,	strides=(2, 2)     ,	padding=((1, 1), (1, 1))     ,	dtype=self.dtype     ,	)







    def __call__(				self     ,	SCREAMING_SNAKE_CASE_      )							->	List[str]:
         # pad = ((0, 0), (0, 1), (0, 1), (0, 0))  # pad height and width dim
         # hidden_states = jnp.pad(hidden_states, pad_width=pad)
         __lowerCamelCase  :      str														=						self.conv(SCREAMING_SNAKE_CASE_      )
         return hidden_states







class   UpperCAmelCase_    (nn.Module    ):





    """simple docstring"""






    lowerCamelCase    :   int
    lowerCamelCase    :   int					=     None
    lowerCamelCase    :   float					=     0.0
    lowerCamelCase    :   bool					=     None
    lowerCamelCase    :   jnp.dtype					=     jnp.floataa







    def  lowercase_							(				self      )							->	Optional[int]:
         __lowerCamelCase  :      Optional[Any]														=						self.in_channels if self.out_channels is None else self.out_channels

         __lowerCamelCase  :      Optional[Any]														=						nn.GroupNorm(num_groups=32     ,	epsilon=1E-5      )
         __lowerCamelCase  :      Tuple														=						nn.Conv(
             SCREAMING_SNAKE_CASE_     ,	kernel_size=(3, 3)     ,	strides=(1, 1)     ,	padding=((1, 1), (1, 1))     ,	dtype=self.dtype     ,	)

         __lowerCamelCase  :      List[str]														=						nn.Dense(SCREAMING_SNAKE_CASE_     ,	dtype=self.dtype      )

         __lowerCamelCase  :      Dict														=						nn.GroupNorm(num_groups=32     ,	epsilon=1E-5      )
         __lowerCamelCase  :      int														=						nn.Dropout(self.dropout_prob      )
         __lowerCamelCase  :      Union[str, Any]														=						nn.Conv(
             SCREAMING_SNAKE_CASE_     ,	kernel_size=(3, 3)     ,	strides=(1, 1)     ,	padding=((1, 1), (1, 1))     ,	dtype=self.dtype     ,	)

         __lowerCamelCase  :      Optional[int]														=						self.in_channels != out_channels if self.use_nin_shortcut is None else self.use_nin_shortcut

         __lowerCamelCase  :      List[Any]														=						None
         if use_nin_shortcut:
              __lowerCamelCase  :      Any														=						nn.Conv(
                  SCREAMING_SNAKE_CASE_     ,	kernel_size=(1, 1)     ,	strides=(1, 1)     ,	padding='VALID'     ,	dtype=self.dtype     ,	)







    def __call__(				self     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_=True      )							->	Tuple:
         __lowerCamelCase  :      List[Any]														=						hidden_states
         __lowerCamelCase  :      str														=						self.norma(SCREAMING_SNAKE_CASE_      )
         __lowerCamelCase  :      Union[str, Any]														=						nn.swish(SCREAMING_SNAKE_CASE_      )
         __lowerCamelCase  :      Union[str, Any]														=						self.conva(SCREAMING_SNAKE_CASE_      )

         __lowerCamelCase  :      str														=						self.time_emb_proj(nn.swish(SCREAMING_SNAKE_CASE_      )      )
         __lowerCamelCase  :      List[str]														=						jnp.expand_dims(jnp.expand_dims(SCREAMING_SNAKE_CASE_     ,	1      )     ,	1      )
         __lowerCamelCase  :      Optional[int]														=						hidden_states + temb

         __lowerCamelCase  :      List[Any]														=						self.norma(SCREAMING_SNAKE_CASE_      )
         __lowerCamelCase  :      Any														=						nn.swish(SCREAMING_SNAKE_CASE_      )
         __lowerCamelCase  :      List[Any]														=						self.dropout(SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_      )
         __lowerCamelCase  :      List[Any]														=						self.conva(SCREAMING_SNAKE_CASE_      )

         if self.conv_shortcut is not None:
              __lowerCamelCase  :      List[str]														=						self.conv_shortcut(SCREAMING_SNAKE_CASE_      )

         return hidden_states + residual






