


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






			"""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  ):

						'''simple docstring'''


						UpperCamelCase__       =							[]
						UpperCamelCase__       =							[]

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

									UpperCamelCase__       =							FlaxResnetBlockaD(
									    in_channels=snake_case   ,    out_channels=self.out_channels   ,    dropout_prob=self.dropout   ,    dtype=self.dtype   ,    )
									resnets.append(snake_case  )

									UpperCamelCase__       =							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  )

						UpperCamelCase__       =							resnets
						UpperCamelCase__       =							attentions

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







			def __call__(				self   ,    snake_case   ,    snake_case   ,    snake_case   ,    snake_case=True  ):

						'''simple docstring'''


						UpperCamelCase__       =							()

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

						if self.add_downsample:
									UpperCamelCase__       =							self.downsamplers_a(snake_case  )
									output_states += (hidden_states,)

						return hidden_states, output_states







class 							lowerCamelCase__						(				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  ):

						'''simple docstring'''


						UpperCamelCase__       =							[]

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

									UpperCamelCase__       =							FlaxResnetBlockaD(
									    in_channels=snake_case   ,    out_channels=self.out_channels   ,    dropout_prob=self.dropout   ,    dtype=self.dtype   ,    )
									resnets.append(snake_case  )
						UpperCamelCase__       =							resnets

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







			def __call__(				self   ,    snake_case   ,    snake_case   ,    snake_case=True  ):

						'''simple docstring'''


						UpperCamelCase__       =							()

						for resnet in self.resnets:
									UpperCamelCase__       =							resnet(snake_case   ,    snake_case   ,    deterministic=snake_case  )
									output_states += (hidden_states,)

						if self.add_downsample:
									UpperCamelCase__       =							self.downsamplers_a(snake_case  )
									output_states += (hidden_states,)

						return hidden_states, output_states







class 							lowerCamelCase__						(				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  ):

						'''simple docstring'''


						UpperCamelCase__       =							[]
						UpperCamelCase__       =							[]

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

									UpperCamelCase__       =							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  )

									UpperCamelCase__       =							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  )

						UpperCamelCase__       =							resnets
						UpperCamelCase__       =							attentions

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







			def __call__(				self   ,    snake_case   ,    snake_case   ,    snake_case   ,    snake_case   ,    snake_case=True  ):

						'''simple docstring'''


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

									UpperCamelCase__       =							resnet(snake_case   ,    snake_case   ,    deterministic=snake_case  )
									UpperCamelCase__       =							attn(snake_case   ,    snake_case   ,    deterministic=snake_case  )

						if self.add_upsample:
									UpperCamelCase__       =							self.upsamplers_a(snake_case  )

						return hidden_states







class 							lowerCamelCase__						(				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  ):

						'''simple docstring'''


						UpperCamelCase__       =							[]

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

									UpperCamelCase__       =							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  )

						UpperCamelCase__       =							resnets

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







			def __call__(				self   ,    snake_case   ,    snake_case   ,    snake_case   ,    snake_case=True  ):

						'''simple docstring'''


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

									UpperCamelCase__       =							resnet(snake_case   ,    snake_case   ,    deterministic=snake_case  )

						if self.add_upsample:
									UpperCamelCase__       =							self.upsamplers_a(snake_case  )

						return hidden_states







class 							lowerCamelCase__						(				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  ):

						'''simple docstring'''


						UpperCamelCase__       =							[
						    FlaxResnetBlockaD(
						        in_channels=self.in_channels   ,    out_channels=self.in_channels   ,    dropout_prob=self.dropout   ,    dtype=self.dtype   ,    )
						]

						UpperCamelCase__       =							[]

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

									UpperCamelCase__       =							FlaxResnetBlockaD(
									    in_channels=self.in_channels   ,    out_channels=self.in_channels   ,    dropout_prob=self.dropout   ,    dtype=self.dtype   ,    )
									resnets.append(snake_case  )

						UpperCamelCase__       =							resnets
						UpperCamelCase__       =							attentions







			def __call__(				self   ,    snake_case   ,    snake_case   ,    snake_case   ,    snake_case=True  ):

						'''simple docstring'''


						UpperCamelCase__       =							self.resnets[0](snake_case   ,    snake_case  )
						for attn, resnet in zip(self.attentions   ,    self.resnets[1:]  ):
									UpperCamelCase__       =							attn(snake_case   ,    snake_case   ,    deterministic=snake_case  )
									UpperCamelCase__       =							resnet(snake_case   ,    snake_case   ,    deterministic=snake_case  )

						return hidden_states






from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__UpperCamelCase     		=							logging.get_logger(__name__)

__UpperCamelCase     		=							{
    'facebook/xmod-base': 'https://huggingface.co/facebook/xmod-base/resolve/main/config.json',
    'facebook/xmod-large-prenorm': 'https://huggingface.co/facebook/xmod-large-prenorm/resolve/main/config.json',
    'facebook/xmod-base-13-125k': 'https://huggingface.co/facebook/xmod-base-13-125k/resolve/main/config.json',
    'facebook/xmod-base-30-125k': 'https://huggingface.co/facebook/xmod-base-30-125k/resolve/main/config.json',
    'facebook/xmod-base-30-195k': 'https://huggingface.co/facebook/xmod-base-30-195k/resolve/main/config.json',
    'facebook/xmod-base-60-125k': 'https://huggingface.co/facebook/xmod-base-60-125k/resolve/main/config.json',
    'facebook/xmod-base-60-265k': 'https://huggingface.co/facebook/xmod-base-60-265k/resolve/main/config.json',
    'facebook/xmod-base-75-125k': 'https://huggingface.co/facebook/xmod-base-75-125k/resolve/main/config.json',
    'facebook/xmod-base-75-269k': 'https://huggingface.co/facebook/xmod-base-75-269k/resolve/main/config.json',
}







class 							lowerCamelCase__						(				UpperCAmelCase   ):






			"""simple docstring"""






			_UpperCamelCase		:       List[str] 			=		'xmod'




			def __init__(				self   ,    snake_case=30522   ,    snake_case=768   ,    snake_case=12   ,    snake_case=12   ,    snake_case=3072   ,    snake_case="gelu"   ,    snake_case=0.1   ,    snake_case=0.1   ,    snake_case=512   ,    snake_case=2   ,    snake_case=0.02   ,    snake_case=1E-1_2   ,    snake_case=1   ,    snake_case=0   ,    snake_case=2   ,    snake_case="absolute"   ,    snake_case=True   ,    snake_case=None   ,    snake_case=False   ,    snake_case=2   ,    snake_case=False   ,    snake_case=True   ,    snake_case=True   ,    snake_case=("en_XX",)   ,    snake_case=None   ,    **snake_case   ,    ):

						'''simple docstring'''


						super().__init__(pad_token_id=snake_case   ,    bos_token_id=snake_case   ,    eos_token_id=snake_case   ,    **snake_case  )

						UpperCamelCase__       =							vocab_size
						UpperCamelCase__       =							hidden_size
						UpperCamelCase__       =							num_hidden_layers
						UpperCamelCase__       =							num_attention_heads
						UpperCamelCase__       =							hidden_act
						UpperCamelCase__       =							intermediate_size
						UpperCamelCase__       =							hidden_dropout_prob
						UpperCamelCase__       =							attention_probs_dropout_prob
						UpperCamelCase__       =							max_position_embeddings
						UpperCamelCase__       =							type_vocab_size
						UpperCamelCase__       =							initializer_range
						UpperCamelCase__       =							layer_norm_eps
						UpperCamelCase__       =							position_embedding_type
						UpperCamelCase__       =							use_cache
						UpperCamelCase__       =							classifier_dropout
						UpperCamelCase__       =							pre_norm
						UpperCamelCase__       =							adapter_reduction_factor
						UpperCamelCase__       =							adapter_layer_norm
						UpperCamelCase__       =							adapter_reuse_layer_norm
						UpperCamelCase__       =							ln_before_adapter
						UpperCamelCase__       =							list(snake_case  )
						UpperCamelCase__       =							default_language







class 							lowerCamelCase__						(				UpperCAmelCase   ):






			"""simple docstring"""






			@property
			def 					snake_case__					(				self  ):

						'''simple docstring'''


						if self.task == "multiple-choice":
									UpperCamelCase__       =							{0: "batch", 1: "choice", 2: "sequence"}
						else:
									UpperCamelCase__       =							{0: "batch", 1: "sequence"}
						return OrderedDict(
						    [
						        ("input_ids", dynamic_axis),
						        ("attention_mask", dynamic_axis),
						    ]  )


