




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







		def        lowercase       (    self				)      ->      Tuple:


							'''simple docstring'''

							_snake_case       :					Any				       =   []
							_snake_case       :					str				       =   []

							for i in range(self.num_layers				):
												_snake_case       :					Optional[Any]				       =   self.in_channels if i == 0 else self.out_channels

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

												_snake_case       :					Dict				       =   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(__snake_case				)

							_snake_case       :					Tuple				       =   resnets
							_snake_case       :					Dict				       =   attentions

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







		def __call__(    self ,						__snake_case ,						__snake_case ,						__snake_case ,						__snake_case=True				)      ->      Any:


							'''simple docstring'''

							_snake_case       :					Optional[Any]				       =   ()

							for resnet, attn in zip(self.resnets ,						self.attentions				):
												_snake_case       :					List[Any]				       =   resnet(__snake_case ,						__snake_case ,						deterministic=__snake_case				)
												_snake_case       :					Optional[int]				       =   attn(__snake_case ,						__snake_case ,						deterministic=__snake_case				)
												output_states += (hidden_states,)

							if self.add_downsample:
												_snake_case       :					Any				       =   self.downsamplers_a(__snake_case				)
												output_states += (hidden_states,)

							return hidden_states, output_states






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







		def        lowercase       (    self				)      ->      Optional[int]:


							'''simple docstring'''

							_snake_case       :					Any				       =   []

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

												_snake_case       :					Optional[int]				       =   FlaxResnetBlockaD(
												    in_channels=__snake_case ,						out_channels=self.out_channels ,						dropout_prob=self.dropout ,						dtype=self.dtype ,						)
												resnets.append(__snake_case				)
							_snake_case       :					Optional[Any]				       =   resnets

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







		def __call__(    self ,						__snake_case ,						__snake_case ,						__snake_case=True				)      ->      str:


							'''simple docstring'''

							_snake_case       :					Union[str, Any]				       =   ()

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

							if self.add_downsample:
												_snake_case       :					int				       =   self.downsamplers_a(__snake_case				)
												output_states += (hidden_states,)

							return hidden_states, output_states






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







		def        lowercase       (    self				)      ->      int:


							'''simple docstring'''

							_snake_case       :					Optional[Any]				       =   []
							_snake_case       :					List[str]				       =   []

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

												_snake_case       :					List[Any]				       =   FlaxResnetBlockaD(
												    in_channels=resnet_in_channels + res_skip_channels ,						out_channels=self.out_channels ,						dropout_prob=self.dropout ,						dtype=self.dtype ,						)
												resnets.append(__snake_case				)

												_snake_case       :					List[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(__snake_case				)

							_snake_case       :					Union[str, Any]				       =   resnets
							_snake_case       :					List[str]				       =   attentions

							if self.add_upsample:
												_snake_case       :					List[str]				       =   FlaxUpsampleaD(self.out_channels ,						dtype=self.dtype				)







		def __call__(    self ,						__snake_case ,						__snake_case ,						__snake_case ,						__snake_case ,						__snake_case=True				)      ->      Optional[int]:


							'''simple docstring'''

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

												_snake_case       :					str				       =   resnet(__snake_case ,						__snake_case ,						deterministic=__snake_case				)
												_snake_case       :					List[str]				       =   attn(__snake_case ,						__snake_case ,						deterministic=__snake_case				)

							if self.add_upsample:
												_snake_case       :					Dict				       =   self.upsamplers_a(__snake_case				)

							return hidden_states






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







		def        lowercase       (    self				)      ->      Union[str, Any]:


							'''simple docstring'''

							_snake_case       :					Tuple				       =   []

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

												_snake_case       :					str				       =   FlaxResnetBlockaD(
												    in_channels=resnet_in_channels + res_skip_channels ,						out_channels=self.out_channels ,						dropout_prob=self.dropout ,						dtype=self.dtype ,						)
												resnets.append(__snake_case				)

							_snake_case       :					Optional[Any]				       =   resnets

							if self.add_upsample:
												_snake_case       :					List[str]				       =   FlaxUpsampleaD(self.out_channels ,						dtype=self.dtype				)







		def __call__(    self ,						__snake_case ,						__snake_case ,						__snake_case ,						__snake_case=True				)      ->      Tuple:


							'''simple docstring'''

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

												_snake_case       :					List[str]				       =   resnet(__snake_case ,						__snake_case ,						deterministic=__snake_case				)

							if self.add_upsample:
												_snake_case       :					int				       =   self.upsamplers_a(__snake_case				)

							return hidden_states






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







		def        lowercase       (    self				)      ->      List[str]:


							'''simple docstring'''

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

							_snake_case       :					List[Any]				       =   []

							for _ in range(self.num_layers				):
												_snake_case       :					int				       =   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(__snake_case				)

												_snake_case       :					Any				       =   FlaxResnetBlockaD(
												    in_channels=self.in_channels ,						out_channels=self.in_channels ,						dropout_prob=self.dropout ,						dtype=self.dtype ,						)
												resnets.append(__snake_case				)

							_snake_case       :					str				       =   resnets
							_snake_case       :					Tuple				       =   attentions







		def __call__(    self ,						__snake_case ,						__snake_case ,						__snake_case ,						__snake_case=True				)      ->      List[Any]:


							'''simple docstring'''

							_snake_case       :					Optional[Any]				       =   self.resnets[0](__snake_case ,						__snake_case				)
							for attn, resnet in zip(self.attentions ,						self.resnets[1:]				):
												_snake_case       :					Any				       =   attn(__snake_case ,						__snake_case ,						deterministic=__snake_case				)
												_snake_case       :					Tuple				       =   resnet(__snake_case ,						__snake_case ,						deterministic=__snake_case				)

							return hidden_states






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__lowerCAmelCase :str     =    {
    'configuration_nllb_moe': [
        'NLLB_MOE_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'NllbMoeConfig',
    ]
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__lowerCAmelCase :Optional[int]     =    [
							    'NLLB_MOE_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'NllbMoeForConditionalGeneration',
							    'NllbMoeModel',
							    'NllbMoePreTrainedModel',
							    'NllbMoeTop2Router',
							    'NllbMoeSparseMLP',
							]


if TYPE_CHECKING:
							from .configuration_nllb_moe import (
							    NLLB_MOE_PRETRAINED_CONFIG_ARCHIVE_MAP,
							    NllbMoeConfig,
							)

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_nllb_moe import (
														    NLLB_MOE_PRETRAINED_MODEL_ARCHIVE_LIST,
														    NllbMoeForConditionalGeneration,
														    NllbMoeModel,
														    NllbMoePreTrainedModel,
														    NllbMoeSparseMLP,
														    NllbMoeTopaRouter,
														)


else:
							import sys

							__lowerCAmelCase :int     =    _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)