
'''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  ):
 A_				:				int
 A_				:				int
 A_				:				float	=			0.0
 A_				:				int	=			1
 A_				:				int	=			1
 A_				:				bool	=			True
 A_				:				bool	=			False
 A_				:				bool	=			False
 A_				:				bool	=			False
 A_				:				jnp.dtype	=			jnp.floataa


 def    _A	(    self  : List[str]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   int     		=	[]
  lowerCAmelCase__     :   Any     		=	[]

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

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

   lowerCAmelCase__     :   Union[str, Any]     		=	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__    )

  lowerCAmelCase__     :   Any     		=	resnets
  lowerCAmelCase__     :   Any     		=	attentions

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


 def __call__(    self  : List[str]			,							a__  : List[str]			,							a__  : Optional[Any]			,							a__  : str			,							a__  : str=True    ):
  '''simple docstring'''

  lowerCAmelCase__     :   List[Any]     		=	()

  for resnet, attn in zip(self.resnets			,							self.attentions    ):
   lowerCAmelCase__     :   List[Any]     		=	resnet(a__			,							a__			,							deterministic=a__    )
   lowerCAmelCase__     :   Tuple     		=	attn(a__			,							a__			,							deterministic=a__    )
   output_states += (hidden_states,)

  if self.add_downsample:
   lowerCAmelCase__     :   List[str]     		=	self.downsamplers_a(a__    )
   output_states += (hidden_states,)

  return hidden_states, output_states




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


 def    _A	(    self  : Union[str, Any]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   Tuple     		=	[]

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

   lowerCAmelCase__     :   Tuple     		=	FlaxResnetBlockaD(
       in_channels=a__			,							out_channels=self.out_channels			,							dropout_prob=self.dropout			,							dtype=self.dtype			,							)
   resnets.append(a__    )
  lowerCAmelCase__     :   Dict     		=	resnets

  if self.add_downsample:
   lowerCAmelCase__     :   Optional[int]     		=	FlaxDownsampleaD(self.out_channels			,							dtype=self.dtype    )


 def __call__(    self  : List[Any]			,							a__  : Optional[int]			,							a__  : Union[str, Any]			,							a__  : List[Any]=True    ):
  '''simple docstring'''

  lowerCAmelCase__     :   Tuple     		=	()

  for resnet in self.resnets:
   lowerCAmelCase__     :   List[Any]     		=	resnet(a__			,							a__			,							deterministic=a__    )
   output_states += (hidden_states,)

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

  return hidden_states, output_states




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


 def    _A	(    self  : Optional[int]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   List[str]     		=	[]
  lowerCAmelCase__     :   str     		=	[]

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

   lowerCAmelCase__     :   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__    )

   lowerCAmelCase__     :   int     		=	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__    )

  lowerCAmelCase__     :   str     		=	resnets
  lowerCAmelCase__     :   Optional[Any]     		=	attentions

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


 def __call__(    self  : Union[str, Any]			,							a__  : Dict			,							a__  : Any			,							a__  : Tuple			,							a__  : str			,							a__  : int=True    ):
  '''simple docstring'''

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

   lowerCAmelCase__     :   Dict     		=	resnet(a__			,							a__			,							deterministic=a__    )
   lowerCAmelCase__     :   Union[str, Any]     		=	attn(a__			,							a__			,							deterministic=a__    )

  if self.add_upsample:
   lowerCAmelCase__     :   List[str]     		=	self.upsamplers_a(a__    )

  return hidden_states




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


 def    _A	(    self  : Optional[Any]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   Tuple     		=	[]

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

   lowerCAmelCase__     :   Optional[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__    )

  lowerCAmelCase__     :   str     		=	resnets

  if self.add_upsample:
   lowerCAmelCase__     :   Union[str, Any]     		=	FlaxUpsampleaD(self.out_channels			,							dtype=self.dtype    )


 def __call__(    self  : Any			,							a__  : Union[str, Any]			,							a__  : Optional[int]			,							a__  : List[str]			,							a__  : Optional[Any]=True    ):
  '''simple docstring'''

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

   lowerCAmelCase__     :   Any     		=	resnet(a__			,							a__			,							deterministic=a__    )

  if self.add_upsample:
   lowerCAmelCase__     :   Optional[Any]     		=	self.upsamplers_a(a__    )

  return hidden_states




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


 def    _A	(    self  : int    ):
  '''simple docstring'''

  lowerCAmelCase__     :   Optional[int]     		=	[
      FlaxResnetBlockaD(
          in_channels=self.in_channels			,							out_channels=self.in_channels			,							dropout_prob=self.dropout			,							dtype=self.dtype			,							)
  ]

  lowerCAmelCase__     :   Dict     		=	[]

  for _ in range(self.num_layers    ):
   lowerCAmelCase__     :   List[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__    )

   lowerCAmelCase__     :   Tuple     		=	FlaxResnetBlockaD(
       in_channels=self.in_channels			,							out_channels=self.in_channels			,							dropout_prob=self.dropout			,							dtype=self.dtype			,							)
   resnets.append(a__    )

  lowerCAmelCase__     :   Any     		=	resnets
  lowerCAmelCase__     :   int     		=	attentions


 def __call__(    self  : List[str]			,							a__  : Dict			,							a__  : Optional[Any]			,							a__  : Dict			,							a__  : Dict=True    ):
  '''simple docstring'''

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

  return hidden_states







'''simple docstring'''

import os


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_doctest_list.py
snake_case									=    """."""


if __name__ == "__main__":
     snake_case									=    os.path.join(REPO_PATH, """utils/documentation_tests.txt""")
     snake_case									=    []
     snake_case									=    []
     with open(doctest_file_path) as fp:
          for line in fp:
               snake_case									=    line.strip()
               snake_case									=    os.path.join(REPO_PATH, line)
               if not (os.path.isfile(path) or os.path.isdir(path)):
                    non_existent_paths.append(line)
               all_paths.append(path)
     if len(non_existent_paths) > 0:
          snake_case									=    """\n""".join(non_existent_paths)
          raise ValueError(f'`utils/documentation_tests.txt` contains non-existent paths:\n{non_existent_paths}')
     if all_paths != sorted(all_paths):
          raise ValueError("""Files in `utils/documentation_tests.txt` are not in alphabetical order.""")





