





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

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



class  A__       (	nn.Module      ):
      _UpperCAmelCase     :int
      _UpperCAmelCase     :int
      _UpperCAmelCase     :float						   =       0.0
      _UpperCAmelCase     :int						   =       1
      _UpperCAmelCase     :int						   =       1
      _UpperCAmelCase     :bool						   =       True
      _UpperCAmelCase     :bool						   =       False
      _UpperCAmelCase     :bool						   =       False
      _UpperCAmelCase     :bool						   =       False
      _UpperCAmelCase     :jnp.dtype						   =       jnp.floataa





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : List[Any]	     =       []
       UpperCamelCase     : Union[str, Any]	     =       []

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

        UpperCamelCase     : Union[str, Any]	     =       FlaxResnetBlockaD(
            in_channels=A_	,							out_channels=self.out_channels	,							dropout_prob=self.dropout	,							dtype=self.dtype	,							)
        resnets.append(A_       )

        UpperCamelCase     : Tuple	     =       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(A_       )

       UpperCamelCase     : Union[str, Any]	     =       resnets
       UpperCamelCase     : Tuple	     =       attentions

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





      def __call__(			self	,							A_	,							A_	,							A_	,							A_=True       ):
       '''simple docstring'''




       UpperCamelCase     : List[Any]	     =       ()

       for resnet, attn in zip(self.resnets	,							self.attentions       ):
        UpperCamelCase     : Any	     =       resnet(A_	,							A_	,							deterministic=A_       )
        UpperCamelCase     : List[str]	     =       attn(A_	,							A_	,							deterministic=A_       )
        output_states += (hidden_states,)

       if self.add_downsample:
        UpperCamelCase     : str	     =       self.downsamplers_a(A_       )
        output_states += (hidden_states,)

       return hidden_states, output_states



class  A__       (	nn.Module      ):
      _UpperCAmelCase     :int
      _UpperCAmelCase     :int
      _UpperCAmelCase     :float						   =       0.0
      _UpperCAmelCase     :int						   =       1
      _UpperCAmelCase     :bool						   =       True
      _UpperCAmelCase     :jnp.dtype						   =       jnp.floataa





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : str	     =       []

       for i in range(self.num_layers       ):
        UpperCamelCase     : List[str]	     =       self.in_channels if i == 0 else self.out_channels

        UpperCamelCase     : Tuple	     =       FlaxResnetBlockaD(
            in_channels=A_	,							out_channels=self.out_channels	,							dropout_prob=self.dropout	,							dtype=self.dtype	,							)
        resnets.append(A_       )
       UpperCamelCase     : Optional[int]	     =       resnets

       if self.add_downsample:
        UpperCamelCase     : Union[str, Any]	     =       FlaxDownsampleaD(self.out_channels	,							dtype=self.dtype       )





      def __call__(			self	,							A_	,							A_	,							A_=True       ):
       '''simple docstring'''




       UpperCamelCase     : List[str]	     =       ()

       for resnet in self.resnets:
        UpperCamelCase     : Dict	     =       resnet(A_	,							A_	,							deterministic=A_       )
        output_states += (hidden_states,)

       if self.add_downsample:
        UpperCamelCase     : Union[str, Any]	     =       self.downsamplers_a(A_       )
        output_states += (hidden_states,)

       return hidden_states, output_states



class  A__       (	nn.Module      ):
      _UpperCAmelCase     :int
      _UpperCAmelCase     :int
      _UpperCAmelCase     :int
      _UpperCAmelCase     :float						   =       0.0
      _UpperCAmelCase     :int						   =       1
      _UpperCAmelCase     :int						   =       1
      _UpperCAmelCase     :bool						   =       True
      _UpperCAmelCase     :bool						   =       False
      _UpperCAmelCase     :bool						   =       False
      _UpperCAmelCase     :bool						   =       False
      _UpperCAmelCase     :jnp.dtype						   =       jnp.floataa





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : Union[str, Any]	     =       []
       UpperCamelCase     : Optional[int]	     =       []

       for i in range(self.num_layers       ):
        UpperCamelCase     : Union[str, Any]	     =       self.in_channels if (i == self.num_layers - 1) else self.out_channels
        UpperCamelCase     : Dict	     =       self.prev_output_channel if i == 0 else self.out_channels

        UpperCamelCase     : Union[str, Any]	     =       FlaxResnetBlockaD(
            in_channels=resnet_in_channels + res_skip_channels	,							out_channels=self.out_channels	,							dropout_prob=self.dropout	,							dtype=self.dtype	,							)
        resnets.append(A_       )

        UpperCamelCase     : str	     =       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(A_       )

       UpperCamelCase     : str	     =       resnets
       UpperCamelCase     : int	     =       attentions

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





      def __call__(			self	,							A_	,							A_	,							A_	,							A_	,							A_=True       ):
       '''simple docstring'''




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

        UpperCamelCase     : List[str]	     =       resnet(A_	,							A_	,							deterministic=A_       )
        UpperCamelCase     : str	     =       attn(A_	,							A_	,							deterministic=A_       )

       if self.add_upsample:
        UpperCamelCase     : Optional[int]	     =       self.upsamplers_a(A_       )

       return hidden_states



class  A__       (	nn.Module      ):
      _UpperCAmelCase     :int
      _UpperCAmelCase     :int
      _UpperCAmelCase     :int
      _UpperCAmelCase     :float						   =       0.0
      _UpperCAmelCase     :int						   =       1
      _UpperCAmelCase     :bool						   =       True
      _UpperCAmelCase     :jnp.dtype						   =       jnp.floataa





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : List[Any]	     =       []

       for i in range(self.num_layers       ):
        UpperCamelCase     : Union[str, Any]	     =       self.in_channels if (i == self.num_layers - 1) else self.out_channels
        UpperCamelCase     : str	     =       self.prev_output_channel if i == 0 else self.out_channels

        UpperCamelCase     : int	     =       FlaxResnetBlockaD(
            in_channels=resnet_in_channels + res_skip_channels	,							out_channels=self.out_channels	,							dropout_prob=self.dropout	,							dtype=self.dtype	,							)
        resnets.append(A_       )

       UpperCamelCase     : int	     =       resnets

       if self.add_upsample:
        UpperCamelCase     : Optional[Any]	     =       FlaxUpsampleaD(self.out_channels	,							dtype=self.dtype       )





      def __call__(			self	,							A_	,							A_	,							A_	,							A_=True       ):
       '''simple docstring'''




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

        UpperCamelCase     : List[str]	     =       resnet(A_	,							A_	,							deterministic=A_       )

       if self.add_upsample:
        UpperCamelCase     : List[str]	     =       self.upsamplers_a(A_       )

       return hidden_states



class  A__       (	nn.Module      ):
      _UpperCAmelCase     :int
      _UpperCAmelCase     :float						   =       0.0
      _UpperCAmelCase     :int						   =       1
      _UpperCAmelCase     :int						   =       1
      _UpperCAmelCase     :bool						   =       False
      _UpperCAmelCase     :bool						   =       False
      _UpperCAmelCase     :jnp.dtype						   =       jnp.floataa





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : List[str]	     =       [
           FlaxResnetBlockaD(
               in_channels=self.in_channels	,							out_channels=self.in_channels	,							dropout_prob=self.dropout	,							dtype=self.dtype	,							)
       ]

       UpperCamelCase     : Any	     =       []

       for _ in range(self.num_layers       ):
        UpperCamelCase     : str	     =       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(A_       )

        UpperCamelCase     : int	     =       FlaxResnetBlockaD(
            in_channels=self.in_channels	,							out_channels=self.in_channels	,							dropout_prob=self.dropout	,							dtype=self.dtype	,							)
        resnets.append(A_       )

       UpperCamelCase     : Tuple	     =       resnets
       UpperCamelCase     : List[str]	     =       attentions





      def __call__(			self	,							A_	,							A_	,							A_	,							A_=True       ):
       '''simple docstring'''




       UpperCamelCase     : Optional[int]	     =       self.resnets[0](A_	,							A_       )
       for attn, resnet in zip(self.attentions	,							self.resnets[1:]       ):
        UpperCamelCase     : Optional[Any]	     =       attn(A_	,							A_	,							deterministic=A_       )
        UpperCamelCase     : Union[str, Any]	     =       resnet(A_	,							A_	,							deterministic=A_       )

       return hidden_states







from __future__ import annotations



def 		A_    (					_lowerCAmelCase							,       _lowerCAmelCase					)						->			list[str]:
 if partitions <= 0:
  raise ValueError("partitions must be a positive number!"					)
 if partitions > number_of_bytes:
  raise ValueError("partitions can not > number_of_bytes!"					)
 UpperCamelCase     : str	     =       number_of_bytes // partitions
 UpperCamelCase     : List[Any]	     =       []
 for i in range(_lowerCAmelCase					):
  UpperCamelCase     : Optional[Any]	     =       i * bytes_per_partition + 1
  UpperCamelCase     : Any	     =       (
      number_of_bytes if i == partitions - 1 else (i + 1) * bytes_per_partition
  )
  allocation_list.append(F"""{start_bytes}-{end_bytes}"""					)
 return allocation_list


if __name__ == "__main__":
    import doctest

    doctest.testmod()
