





'''simple docstring'''

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


a        =						logging.get_logger(__name__)

a        =						{
    "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 __a (   _snake_case			):
   __UpperCamelCase   : int	      =	'poolformer'





   def __init__(					self				:			Any				,lowerCamelCase				:			str=3				,lowerCamelCase				:			str=16				,lowerCamelCase				:			Dict=16				,lowerCamelCase				:			int=3				,lowerCamelCase				:			List[str]=4.0				,lowerCamelCase				:			List[Any]=[2, 2, 6, 2]				,lowerCamelCase				:			Union[str, Any]=[64, 128, 320, 512]				,lowerCamelCase				:			int=[7, 3, 3, 3]				,lowerCamelCase				:			List[str]=[4, 2, 2, 2]				,lowerCamelCase				:			Any=[2, 1, 1, 1]				,lowerCamelCase				:			List[str]=4				,lowerCamelCase				:			Tuple=0.0				,lowerCamelCase				:			List[Any]="gelu"				,lowerCamelCase				:			List[str]=True				,lowerCamelCase				:			Dict=1E-5				,lowerCamelCase				:			Dict=0.02				,**lowerCamelCase				:			Tuple				,):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       num_channels
      __SCREAMING_SNAKE_CASE      							=       patch_size
      __SCREAMING_SNAKE_CASE      							=       stride
      __SCREAMING_SNAKE_CASE      							=       padding
      __SCREAMING_SNAKE_CASE      							=       pool_size
      __SCREAMING_SNAKE_CASE      							=       hidden_sizes
      __SCREAMING_SNAKE_CASE      							=       mlp_ratio
      __SCREAMING_SNAKE_CASE      							=       depths
      __SCREAMING_SNAKE_CASE      							=       patch_sizes
      __SCREAMING_SNAKE_CASE      							=       strides
      __SCREAMING_SNAKE_CASE      							=       num_encoder_blocks
      __SCREAMING_SNAKE_CASE      							=       drop_path_rate
      __SCREAMING_SNAKE_CASE      							=       hidden_act
      __SCREAMING_SNAKE_CASE      							=       use_layer_scale
      __SCREAMING_SNAKE_CASE      							=       layer_scale_init_value
      __SCREAMING_SNAKE_CASE      							=       initializer_range
      super().__init__(**lowerCamelCase    )







class __a (   _snake_case			):
   __UpperCamelCase   : List[str]	      =	version.parse('1.11'			)





   @property
   def      UpperCAmelCase__     (					self				:			int    ):

      '''simple docstring'''

      return OrderedDict(
          [
              ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
          ]    )





   @property
   def      UpperCAmelCase__     (					self				:			Tuple    ):

      '''simple docstring'''

      return 2E-3












'''simple docstring'''

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







class __a (   nn.Module			):
   __UpperCamelCase   : int
   __UpperCamelCase   : jnp.dtype	      =	jnp.floataa





   def      UpperCAmelCase__     (					self				:			List[Any]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       nn.Conv(
          self.out_channels				,kernel_size=(3, 3)				,strides=(1, 1)				,padding=((1, 1), (1, 1))				,dtype=self.dtype				,)





   def __call__(					self				:			List[Any]				,lowerCamelCase				:			Tuple    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE							,     __SCREAMING_SNAKE_CASE      							=       hidden_states.shape
      __SCREAMING_SNAKE_CASE      							=       jax.image.resize(
          lowerCamelCase				,shape=(batch, height * 2, width * 2, channels)				,method="""nearest"""				,)
      __SCREAMING_SNAKE_CASE      							=       self.conv(lowerCamelCase    )
      return hidden_states







class __a (   nn.Module			):
   __UpperCamelCase   : int
   __UpperCamelCase   : jnp.dtype	      =	jnp.floataa





   def      UpperCAmelCase__     (					self				:			Optional[int]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       nn.Conv(
          self.out_channels				,kernel_size=(3, 3)				,strides=(2, 2)				,padding=((1, 1), (1, 1))				,dtype=self.dtype				,)





   def __call__(					self				:			List[str]				,lowerCamelCase				:			Tuple    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.conv(lowerCamelCase    )
      return hidden_states







class __a (   nn.Module			):
   __UpperCamelCase   : int
   __UpperCamelCase   : int	      =	None
   __UpperCamelCase   : float	      =	0.0
   __UpperCamelCase   : bool	      =	None
   __UpperCamelCase   : jnp.dtype	      =	jnp.floataa





   def      UpperCAmelCase__     (					self				:			Union[str, Any]    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       self.in_channels if self.out_channels is None else self.out_channels

      __SCREAMING_SNAKE_CASE      							=       nn.GroupNorm(num_groups=32				,epsilon=1E-5    )
      __SCREAMING_SNAKE_CASE      							=       nn.Conv(
          lowerCamelCase				,kernel_size=(3, 3)				,strides=(1, 1)				,padding=((1, 1), (1, 1))				,dtype=self.dtype				,)

      __SCREAMING_SNAKE_CASE      							=       nn.Dense(lowerCamelCase				,dtype=self.dtype    )

      __SCREAMING_SNAKE_CASE      							=       nn.GroupNorm(num_groups=32				,epsilon=1E-5    )
      __SCREAMING_SNAKE_CASE      							=       nn.Dropout(self.dropout_prob    )
      __SCREAMING_SNAKE_CASE      							=       nn.Conv(
          lowerCamelCase				,kernel_size=(3, 3)				,strides=(1, 1)				,padding=((1, 1), (1, 1))				,dtype=self.dtype				,)

      __SCREAMING_SNAKE_CASE      							=       self.in_channels != out_channels if self.use_nin_shortcut is None else self.use_nin_shortcut

      __SCREAMING_SNAKE_CASE      							=       None
      if use_nin_shortcut:
         __SCREAMING_SNAKE_CASE      							=       nn.Conv(
             lowerCamelCase				,kernel_size=(1, 1)				,strides=(1, 1)				,padding="""VALID"""				,dtype=self.dtype				,)





   def __call__(					self				:			List[str]				,lowerCamelCase				:			Optional[int]				,lowerCamelCase				:			Tuple				,lowerCamelCase				:			Union[str, Any]=True    ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE      							=       hidden_states
      __SCREAMING_SNAKE_CASE      							=       self.norma(lowerCamelCase    )
      __SCREAMING_SNAKE_CASE      							=       nn.swish(lowerCamelCase    )
      __SCREAMING_SNAKE_CASE      							=       self.conva(lowerCamelCase    )

      __SCREAMING_SNAKE_CASE      							=       self.time_emb_proj(nn.swish(lowerCamelCase    )    )
      __SCREAMING_SNAKE_CASE      							=       jnp.expand_dims(jnp.expand_dims(lowerCamelCase				,1    )				,1    )
      __SCREAMING_SNAKE_CASE      							=       hidden_states + temb

      __SCREAMING_SNAKE_CASE      							=       self.norma(lowerCamelCase    )
      __SCREAMING_SNAKE_CASE      							=       nn.swish(lowerCamelCase    )
      __SCREAMING_SNAKE_CASE      							=       self.dropout(lowerCamelCase				,lowerCamelCase    )
      __SCREAMING_SNAKE_CASE      							=       self.conva(lowerCamelCase    )

      if self.conv_shortcut is not None:
         __SCREAMING_SNAKE_CASE      							=       self.conv_shortcut(lowerCamelCase    )

      return hidden_states + residual





