



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


			'''simple docstring'''

			_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 UpperCamelCase__					(							self     : Union[str, Any]						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Tuple           =		[]
					__SCREAMING_SNAKE_CASE       :		Dict           =		[]

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

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

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

					__SCREAMING_SNAKE_CASE       :		Tuple           =		resnets
					__SCREAMING_SNAKE_CASE       :		Dict           =		attentions

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



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





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		()

					for resnet, attn in zip(self.resnets							,     self.attentions						):
							__SCREAMING_SNAKE_CASE       :		Optional[int]           =		resnet(lowerCAmelCase__							,     lowerCAmelCase__							,     deterministic=lowerCAmelCase__						)
							__SCREAMING_SNAKE_CASE       :		List[str]           =		attn(lowerCAmelCase__							,     lowerCAmelCase__							,     deterministic=lowerCAmelCase__						)
							output_states += (hidden_states,)

					if self.add_downsample:
							__SCREAMING_SNAKE_CASE       :		str           =		self.downsamplers_a(lowerCAmelCase__						)
							output_states += (hidden_states,)

					return hidden_states, output_states






class 						_UpperCamelCase  (							nn.Module    ):


			'''simple docstring'''

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

			def UpperCamelCase__					(							self     : List[Any]						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		[]

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

							__SCREAMING_SNAKE_CASE       :		Dict           =		FlaxResnetBlockaD(
							    in_channels=lowerCAmelCase__							,     out_channels=self.out_channels							,     dropout_prob=self.dropout							,     dtype=self.dtype							,     )
							resnets.append(lowerCAmelCase__						)
					__SCREAMING_SNAKE_CASE       :		List[str]           =		resnets

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



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





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		List[Any]           =		()

					for resnet in self.resnets:
							__SCREAMING_SNAKE_CASE       :		Any           =		resnet(lowerCAmelCase__							,     lowerCAmelCase__							,     deterministic=lowerCAmelCase__						)
							output_states += (hidden_states,)

					if self.add_downsample:
							__SCREAMING_SNAKE_CASE       :		Tuple           =		self.downsamplers_a(lowerCAmelCase__						)
							output_states += (hidden_states,)

					return hidden_states, output_states






class 						_UpperCamelCase  (							nn.Module    ):


			'''simple docstring'''

			_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 UpperCamelCase__					(							self     : Any						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		List[str]           =		[]
					__SCREAMING_SNAKE_CASE       :		str           =		[]

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

							__SCREAMING_SNAKE_CASE       :		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(lowerCAmelCase__						)

							__SCREAMING_SNAKE_CASE       :		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(lowerCAmelCase__						)

					__SCREAMING_SNAKE_CASE       :		int           =		resnets
					__SCREAMING_SNAKE_CASE       :		Dict           =		attentions

					if self.add_upsample:
							__SCREAMING_SNAKE_CASE       :		Optional[int]           =		FlaxUpsampleaD(self.out_channels							,     dtype=self.dtype						)



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





					"""simple docstring"""






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

							__SCREAMING_SNAKE_CASE       :		str           =		resnet(lowerCAmelCase__							,     lowerCAmelCase__							,     deterministic=lowerCAmelCase__						)
							__SCREAMING_SNAKE_CASE       :		Dict           =		attn(lowerCAmelCase__							,     lowerCAmelCase__							,     deterministic=lowerCAmelCase__						)

					if self.add_upsample:
							__SCREAMING_SNAKE_CASE       :		str           =		self.upsamplers_a(lowerCAmelCase__						)

					return hidden_states






class 						_UpperCamelCase  (							nn.Module    ):


			'''simple docstring'''

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

			def UpperCamelCase__					(							self     : Tuple						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		[]

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

							__SCREAMING_SNAKE_CASE       :		List[str]           =		FlaxResnetBlockaD(
							    in_channels=resnet_in_channels + res_skip_channels							,     out_channels=self.out_channels							,     dropout_prob=self.dropout							,     dtype=self.dtype							,     )
							resnets.append(lowerCAmelCase__						)

					__SCREAMING_SNAKE_CASE       :		List[str]           =		resnets

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



			def __call__(							self     : Optional[Any]							,     lowerCAmelCase__     : Any							,     lowerCAmelCase__     : Tuple							,     lowerCAmelCase__     : Tuple							,     lowerCAmelCase__     : Union[str, Any]=True						):





					"""simple docstring"""






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

							__SCREAMING_SNAKE_CASE       :		Optional[int]           =		resnet(lowerCAmelCase__							,     lowerCAmelCase__							,     deterministic=lowerCAmelCase__						)

					if self.add_upsample:
							__SCREAMING_SNAKE_CASE       :		Dict           =		self.upsamplers_a(lowerCAmelCase__						)

					return hidden_states






class 						_UpperCamelCase  (							nn.Module    ):


			'''simple docstring'''

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

			def UpperCamelCase__					(							self     : Optional[Any]						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Any           =		[
					    FlaxResnetBlockaD(
					        in_channels=self.in_channels							,     out_channels=self.in_channels							,     dropout_prob=self.dropout							,     dtype=self.dtype							,     )
					]

					__SCREAMING_SNAKE_CASE       :		Dict           =		[]

					for _ in range(self.num_layers						):
							__SCREAMING_SNAKE_CASE       :		Any           =		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(lowerCAmelCase__						)

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

					__SCREAMING_SNAKE_CASE       :		List[Any]           =		resnets
					__SCREAMING_SNAKE_CASE       :		List[Any]           =		attentions



			def __call__(							self     : str							,     lowerCAmelCase__     : int							,     lowerCAmelCase__     : List[str]							,     lowerCAmelCase__     : List[str]							,     lowerCAmelCase__     : int=True						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Dict           =		self.resnets[0](lowerCAmelCase__							,     lowerCAmelCase__						)
					for attn, resnet in zip(self.attentions							,     self.resnets[1:]						):
							__SCREAMING_SNAKE_CASE       :		str           =		attn(lowerCAmelCase__							,     lowerCAmelCase__							,     deterministic=lowerCAmelCase__						)
							__SCREAMING_SNAKE_CASE       :		str           =		resnet(lowerCAmelCase__							,     lowerCAmelCase__							,     deterministic=lowerCAmelCase__						)

					return hidden_states




'''simple docstring'''




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__       :	Dict    = [
    '''python''',
    '''tqdm''',
    '''regex''',
    '''requests''',
    '''packaging''',
    '''filelock''',
    '''numpy''',
    '''tokenizers''',
    '''huggingface-hub''',
    '''safetensors''',
    '''accelerate''',
    '''pyyaml''',
]

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
												elif pkg == "accelerate":
																		# must be loaded here, or else tqdm check may fail
																		from .utils import is_accelerate_available

																		# Maybe switch to is_torch_available in the future here so that Accelerate is hard dep of
																		# Transformers with PyTorch
																		if not is_accelerate_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 				lowerCAmelCase_   (	_lowerCamelCase:   List[Any]       ,      _lowerCamelCase:   Optional[int]=None					):
		require_version(deps[pkg]       ,      _lowerCamelCase					)