
"""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 				lowercase__(				nn.Module   ):
	'''simple docstring'''

	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    :Optional[Any]					)							->			List[Any]:







			'''simple docstring'''




			SCREAMING_SNAKE_CASE       :     Optional[int]				= []
			SCREAMING_SNAKE_CASE       :     Optional[int]				= []

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

					SCREAMING_SNAKE_CASE       :     List[Any]				= FlaxResnetBlockaD(
					    in_channels=lowerCamelCase_		, out_channels=self.out_channels		, dropout_prob=self.dropout		, dtype=self.dtype		, )
					resnets.append(lowerCamelCase_					)

					SCREAMING_SNAKE_CASE       :     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       :     List[Any]				= resnets
			SCREAMING_SNAKE_CASE       :     List[str]				= attentions

			if self.add_downsample:
					SCREAMING_SNAKE_CASE       :     Union[str, Any]				= FlaxDownsampleaD(self.out_channels		, dtype=self.dtype					)







	def __call__(						self    :int		, lowerCamelCase_    :Tuple		, lowerCamelCase_    :Optional[int]		, lowerCamelCase_    :Tuple		, lowerCamelCase_    :Tuple=True					)							->			Union[str, Any]:







			'''simple docstring'''




			SCREAMING_SNAKE_CASE       :     int				= ()

			for resnet, attn in zip(self.resnets		, self.attentions					):
					SCREAMING_SNAKE_CASE       :     int				= resnet(lowerCamelCase_		, lowerCamelCase_		, deterministic=lowerCamelCase_					)
					SCREAMING_SNAKE_CASE       :     str				= attn(lowerCamelCase_		, lowerCamelCase_		, deterministic=lowerCamelCase_					)
					output_states += (hidden_states,)

			if self.add_downsample:
					SCREAMING_SNAKE_CASE       :     Union[str, Any]				= self.downsamplers_a(lowerCamelCase_					)
					output_states += (hidden_states,)

			return hidden_states, output_states





class 				lowercase__(				nn.Module   ):
	'''simple docstring'''

	UpperCamelCase				=  42
	UpperCamelCase				=  42
	UpperCamelCase				=  0.0
	UpperCamelCase				=  1
	UpperCamelCase				=  True
	UpperCamelCase				=  jnp.floataa





	def   __lowerCAmelCase (						self    :List[Any]					)							->			Dict:







			'''simple docstring'''




			SCREAMING_SNAKE_CASE       :     str				= []

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

					SCREAMING_SNAKE_CASE       :     Optional[int]				= FlaxResnetBlockaD(
					    in_channels=lowerCamelCase_		, out_channels=self.out_channels		, dropout_prob=self.dropout		, dtype=self.dtype		, )
					resnets.append(lowerCamelCase_					)
			SCREAMING_SNAKE_CASE       :     str				= resnets

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







	def __call__(						self    :Optional[Any]		, lowerCamelCase_    :Union[str, Any]		, lowerCamelCase_    :Tuple		, lowerCamelCase_    :List[str]=True					)							->			List[str]:







			'''simple docstring'''




			SCREAMING_SNAKE_CASE       :     Optional[int]				= ()

			for resnet in self.resnets:
					SCREAMING_SNAKE_CASE       :     int				= resnet(lowerCamelCase_		, lowerCamelCase_		, deterministic=lowerCamelCase_					)
					output_states += (hidden_states,)

			if self.add_downsample:
					SCREAMING_SNAKE_CASE       :     Optional[int]				= self.downsamplers_a(lowerCamelCase_					)
					output_states += (hidden_states,)

			return hidden_states, output_states





class 				lowercase__(				nn.Module   ):
	'''simple docstring'''

	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    :Any					)							->			List[Any]:







			'''simple docstring'''




			SCREAMING_SNAKE_CASE       :     int				= []
			SCREAMING_SNAKE_CASE       :     List[Any]				= []

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

					SCREAMING_SNAKE_CASE       :     Tuple				= 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]				= 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       :     str				= resnets
			SCREAMING_SNAKE_CASE       :     Tuple				= attentions

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







	def __call__(						self    :List[Any]		, lowerCamelCase_    :Optional[int]		, lowerCamelCase_    :Dict		, lowerCamelCase_    :List[Any]		, lowerCamelCase_    :Tuple		, lowerCamelCase_    :Dict=True					)							->			Union[str, Any]:







			'''simple docstring'''




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

					SCREAMING_SNAKE_CASE       :     Optional[Any]				= resnet(lowerCamelCase_		, lowerCamelCase_		, deterministic=lowerCamelCase_					)
					SCREAMING_SNAKE_CASE       :     List[str]				= attn(lowerCamelCase_		, lowerCamelCase_		, deterministic=lowerCamelCase_					)

			if self.add_upsample:
					SCREAMING_SNAKE_CASE       :     Optional[int]				= self.upsamplers_a(lowerCamelCase_					)

			return hidden_states





class 				lowercase__(				nn.Module   ):
	'''simple docstring'''

	UpperCamelCase				=  42
	UpperCamelCase				=  42
	UpperCamelCase				=  42
	UpperCamelCase				=  0.0
	UpperCamelCase				=  1
	UpperCamelCase				=  True
	UpperCamelCase				=  jnp.floataa





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







			'''simple docstring'''




			SCREAMING_SNAKE_CASE       :     Any				= []

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

					SCREAMING_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(lowerCamelCase_					)

			SCREAMING_SNAKE_CASE       :     Union[str, Any]				= resnets

			if self.add_upsample:
					SCREAMING_SNAKE_CASE       :     Optional[Any]				= FlaxUpsampleaD(self.out_channels		, dtype=self.dtype					)







	def __call__(						self    :List[Any]		, lowerCamelCase_    :List[Any]		, lowerCamelCase_    :int		, lowerCamelCase_    :List[Any]		, lowerCamelCase_    :int=True					)							->			Dict:







			'''simple docstring'''




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

					SCREAMING_SNAKE_CASE       :     str				= resnet(lowerCamelCase_		, lowerCamelCase_		, deterministic=lowerCamelCase_					)

			if self.add_upsample:
					SCREAMING_SNAKE_CASE       :     Union[str, Any]				= self.upsamplers_a(lowerCamelCase_					)

			return hidden_states





class 				lowercase__(				nn.Module   ):
	'''simple docstring'''

	UpperCamelCase				=  42
	UpperCamelCase				=  0.0
	UpperCamelCase				=  1
	UpperCamelCase				=  1
	UpperCamelCase				=  False
	UpperCamelCase				=  False
	UpperCamelCase				=  jnp.floataa





	def   __lowerCAmelCase (						self    :Optional[Any]					)							->			Optional[int]:







			'''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       :     int				= []

			for _ in range(self.num_layers					):
					SCREAMING_SNAKE_CASE       :     Tuple				= 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       :     Optional[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       :     Optional[Any]				= resnets
			SCREAMING_SNAKE_CASE       :     Any				= attentions







	def __call__(						self    :Optional[Any]		, lowerCamelCase_    :Union[str, Any]		, lowerCamelCase_    :Any		, lowerCamelCase_    :Optional[Any]		, lowerCamelCase_    :Any=True					)							->			Optional[Any]:







			'''simple docstring'''




			SCREAMING_SNAKE_CASE       :     int				= 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       :     Optional[int]				= resnet(lowerCamelCase_		, lowerCamelCase_		, deterministic=lowerCamelCase_					)

			return hidden_states







"""simple docstring"""






import os
import sys

lowerCamelCase__ :       List[Any]						     =			os.path.join(os.path.dirname(__file__), "src")
sys.path.append(SRC_DIR)


from transformers import (
    AutoConfig,
    AutoModel,
    AutoModelForCausalLM,
    AutoModelForMaskedLM,
    AutoModelForQuestionAnswering,
    AutoModelForSequenceClassification,
    AutoTokenizer,
    add_start_docstrings,
)


lowerCamelCase__ :       str						     =			[
    "torch",
    "numpy",
    "tokenizers",
    "filelock",
    "requests",
    "tqdm",
    "regex",
    "sentencepiece",
    "sacremoses",
    "importlib_metadata",
    "huggingface_hub",
]





@add_start_docstrings(AutoConfig.__doc__     )
def __A						(   *a_ :							Any		,		**a_ :							Union[str, Any]     )->							Dict:




		'''simple docstring'''






		return AutoConfig.from_pretrained(*a_		,		**a_     )





@add_start_docstrings(AutoTokenizer.__doc__     )
def __A						(   *a_ :							str		,		**a_ :							Union[str, Any]     )->							Union[str, Any]:




		'''simple docstring'''






		return AutoTokenizer.from_pretrained(*a_		,		**a_     )





@add_start_docstrings(AutoModel.__doc__     )
def __A						(   *a_ :							List[str]		,		**a_ :							int     )->							Dict:




		'''simple docstring'''






		return AutoModel.from_pretrained(*a_		,		**a_     )





@add_start_docstrings(AutoModelForCausalLM.__doc__     )
def __A						(   *a_ :							Any		,		**a_ :							Tuple     )->							Dict:




		'''simple docstring'''






		return AutoModelForCausalLM.from_pretrained(*a_		,		**a_     )





@add_start_docstrings(AutoModelForMaskedLM.__doc__     )
def __A						(   *a_ :							Dict		,		**a_ :							Optional[Any]     )->							Optional[int]:




		'''simple docstring'''






		return AutoModelForMaskedLM.from_pretrained(*a_		,		**a_     )





@add_start_docstrings(AutoModelForSequenceClassification.__doc__     )
def __A						(   *a_ :							Optional[int]		,		**a_ :							str     )->							Optional[int]:




		'''simple docstring'''






		return AutoModelForSequenceClassification.from_pretrained(*a_		,		**a_     )





@add_start_docstrings(AutoModelForQuestionAnswering.__doc__     )
def __A						(   *a_ :							List[str]		,		**a_ :							int     )->							List[Any]:




		'''simple docstring'''






		return AutoModelForQuestionAnswering.from_pretrained(*a_		,		**a_     )





