




'''simple docstring'''




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

from .attention_flax import FlaxTransformeraDModel
from .resnet_flax import FlaxDownsampleaD, FlaxResnetBlockaD, FlaxUpsampleaD

class   lowerCAmelCase_      (       nn.Module      ):







  '''simple docstring'''







  lowerCAmelCase_ :    Any    =  42
  lowerCAmelCase_ :    List[str]    =  42
  lowerCAmelCase_ :    Optional[int]    =  0.0
  lowerCAmelCase_ :    Tuple    =  1
  lowerCAmelCase_ :    int    =  1
  lowerCAmelCase_ :    List[Any]    =  True
  lowerCAmelCase_ :    str    =  False
  lowerCAmelCase_ :    str    =  False
  lowerCAmelCase_ :    List[Any]    =  False
  lowerCAmelCase_ :    Optional[Any]    =  jnp.floataa


  def 							SCREAMING_SNAKE_CASE__	(  self			:		Dict       ):






   """simple docstring"""






   UpperCAmelCase__								=			[]
   UpperCAmelCase__								=			[]

   for i in range(self.num_layers       ):
    UpperCAmelCase__								=			self.in_channels if i == 0 else self.out_channels

    UpperCAmelCase__								=			FlaxResnetBlockaD(
        in_channels=_UpperCAmelCase  ,						out_channels=self.out_channels  ,						dropout_prob=self.dropout  ,						dtype=self.dtype  ,						)
    resnets.append(_UpperCAmelCase       )

    UpperCAmelCase__								=			FlaxTransformeraDModel(
        in_channels=self.out_channels  ,						n_heads=self.num_attention_heads  ,						d_head=self.out_channels // self.num_attention_heads  ,						depth=1  ,						use_linear_projection=self.use_linear_projection  ,						only_cross_attention=self.only_cross_attention  ,						use_memory_efficient_attention=self.use_memory_efficient_attention  ,						dtype=self.dtype  ,						)
    attentions.append(_UpperCAmelCase       )

   UpperCAmelCase__								=			resnets
   UpperCAmelCase__								=			attentions

   if self.add_downsample:
    UpperCAmelCase__								=			FlaxDownsampleaD(self.out_channels  ,						dtype=self.dtype       )



  def __call__(  self			:		Union[str, Any]  ,						_UpperCAmelCase			:		Dict  ,						_UpperCAmelCase			:		int  ,						_UpperCAmelCase			:		str  ,						_UpperCAmelCase			:		Optional[int]=True       ):






   """simple docstring"""






   UpperCAmelCase__								=			()

   for resnet, attn in zip(self.resnets  ,						self.attentions       ):
    UpperCAmelCase__								=			resnet(_UpperCAmelCase  ,						_UpperCAmelCase  ,						deterministic=_UpperCAmelCase       )
    UpperCAmelCase__								=			attn(_UpperCAmelCase  ,						_UpperCAmelCase  ,						deterministic=_UpperCAmelCase       )
    output_states += (hidden_states,)

   if self.add_downsample:
    UpperCAmelCase__								=			self.downsamplers_a(_UpperCAmelCase       )
    output_states += (hidden_states,)

   return hidden_states, output_states

class   lowerCAmelCase_      (       nn.Module      ):







  '''simple docstring'''







  lowerCAmelCase_ :    int    =  42
  lowerCAmelCase_ :    List[str]    =  42
  lowerCAmelCase_ :    Optional[int]    =  0.0
  lowerCAmelCase_ :    Optional[int]    =  1
  lowerCAmelCase_ :    str    =  True
  lowerCAmelCase_ :    List[str]    =  jnp.floataa


  def 							SCREAMING_SNAKE_CASE__	(  self			:		Tuple       ):






   """simple docstring"""






   UpperCAmelCase__								=			[]

   for i in range(self.num_layers       ):
    UpperCAmelCase__								=			self.in_channels if i == 0 else self.out_channels

    UpperCAmelCase__								=			FlaxResnetBlockaD(
        in_channels=_UpperCAmelCase  ,						out_channels=self.out_channels  ,						dropout_prob=self.dropout  ,						dtype=self.dtype  ,						)
    resnets.append(_UpperCAmelCase       )
   UpperCAmelCase__								=			resnets

   if self.add_downsample:
    UpperCAmelCase__								=			FlaxDownsampleaD(self.out_channels  ,						dtype=self.dtype       )



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






   """simple docstring"""






   UpperCAmelCase__								=			()

   for resnet in self.resnets:
    UpperCAmelCase__								=			resnet(_UpperCAmelCase  ,						_UpperCAmelCase  ,						deterministic=_UpperCAmelCase       )
    output_states += (hidden_states,)

   if self.add_downsample:
    UpperCAmelCase__								=			self.downsamplers_a(_UpperCAmelCase       )
    output_states += (hidden_states,)

   return hidden_states, output_states

class   lowerCAmelCase_      (       nn.Module      ):







  '''simple docstring'''







  lowerCAmelCase_ :    int    =  42
  lowerCAmelCase_ :    Optional[Any]    =  42
  lowerCAmelCase_ :    Any    =  42
  lowerCAmelCase_ :    str    =  0.0
  lowerCAmelCase_ :    int    =  1
  lowerCAmelCase_ :    Any    =  1
  lowerCAmelCase_ :    Tuple    =  True
  lowerCAmelCase_ :    Dict    =  False
  lowerCAmelCase_ :    Optional[Any]    =  False
  lowerCAmelCase_ :    Any    =  False
  lowerCAmelCase_ :    int    =  jnp.floataa


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






   """simple docstring"""






   UpperCAmelCase__								=			[]
   UpperCAmelCase__								=			[]

   for i in range(self.num_layers       ):
    UpperCAmelCase__								=			self.in_channels if (i == self.num_layers - 1) else self.out_channels
    UpperCAmelCase__								=			self.prev_output_channel if i == 0 else self.out_channels

    UpperCAmelCase__								=			FlaxResnetBlockaD(
        in_channels=resnet_in_channels + res_skip_channels  ,						out_channels=self.out_channels  ,						dropout_prob=self.dropout  ,						dtype=self.dtype  ,						)
    resnets.append(_UpperCAmelCase       )

    UpperCAmelCase__								=			FlaxTransformeraDModel(
        in_channels=self.out_channels  ,						n_heads=self.num_attention_heads  ,						d_head=self.out_channels // self.num_attention_heads  ,						depth=1  ,						use_linear_projection=self.use_linear_projection  ,						only_cross_attention=self.only_cross_attention  ,						use_memory_efficient_attention=self.use_memory_efficient_attention  ,						dtype=self.dtype  ,						)
    attentions.append(_UpperCAmelCase       )

   UpperCAmelCase__								=			resnets
   UpperCAmelCase__								=			attentions

   if self.add_upsample:
    UpperCAmelCase__								=			FlaxUpsampleaD(self.out_channels  ,						dtype=self.dtype       )



  def __call__(  self			:		List[Any]  ,						_UpperCAmelCase			:		List[Any]  ,						_UpperCAmelCase			:		str  ,						_UpperCAmelCase			:		str  ,						_UpperCAmelCase			:		Any  ,						_UpperCAmelCase			:		Union[str, Any]=True       ):






   """simple docstring"""






   for resnet, attn in zip(self.resnets  ,						self.attentions       ):
    # pop res hidden states
    UpperCAmelCase__								=			res_hidden_states_tuple[-1]
    UpperCAmelCase__								=			res_hidden_states_tuple[:-1]
    UpperCAmelCase__								=			jnp.concatenate((hidden_states, res_hidden_states)  ,						axis=-1       )

    UpperCAmelCase__								=			resnet(_UpperCAmelCase  ,						_UpperCAmelCase  ,						deterministic=_UpperCAmelCase       )
    UpperCAmelCase__								=			attn(_UpperCAmelCase  ,						_UpperCAmelCase  ,						deterministic=_UpperCAmelCase       )

   if self.add_upsample:
    UpperCAmelCase__								=			self.upsamplers_a(_UpperCAmelCase       )

   return hidden_states

class   lowerCAmelCase_      (       nn.Module      ):







  '''simple docstring'''







  lowerCAmelCase_ :    List[str]    =  42
  lowerCAmelCase_ :    List[str]    =  42
  lowerCAmelCase_ :    int    =  42
  lowerCAmelCase_ :    str    =  0.0
  lowerCAmelCase_ :    Dict    =  1
  lowerCAmelCase_ :    List[str]    =  True
  lowerCAmelCase_ :    List[Any]    =  jnp.floataa


  def 							SCREAMING_SNAKE_CASE__	(  self			:		Tuple       ):






   """simple docstring"""






   UpperCAmelCase__								=			[]

   for i in range(self.num_layers       ):
    UpperCAmelCase__								=			self.in_channels if (i == self.num_layers - 1) else self.out_channels
    UpperCAmelCase__								=			self.prev_output_channel if i == 0 else self.out_channels

    UpperCAmelCase__								=			FlaxResnetBlockaD(
        in_channels=resnet_in_channels + res_skip_channels  ,						out_channels=self.out_channels  ,						dropout_prob=self.dropout  ,						dtype=self.dtype  ,						)
    resnets.append(_UpperCAmelCase       )

   UpperCAmelCase__								=			resnets

   if self.add_upsample:
    UpperCAmelCase__								=			FlaxUpsampleaD(self.out_channels  ,						dtype=self.dtype       )



  def __call__(  self			:		str  ,						_UpperCAmelCase			:		List[Any]  ,						_UpperCAmelCase			:		Dict  ,						_UpperCAmelCase			:		int  ,						_UpperCAmelCase			:		Tuple=True       ):






   """simple docstring"""






   for resnet in self.resnets:
    # pop res hidden states
    UpperCAmelCase__								=			res_hidden_states_tuple[-1]
    UpperCAmelCase__								=			res_hidden_states_tuple[:-1]
    UpperCAmelCase__								=			jnp.concatenate((hidden_states, res_hidden_states)  ,						axis=-1       )

    UpperCAmelCase__								=			resnet(_UpperCAmelCase  ,						_UpperCAmelCase  ,						deterministic=_UpperCAmelCase       )

   if self.add_upsample:
    UpperCAmelCase__								=			self.upsamplers_a(_UpperCAmelCase       )

   return hidden_states

class   lowerCAmelCase_      (       nn.Module      ):







  '''simple docstring'''







  lowerCAmelCase_ :    Optional[int]    =  42
  lowerCAmelCase_ :    Union[str, Any]    =  0.0
  lowerCAmelCase_ :    Dict    =  1
  lowerCAmelCase_ :    List[Any]    =  1
  lowerCAmelCase_ :    int    =  False
  lowerCAmelCase_ :    int    =  False
  lowerCAmelCase_ :    Any    =  jnp.floataa


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






   """simple docstring"""






   UpperCAmelCase__								=			[
       FlaxResnetBlockaD(
           in_channels=self.in_channels  ,						out_channels=self.in_channels  ,						dropout_prob=self.dropout  ,						dtype=self.dtype  ,						)
   ]

   UpperCAmelCase__								=			[]

   for _ in range(self.num_layers       ):
    UpperCAmelCase__								=			FlaxTransformeraDModel(
        in_channels=self.in_channels  ,						n_heads=self.num_attention_heads  ,						d_head=self.in_channels // self.num_attention_heads  ,						depth=1  ,						use_linear_projection=self.use_linear_projection  ,						use_memory_efficient_attention=self.use_memory_efficient_attention  ,						dtype=self.dtype  ,						)
    attentions.append(_UpperCAmelCase       )

    UpperCAmelCase__								=			FlaxResnetBlockaD(
        in_channels=self.in_channels  ,						out_channels=self.in_channels  ,						dropout_prob=self.dropout  ,						dtype=self.dtype  ,						)
    resnets.append(_UpperCAmelCase       )

   UpperCAmelCase__								=			resnets
   UpperCAmelCase__								=			attentions



  def __call__(  self			:		str  ,						_UpperCAmelCase			:		str  ,						_UpperCAmelCase			:		str  ,						_UpperCAmelCase			:		str  ,						_UpperCAmelCase			:		Any=True       ):






   """simple docstring"""






   UpperCAmelCase__								=			self.resnets[0](_UpperCAmelCase  ,						_UpperCAmelCase       )
   for attn, resnet in zip(self.attentions  ,						self.resnets[1:]       ):
    UpperCAmelCase__								=			attn(_UpperCAmelCase  ,						_UpperCAmelCase  ,						deterministic=_UpperCAmelCase       )
    UpperCAmelCase__								=			resnet(_UpperCAmelCase  ,						_UpperCAmelCase  ,						deterministic=_UpperCAmelCase       )

   return hidden_states







'''simple docstring'''

from string import ascii_lowercase, ascii_uppercase





def lowerCamelCase						(     __lowerCamelCase :    str    )						->str:
    if not sentence:
        return ""
    _SCREAMING_SNAKE_CASE									=			dict(zip(__lowerCamelCase					,       __lowerCamelCase    )    )
    return lower_to_upper.get(sentence[0]					,       sentence[0]    ) + sentence[1:]


if __name__ == "__main__":
      from doctest import testmod

      testmod()



