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


class  _UpperCAmelCase ( nn.Module    ):

     """simple docstring"""

     a_    	=					42
     a_    	=					jnp.floataa


     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       a_      :	Any      =							nn.Conv(
           self.out_channels							,		kernel_size=(3, 3)							,		strides=(1, 1)							,		padding=((1, 1), (1, 1))							,		dtype=self.dtype							,		)






     def __call__(      self							,		lowerCAmelCase_ ):

       '''simple docstring'''

       a_      :	Union[str, Any]      =							hidden_states.shape
       a_      :	Tuple      =							jax.image.resize(
           lowerCAmelCase_							,		shape=(batch, height * 2, width * 2, channels)							,		method="""nearest"""							,		)
       a_      :	Tuple      =							self.conv(lowerCAmelCase_ )
       return hidden_states







class  _UpperCAmelCase ( nn.Module    ):

     """simple docstring"""

     a_    	=					42
     a_    	=					jnp.floataa


     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       a_      :	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							,		lowerCAmelCase_ ):

       '''simple docstring'''

       a_      :	int      =							self.conv(lowerCAmelCase_ )
       return hidden_states







class  _UpperCAmelCase ( nn.Module    ):

     """simple docstring"""

     a_    	=					42
     a_    	=					None
     a_    	=					0.0
     a_    	=					None
     a_    	=					jnp.floataa


     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       a_      :	Optional[int]      =							self.in_channels if self.out_channels is None else self.out_channels

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

       a_      :	Any      =							nn.Dense(lowerCAmelCase_							,		dtype=self.dtype )

       a_      :	List[Any]      =							nn.GroupNorm(num_groups=32							,		epsilon=1E-5 )
       a_      :	Any      =							nn.Dropout(self.dropout_prob )
       a_      :	str      =							nn.Conv(
           lowerCAmelCase_							,		kernel_size=(3, 3)							,		strides=(1, 1)							,		padding=((1, 1), (1, 1))							,		dtype=self.dtype							,		)

       a_      :	Any      =							self.in_channels != out_channels if self.use_nin_shortcut is None else self.use_nin_shortcut

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






     def __call__(      self							,		lowerCAmelCase_							,		lowerCAmelCase_							,		lowerCAmelCase_=True ):

       '''simple docstring'''

       a_      :	int      =							hidden_states
       a_      :	Dict      =							self.norma(lowerCAmelCase_ )
       a_      :	List[Any]      =							nn.swish(lowerCAmelCase_ )
       a_      :	str      =							self.conva(lowerCAmelCase_ )

       a_      :	List[Any]      =							self.time_emb_proj(nn.swish(lowerCAmelCase_ ) )
       a_      :	Tuple      =							jnp.expand_dims(jnp.expand_dims(lowerCAmelCase_							,		1 )							,		1 )
       a_      :	List[str]      =							hidden_states + temb

       a_      :	Tuple      =							self.norma(lowerCAmelCase_ )
       a_      :	str      =							nn.swish(lowerCAmelCase_ )
       a_      :	Any      =							self.dropout(lowerCAmelCase_							,		lowerCAmelCase_ )
       a_      :	List[Any]      =							self.conva(lowerCAmelCase_ )

       if self.conv_shortcut is not None:
         a_      :	Union[str, Any]      =							self.conv_shortcut(lowerCAmelCase_ )

       return hidden_states + residual




'''simple docstring'''

from torch import nn






def 	_snake_case						(      A_       :    Dict   ):
  """simple docstring"""







  if act_fn in ["swish", "silu"]:
    return nn.SiLU()
  elif act_fn == "mish":
    return nn.Mish()
  elif act_fn == "gelu":
    return nn.GELU()
  else:
    raise ValueError(f'''Unsupported activation function: {act_fn}'''   )


