



'''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       a__				( nn.Module      ):







				"""simple docstring"""



				__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 					_snake_case  (self		):
										__lowerCAmelCase							       =				[]
										__lowerCAmelCase							       =				[]

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

																__lowerCAmelCase							       =				FlaxResnetBlockaD(
																    in_channels=A_       ,			out_channels=self.out_channels       ,			dropout_prob=self.dropout       ,			dtype=self.dtype       ,			)
																resnets.append(A_		)

																__lowerCAmelCase							       =				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							       =				resnets
										__lowerCAmelCase							       =				attentions

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




				def __call__(self       ,			__lowercase       ,			__lowercase       ,			__lowercase       ,			__lowercase=True		):
										__lowerCAmelCase							       =				()

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

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

										return hidden_states, output_states


class       a__				( nn.Module      ):







				"""simple docstring"""



				__UpperCamelCase    :		int
				__UpperCamelCase    :		int
				__UpperCamelCase    :		float	=	0.0
				__UpperCamelCase    :		int	=	1
				__UpperCamelCase    :		bool	=	True
				__UpperCamelCase    :		jnp.dtype	=	jnp.floataa




				def 					_snake_case  (self		):
										__lowerCAmelCase							       =				[]

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

																__lowerCAmelCase							       =				FlaxResnetBlockaD(
																    in_channels=A_       ,			out_channels=self.out_channels       ,			dropout_prob=self.dropout       ,			dtype=self.dtype       ,			)
																resnets.append(A_		)
										__lowerCAmelCase							       =				resnets

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




				def __call__(self       ,			__lowercase       ,			__lowercase       ,			__lowercase=True		):
										__lowerCAmelCase							       =				()

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

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

										return hidden_states, output_states


class       a__				( nn.Module      ):







				"""simple docstring"""



				__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 					_snake_case  (self		):
										__lowerCAmelCase							       =				[]
										__lowerCAmelCase							       =				[]

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

																__lowerCAmelCase							       =				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							       =				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							       =				resnets
										__lowerCAmelCase							       =				attentions

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




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

																__lowerCAmelCase							       =				resnet(A_       ,			A_       ,			deterministic=A_		)
																__lowerCAmelCase							       =				attn(A_       ,			A_       ,			deterministic=A_		)

										if self.add_upsample:
																__lowerCAmelCase							       =				self.upsamplers_a(A_		)

										return hidden_states


class       a__				( nn.Module      ):







				"""simple docstring"""



				__UpperCamelCase    :		int
				__UpperCamelCase    :		int
				__UpperCamelCase    :		int
				__UpperCamelCase    :		float	=	0.0
				__UpperCamelCase    :		int	=	1
				__UpperCamelCase    :		bool	=	True
				__UpperCamelCase    :		jnp.dtype	=	jnp.floataa




				def 					_snake_case  (self		):
										__lowerCAmelCase							       =				[]

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

																__lowerCAmelCase							       =				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							       =				resnets

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




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

																__lowerCAmelCase							       =				resnet(A_       ,			A_       ,			deterministic=A_		)

										if self.add_upsample:
																__lowerCAmelCase							       =				self.upsamplers_a(A_		)

										return hidden_states


class       a__				( nn.Module      ):







				"""simple docstring"""



				__UpperCamelCase    :		int
				__UpperCamelCase    :		float	=	0.0
				__UpperCamelCase    :		int	=	1
				__UpperCamelCase    :		int	=	1
				__UpperCamelCase    :		bool	=	False
				__UpperCamelCase    :		bool	=	False
				__UpperCamelCase    :		jnp.dtype	=	jnp.floataa




				def 					_snake_case  (self		):
										# there is always at least one resnet
										__lowerCAmelCase							       =				[
										    FlaxResnetBlockaD(
										        in_channels=self.in_channels       ,			out_channels=self.in_channels       ,			dropout_prob=self.dropout       ,			dtype=self.dtype       ,			)
										]

										__lowerCAmelCase							       =				[]

										for _ in range(self.num_layers		):
																__lowerCAmelCase							       =				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							       =				FlaxResnetBlockaD(
																    in_channels=self.in_channels       ,			out_channels=self.in_channels       ,			dropout_prob=self.dropout       ,			dtype=self.dtype       ,			)
																resnets.append(A_		)

										__lowerCAmelCase							       =				resnets
										__lowerCAmelCase							       =				attentions




				def __call__(self       ,			__lowercase       ,			__lowercase       ,			__lowercase       ,			__lowercase=True		):
										__lowerCAmelCase							       =				self.resnets[0](A_       ,			A_		)
										for attn, resnet in zip(self.attentions       ,			self.resnets[1:]		):
																__lowerCAmelCase							       =				attn(A_       ,			A_       ,			deterministic=A_		)
																__lowerCAmelCase							       =				resnet(A_       ,			A_       ,			deterministic=A_		)

										return hidden_states





'''simple docstring'''

import sys

from .dependency_versions_table import deps
from .utils.versions import require_version, require_version_core


# define which module versions we always want to check at run time
# (usually the ones defined in `install_requires` in setup.py)
#
# order specific notes:
# - tqdm must be checked before tokenizers

_UpperCAmelCase				: Tuple							    =				"""python tqdm regex requests packaging filelock numpy tokenizers""".split()
if sys.version_info < (3, 7):
	pkgs_to_check_at_runtime.append("""dataclasses""")
if sys.version_info < (3, 8):
	pkgs_to_check_at_runtime.append("""importlib_metadata""")

for pkg in pkgs_to_check_at_runtime:
	if pkg in deps:
		if pkg == "tokenizers":
			# must be loaded here, or else tqdm check may fail
			from .utils import is_tokenizers_available

			if not is_tokenizers_available():
				continue  # not required, check version only if installed

		require_version_core(deps[pkg])
	else:
		raise ValueError(f"""can't find {pkg} in {deps.keys()}, check dependency_versions_table.py""")

def 							__magic_name__(						lowerCamelCase,				lowerCamelCase=None):
						require_version(deps[pkg],				lowerCamelCase)

