






"""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			):
					UpperCAmelCase__								=				42
					UpperCAmelCase__								=				42
					UpperCAmelCase__								=				0.0
					UpperCAmelCase__								=				1
					UpperCAmelCase__								=				1
					UpperCAmelCase__								=				True
					UpperCAmelCase__								=				False
					UpperCAmelCase__								=				False
					UpperCAmelCase__								=				False
					UpperCAmelCase__								=				jnp.floataa

					def   lowerCamelCase__   (			self  :      str					)			->							int:
											__magic_name__:	str							=       []
											__magic_name__:	Any							=       []

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

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

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

											__magic_name__:	Any							=       resnets
											__magic_name__:	str							=       attentions

											if self.add_downsample:
																	__magic_name__:	List[str]							=       FlaxDownsampleaD(self.out_channels     ,		dtype=self.dtype					)






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

											for resnet, attn in zip(self.resnets     ,		self.attentions					):
																	__magic_name__:	Optional[Any]							=       resnet(__snake_case     ,		__snake_case     ,		deterministic=__snake_case					)
																	__magic_name__:	Union[str, Any]							=       attn(__snake_case     ,		__snake_case     ,		deterministic=__snake_case					)
																	output_states += (hidden_states,)

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

											return hidden_states, output_states



class       __A		(   nn.Module			):
					UpperCAmelCase__								=				42
					UpperCAmelCase__								=				42
					UpperCAmelCase__								=				0.0
					UpperCAmelCase__								=				1
					UpperCAmelCase__								=				True
					UpperCAmelCase__								=				jnp.floataa

					def   lowerCamelCase__   (			self  :      str					)			->							Optional[int]:
											__magic_name__:	Optional[Any]							=       []

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

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

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






					def __call__(			self  :      str     ,		__snake_case  :      int     ,		__snake_case  :      List[str]     ,		__snake_case  :      List[Any]=True					)			->							Dict:
											__magic_name__:	Optional[Any]							=       ()

											for resnet in self.resnets:
																	__magic_name__:	Optional[int]							=       resnet(__snake_case     ,		__snake_case     ,		deterministic=__snake_case					)
																	output_states += (hidden_states,)

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

											return hidden_states, output_states



class       __A		(   nn.Module			):
					UpperCAmelCase__								=				42
					UpperCAmelCase__								=				42
					UpperCAmelCase__								=				42
					UpperCAmelCase__								=				0.0
					UpperCAmelCase__								=				1
					UpperCAmelCase__								=				1
					UpperCAmelCase__								=				True
					UpperCAmelCase__								=				False
					UpperCAmelCase__								=				False
					UpperCAmelCase__								=				False
					UpperCAmelCase__								=				jnp.floataa

					def   lowerCamelCase__   (			self  :      int					)			->							int:
											__magic_name__:	Optional[int]							=       []
											__magic_name__:	Any							=       []

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

																	__magic_name__:	Dict							=       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					)

																	__magic_name__:	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(__snake_case					)

											__magic_name__:	List[str]							=       resnets
											__magic_name__:	List[str]							=       attentions

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






					def __call__(			self  :      Tuple     ,		__snake_case  :      int     ,		__snake_case  :      List[Any]     ,		__snake_case  :      Dict     ,		__snake_case  :      List[str]     ,		__snake_case  :      Dict=True					)			->							List[Any]:
											for resnet, attn in zip(self.resnets     ,		self.attentions					):
																	# pop res hidden states
																	__magic_name__:	Any							=       res_hidden_states_tuple[-1]
																	__magic_name__:	Optional[int]							=       res_hidden_states_tuple[:-1]
																	__magic_name__:	Optional[Any]							=       jnp.concatenate((hidden_states, res_hidden_states)     ,		axis=-1					)

																	__magic_name__:	Optional[Any]							=       resnet(__snake_case     ,		__snake_case     ,		deterministic=__snake_case					)
																	__magic_name__:	str							=       attn(__snake_case     ,		__snake_case     ,		deterministic=__snake_case					)

											if self.add_upsample:
																	__magic_name__:	Optional[Any]							=       self.upsamplers_a(__snake_case					)

											return hidden_states



class       __A		(   nn.Module			):
					UpperCAmelCase__								=				42
					UpperCAmelCase__								=				42
					UpperCAmelCase__								=				42
					UpperCAmelCase__								=				0.0
					UpperCAmelCase__								=				1
					UpperCAmelCase__								=				True
					UpperCAmelCase__								=				jnp.floataa

					def   lowerCamelCase__   (			self  :      int					)			->							Union[str, Any]:
											__magic_name__:	Any							=       []

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

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

											__magic_name__:	Any							=       resnets

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






					def __call__(			self  :      List[str]     ,		__snake_case  :      Any     ,		__snake_case  :      Tuple     ,		__snake_case  :      str     ,		__snake_case  :      Optional[int]=True					)			->							int:
											for resnet in self.resnets:
																	# pop res hidden states
																	__magic_name__:	List[Any]							=       res_hidden_states_tuple[-1]
																	__magic_name__:	Dict							=       res_hidden_states_tuple[:-1]
																	__magic_name__:	Dict							=       jnp.concatenate((hidden_states, res_hidden_states)     ,		axis=-1					)

																	__magic_name__:	Optional[int]							=       resnet(__snake_case     ,		__snake_case     ,		deterministic=__snake_case					)

											if self.add_upsample:
																	__magic_name__:	Optional[Any]							=       self.upsamplers_a(__snake_case					)

											return hidden_states



class       __A		(   nn.Module			):
					UpperCAmelCase__								=				42
					UpperCAmelCase__								=				0.0
					UpperCAmelCase__								=				1
					UpperCAmelCase__								=				1
					UpperCAmelCase__								=				False
					UpperCAmelCase__								=				False
					UpperCAmelCase__								=				jnp.floataa

					def   lowerCamelCase__   (			self  :      Dict					)			->							Dict:
											# there is always at least one resnet
											__magic_name__:	Tuple							=       [
											    FlaxResnetBlockaD(
											        in_channels=self.in_channels     ,		out_channels=self.in_channels     ,		dropout_prob=self.dropout     ,		dtype=self.dtype     ,		)
											]

											__magic_name__:	str							=       []

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

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

											__magic_name__:	Optional[Any]							=       resnets
											__magic_name__:	int							=       attentions






					def __call__(			self  :      str     ,		__snake_case  :      Tuple     ,		__snake_case  :      Tuple     ,		__snake_case  :      List[Any]     ,		__snake_case  :      Optional[Any]=True					)			->							int:
											__magic_name__:	Optional[Any]							=       self.resnets[0](__snake_case     ,		__snake_case					)
											for attn, resnet in zip(self.attentions     ,		self.resnets[1:]					):
																	__magic_name__:	Optional[Any]							=       attn(__snake_case     ,		__snake_case     ,		deterministic=__snake_case					)
																	__magic_name__:	str							=       resnet(__snake_case     ,		__snake_case     ,		deterministic=__snake_case					)

											return hidden_states










from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase__           =			logging.get_logger(__name__)

UpperCamelCase__           =			{
    "tanreinama/GPTSAN-2.8B-spout_is_uniform": (
        "https://huggingface.co/tanreinama/GPTSAN-2.8B-spout_is_uniform/resolve/main/config.json"
    ),
}

class 							__SCREAMING_SNAKE_CASE       (  _a							):
							snake_case  :   Optional[Any]      =							"""gptsan-japanese"""
							snake_case  :   Any      =							[
							    """past_key_values""",
							]
							snake_case  :   str      =							{
							    """hidden_size""": """d_model""",
							    """num_attention_heads""": """num_heads""",
							    """num_hidden_layers""": """num_layers""",
							}






							def __init__(    self	,			__lowerCAmelCase=36000	,			__lowerCAmelCase=1280	,			__lowerCAmelCase=1024	,			__lowerCAmelCase=8192	,			__lowerCAmelCase=4096	,			__lowerCAmelCase=128	,			__lowerCAmelCase=10	,			__lowerCAmelCase=0	,			__lowerCAmelCase=16	,			__lowerCAmelCase=16	,			__lowerCAmelCase=128	,			__lowerCAmelCase=0.0	,			__lowerCAmelCase=1E-5	,			__lowerCAmelCase=False	,			__lowerCAmelCase=0.0	,			__lowerCAmelCase="float32"	,			__lowerCAmelCase=False	,			__lowerCAmelCase=False	,			__lowerCAmelCase=False	,			__lowerCAmelCase=0.002	,			__lowerCAmelCase=False	,			__lowerCAmelCase=True	,			__lowerCAmelCase=35998	,			__lowerCAmelCase=35995	,			__lowerCAmelCase=35999	,			**__lowerCAmelCase	,			):
														UpperCamelCase__					  =      vocab_size
														UpperCamelCase__					  =      max_position_embeddings
														UpperCamelCase__					  =      d_model
														UpperCamelCase__					  =      d_ff
														UpperCamelCase__					  =      d_ext
														UpperCamelCase__					  =      d_spout
														UpperCamelCase__					  =      num_switch_layers
														UpperCamelCase__					  =      num_ext_layers
														UpperCamelCase__					  =      num_switch_layers + num_ext_layers
														UpperCamelCase__					  =      num_heads
														UpperCamelCase__					  =      num_experts
														UpperCamelCase__					  =      expert_capacity
														UpperCamelCase__					  =      dropout_rate
														UpperCamelCase__					  =      layer_norm_epsilon
														UpperCamelCase__					  =      router_bias
														UpperCamelCase__					  =      router_jitter_noise
														UpperCamelCase__					  =      router_dtype
														UpperCamelCase__					  =      router_ignore_padding_tokens
														UpperCamelCase__					  =      output_hidden_states
														UpperCamelCase__					  =      output_attentions
														UpperCamelCase__					  =      initializer_factor
														UpperCamelCase__					  =      output_router_logits
														UpperCamelCase__					  =      use_cache

														super().__init__(
														    separator_token_id=__lowerCAmelCase	,			pad_token_id=__lowerCAmelCase	,			eos_token_id=__lowerCAmelCase	,			**__lowerCAmelCase	,			)




