






import flax.linen as nn
import jax
import jax.numpy as jnp
class     a    ( nn.Module   ):



      """simple docstring"""


      a  : int
      a  : jnp.dtype							       =	jnp.floataa
      def 	UpperCAmelCase      (      self					:			Optional[int]					)							->      str:
        __UpperCAmelCase							:	Tuple           =  nn.Conv(
            self.out_channels		,      kernel_size=(3, 3)		,      strides=(1, 1)		,      padding=((1, 1), (1, 1))		,      dtype=self.dtype		,      )




      def __call__(      self					:			Dict		,      __lowercase					:			Union[str, Any]					)							->      List[Any]:
        __UpperCAmelCase      , __UpperCAmelCase      , __UpperCAmelCase      , __UpperCAmelCase							:	Dict           =  hidden_states.shape
        __UpperCAmelCase							:	str           =  jax.image.resize(
            __lowercase		,      shape=(batch, height * 2, width * 2, channels)		,      method="""nearest"""		,      )
        __UpperCAmelCase							:	Optional[int]           =  self.conv(__lowercase					)
        return hidden_states


class     a    ( nn.Module   ):



      """simple docstring"""


      a  : int
      a  : jnp.dtype							       =	jnp.floataa
      def 	UpperCAmelCase      (      self					:			int					)							->      Tuple:
        __UpperCAmelCase							:	List[Any]           =  nn.Conv(
            self.out_channels		,      kernel_size=(3, 3)		,      strides=(2, 2)		,      padding=((1, 1), (1, 1))		,      dtype=self.dtype		,      )




      def __call__(      self					:			Optional[int]		,      __lowercase					:			Optional[int]					)							->      Optional[int]:
        # pad = ((0, 0), (0, 1), (0, 1), (0, 0))  # pad height and width dim
        # hidden_states = jnp.pad(hidden_states, pad_width=pad)
        __UpperCAmelCase							:	Tuple           =  self.conv(__lowercase					)
        return hidden_states


class     a    ( nn.Module   ):



      """simple docstring"""


      a  : int
      a  : int							       =	None
      a  : float							       =	0.0
      a  : bool							       =	None
      a  : jnp.dtype							       =	jnp.floataa
      def 	UpperCAmelCase      (      self					:			Any					)							->      Optional[Any]:
        __UpperCAmelCase							:	List[Any]           =  self.in_channels if self.out_channels is None else self.out_channels

        __UpperCAmelCase							:	Dict           =  nn.GroupNorm(num_groups=32		,      epsilon=1e-5					)
        __UpperCAmelCase							:	List[str]           =  nn.Conv(
            __lowercase		,      kernel_size=(3, 3)		,      strides=(1, 1)		,      padding=((1, 1), (1, 1))		,      dtype=self.dtype		,      )

        __UpperCAmelCase							:	str           =  nn.Dense(__lowercase		,      dtype=self.dtype					)

        __UpperCAmelCase							:	List[Any]           =  nn.GroupNorm(num_groups=32		,      epsilon=1e-5					)
        __UpperCAmelCase							:	List[str]           =  nn.Dropout(self.dropout_prob					)
        __UpperCAmelCase							:	Optional[int]           =  nn.Conv(
            __lowercase		,      kernel_size=(3, 3)		,      strides=(1, 1)		,      padding=((1, 1), (1, 1))		,      dtype=self.dtype		,      )

        __UpperCAmelCase							:	Union[str, Any]           =  self.in_channels != out_channels if self.use_nin_shortcut is None else self.use_nin_shortcut

        __UpperCAmelCase							:	List[str]           =  None
        if use_nin_shortcut:
          __UpperCAmelCase							:	str           =  nn.Conv(
              __lowercase		,      kernel_size=(1, 1)		,      strides=(1, 1)		,      padding="""VALID"""		,      dtype=self.dtype		,      )




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

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

        __UpperCAmelCase							:	List[Any]           =  self.norma(__lowercase					)
        __UpperCAmelCase							:	List[Any]           =  nn.swish(__lowercase					)
        __UpperCAmelCase							:	List[Any]           =  self.dropout(__lowercase		,      __lowercase					)
        __UpperCAmelCase							:	Union[str, Any]           =  self.conva(__lowercase					)

        if self.conv_shortcut is not None:
          __UpperCAmelCase							:	List[Any]           =  self.conv_shortcut(__lowercase					)

        return hidden_states + residual










from functools import lru_cache






@lru_cache
def 				lowerCamelCase__      (    __lowerCamelCase			:     int		):
  if num < 0:
    raise ValueError("""Number should not be negative."""		)

  return 1 if num in (0, 1) else num * factorial(num - 1		)


if __name__ == "__main__":
       import doctest

       doctest.testmod()


