

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowercase_   							=  logging.get_logger(__name__)

lowercase_   							=  {
    'microsoft/cvt-13': 'https://huggingface.co/microsoft/cvt-13/resolve/main/config.json',
    # See all Cvt models at https://huggingface.co/models?filter=cvt
}





class 					__lowerCAmelCase	(   SCREAMING_SNAKE_CASE				):
  _a		     =    """cvt"""




  def __init__(							self				,  lowerCAmelCase=3				,  lowerCAmelCase=[7, 3, 3]				,  lowerCAmelCase=[4, 2, 2]				,  lowerCAmelCase=[2, 1, 1]				,  lowerCAmelCase=[64, 192, 384]				,  lowerCAmelCase=[1, 3, 6]				,  lowerCAmelCase=[1, 2, 10]				,  lowerCAmelCase=[4.0, 4.0, 4.0]				,  lowerCAmelCase=[0.0, 0.0, 0.0]				,  lowerCAmelCase=[0.0, 0.0, 0.0]				,  lowerCAmelCase=[0.0, 0.0, 0.1]				,  lowerCAmelCase=[True, True, True]				,  lowerCAmelCase=[False, False, True]				,  lowerCAmelCase=["dw_bn", "dw_bn", "dw_bn"]				,  lowerCAmelCase=[3, 3, 3]				,  lowerCAmelCase=[1, 1, 1]				,  lowerCAmelCase=[2, 2, 2]				,  lowerCAmelCase=[1, 1, 1]				,  lowerCAmelCase=[1, 1, 1]				,  lowerCAmelCase=0.02				,  lowerCAmelCase=1e-12				,  **lowerCAmelCase				,  )    ->					Any:
        '''simple docstring'''






        super().__init__(**lowerCAmelCase   )
        _lowercase      			=num_channels
        _lowercase      			=patch_sizes
        _lowercase      			=patch_stride
        _lowercase      			=patch_padding
        _lowercase      			=embed_dim
        _lowercase      			=num_heads
        _lowercase      			=depth
        _lowercase      			=mlp_ratio
        _lowercase      			=attention_drop_rate
        _lowercase      			=drop_rate
        _lowercase      			=drop_path_rate
        _lowercase      			=qkv_bias
        _lowercase      			=cls_token
        _lowercase      			=qkv_projection_method
        _lowercase      			=kernel_qkv
        _lowercase      			=padding_kv
        _lowercase      			=stride_kv
        _lowercase      			=padding_q
        _lowercase      			=stride_q
        _lowercase      			=initializer_range
        _lowercase      			=layer_norm_eps





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





class 					__lowerCAmelCase	(   nn.Module				):
  _a		     =    42
  _a		     =    jnp.floataa




  def     A__	(							self   )    ->					int:
        '''simple docstring'''






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




  def __call__(							self				,  lowerCAmelCase   )    ->					Any:
        '''simple docstring'''






        _lowercase			,			_lowercase			,			_lowercase			,			_lowercase      			=hidden_states.shape
        _lowercase      			=jax.image.resize(
            lowerCAmelCase				,  shape=(batch, height * 2, width * 2, channels)				,  method='nearest'				,  )
        _lowercase      			=self.conv(lowerCAmelCase   )
        return hidden_states





class 					__lowerCAmelCase	(   nn.Module				):
  _a		     =    42
  _a		     =    jnp.floataa




  def     A__	(							self   )    ->					Any:
        '''simple docstring'''






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




  def __call__(							self				,  lowerCAmelCase   )    ->					Optional[int]:
        '''simple docstring'''






        _lowercase      			=self.conv(lowerCAmelCase   )
        return hidden_states





class 					__lowerCAmelCase	(   nn.Module				):
  _a		     =    42
  _a		     =    None
  _a		     =    0.0
  _a		     =    None
  _a		     =    jnp.floataa




  def     A__	(							self   )    ->					Optional[int]:
        '''simple docstring'''






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

        _lowercase      			=nn.GroupNorm(num_groups=32				,  epsilon=1e-5   )
        _lowercase      			=nn.Conv(
            lowerCAmelCase				,  kernel_size=(3, 3)				,  strides=(1, 1)				,  padding=((1, 1), (1, 1))				,  dtype=self.dtype				,  )

        _lowercase      			=nn.Dense(lowerCAmelCase				,  dtype=self.dtype   )

        _lowercase      			=nn.GroupNorm(num_groups=32				,  epsilon=1e-5   )
        _lowercase      			=nn.Dropout(self.dropout_prob   )
        _lowercase      			=nn.Conv(
            lowerCAmelCase				,  kernel_size=(3, 3)				,  strides=(1, 1)				,  padding=((1, 1), (1, 1))				,  dtype=self.dtype				,  )

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

        _lowercase      			=None
        if use_nin_shortcut:
              _lowercase      			=nn.Conv(
                  lowerCAmelCase				,  kernel_size=(1, 1)				,  strides=(1, 1)				,  padding='VALID'				,  dtype=self.dtype				,  )




  def __call__(							self				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase=True   )    ->					Tuple:
        '''simple docstring'''






        _lowercase      			=hidden_states
        _lowercase      			=self.norma(lowerCAmelCase   )
        _lowercase      			=nn.swish(lowerCAmelCase   )
        _lowercase      			=self.conva(lowerCAmelCase   )

        _lowercase      			=self.time_emb_proj(nn.swish(lowerCAmelCase   )   )
        _lowercase      			=jnp.expand_dims(jnp.expand_dims(lowerCAmelCase				,  1   )				,  1   )
        _lowercase      			=hidden_states + temb

        _lowercase      			=self.norma(lowerCAmelCase   )
        _lowercase      			=nn.swish(lowerCAmelCase   )
        _lowercase      			=self.dropout(lowerCAmelCase				,  lowerCAmelCase   )
        _lowercase      			=self.conva(lowerCAmelCase   )

        if self.conv_shortcut is not None:
              _lowercase      			=self.conv_shortcut(lowerCAmelCase   )

        return hidden_states + residual


