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


class     __lowerCAmelCase						(						nn.Module   ):



      """simple docstring"""







      A__						:      int   =     4_2
      A__						:      Dict   =     jnp.floataa




      def 		snake_case_      (   self		:							str					):
          __lowercase		:      List[Any]						     =							nn.Conv(
              self.out_channels					,							kernel_size=(3, 3)					,							strides=(1, 1)					,							padding=((1, 1), (1, 1))					,							dtype=self.dtype					,							)




      def __call__(   self		:							List[str]					,							_snake_case		:							int					):
          __lowercase		:      Optional[Any]						     =							hidden_states.shape
          __lowercase		:      Any						     =							jax.image.resize(
              __SCREAMING_SNAKE_CASE					,							shape=(batch, height * 2, width * 2, channels)					,							method='''nearest'''					,							)
          __lowercase		:      Any						     =							self.conv(__SCREAMING_SNAKE_CASE					)
          return hidden_states






class     __lowerCAmelCase						(						nn.Module   ):



      """simple docstring"""







      A__						:      Optional[Any]   =     4_2
      A__						:      Dict   =     jnp.floataa




      def 		snake_case_      (   self		:							Tuple					):
          __lowercase		:      Optional[int]						     =							nn.Conv(
              self.out_channels					,							kernel_size=(3, 3)					,							strides=(2, 2)					,							padding=((1, 1), (1, 1))					,							dtype=self.dtype					,							)




      def __call__(   self		:							Any					,							_snake_case		:							Union[str, Any]					):
          # pad = ((0, 0), (0, 1), (0, 1), (0, 0))  # pad height and width dim
          # hidden_states = jnp.pad(hidden_states, pad_width=pad)
          __lowercase		:      Union[str, Any]						     =							self.conv(__SCREAMING_SNAKE_CASE					)
          return hidden_states






class     __lowerCAmelCase						(						nn.Module   ):



      """simple docstring"""







      A__						:      str   =     4_2
      A__						:      List[Any]   =     None
      A__						:      int   =     0.0
      A__						:      Union[str, Any]   =     None
      A__						:      str   =     jnp.floataa




      def 		snake_case_      (   self		:							Optional[int]					):
          __lowercase		:      Optional[int]						     =							self.in_channels if self.out_channels is None else self.out_channels

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

          __lowercase		:      Optional[Any]						     =							nn.Dense(__SCREAMING_SNAKE_CASE					,							dtype=self.dtype					)

          __lowercase		:      Tuple						     =							nn.GroupNorm(num_groups=32					,							epsilon=1E-5					)
          __lowercase		:      Union[str, Any]						     =							nn.Dropout(self.dropout_prob					)
          __lowercase		:      Optional[Any]						     =							nn.Conv(
              __SCREAMING_SNAKE_CASE					,							kernel_size=(3, 3)					,							strides=(1, 1)					,							padding=((1, 1), (1, 1))					,							dtype=self.dtype					,							)

          __lowercase		:      int						     =							self.in_channels != out_channels if self.use_nin_shortcut is None else self.use_nin_shortcut

          __lowercase		:      Any						     =							None
          if use_nin_shortcut:
              __lowercase		:      Optional[Any]						     =							nn.Conv(
                  __SCREAMING_SNAKE_CASE					,							kernel_size=(1, 1)					,							strides=(1, 1)					,							padding='''VALID'''					,							dtype=self.dtype					,							)




      def __call__(   self		:							Dict					,							_snake_case		:							List[Any]					,							_snake_case		:							Union[str, Any]					,							_snake_case		:							int=True					):
          __lowercase		:      Union[str, Any]						     =							hidden_states
          __lowercase		:      int						     =							self.norma(__SCREAMING_SNAKE_CASE					)
          __lowercase		:      Optional[Any]						     =							nn.swish(__SCREAMING_SNAKE_CASE					)
          __lowercase		:      Union[str, Any]						     =							self.conva(__SCREAMING_SNAKE_CASE					)

          __lowercase		:      List[Any]						     =							self.time_emb_proj(nn.swish(__SCREAMING_SNAKE_CASE					)					)
          __lowercase		:      List[str]						     =							jnp.expand_dims(jnp.expand_dims(__SCREAMING_SNAKE_CASE					,							1					)					,							1					)
          __lowercase		:      int						     =							hidden_states + temb

          __lowercase		:      Tuple						     =							self.norma(__SCREAMING_SNAKE_CASE					)
          __lowercase		:      List[str]						     =							nn.swish(__SCREAMING_SNAKE_CASE					)
          __lowercase		:      Dict						     =							self.dropout(__SCREAMING_SNAKE_CASE					,							__SCREAMING_SNAKE_CASE					)
          __lowercase		:      List[Any]						     =							self.conva(__SCREAMING_SNAKE_CASE					)

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

          return hidden_states + residual










'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


__lowerCAmelCase									=   {'configuration_deit': ['DEIT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'DeiTConfig', 'DeiTOnnxConfig']}

try:
		if not is_vision_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__lowerCAmelCase									=   ['DeiTFeatureExtractor']
		__lowerCAmelCase									=   ['DeiTImageProcessor']

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__lowerCAmelCase									=   [
		    'DEIT_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'DeiTForImageClassification',
		    'DeiTForImageClassificationWithTeacher',
		    'DeiTForMaskedImageModeling',
		    'DeiTModel',
		    'DeiTPreTrainedModel',
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__lowerCAmelCase									=   [
		    'TF_DEIT_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'TFDeiTForImageClassification',
		    'TFDeiTForImageClassificationWithTeacher',
		    'TFDeiTForMaskedImageModeling',
		    'TFDeiTModel',
		    'TFDeiTPreTrainedModel',
		]


if TYPE_CHECKING:
		from .configuration_deit import DEIT_PRETRAINED_CONFIG_ARCHIVE_MAP, DeiTConfig, DeiTOnnxConfig

		try:
				if not is_vision_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .feature_extraction_deit import DeiTFeatureExtractor
				from .image_processing_deit import DeiTImageProcessor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_deit import (
				    DEIT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    DeiTForImageClassification,
				    DeiTForImageClassificationWithTeacher,
				    DeiTForMaskedImageModeling,
				    DeiTModel,
				    DeiTPreTrainedModel,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_deit import (
				    TF_DEIT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFDeiTForImageClassification,
				    TFDeiTForImageClassificationWithTeacher,
				    TFDeiTForMaskedImageModeling,
				    TFDeiTModel,
				    TFDeiTPreTrainedModel,
				)


else:
		import sys

		__lowerCAmelCase									=   _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)




