


"""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 			lowerCamelCase__						(   nn.Module			):
						lowerCAmelCase       =     42
						lowerCAmelCase       =     42
						lowerCAmelCase       =     0.0
						lowerCAmelCase       =     1
						lowerCAmelCase       =     1
						lowerCAmelCase       =     True
						lowerCAmelCase       =     False
						lowerCAmelCase       =     False
						lowerCAmelCase       =     False
						lowerCAmelCase       =     jnp.floataa







						def __a						(							self   :    int		):
								A					       = []
								A					       = []

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

										A					       = FlaxResnetBlockaD(
										    in_channels=UpperCAmelCase__			,			out_channels=self.out_channels			,			dropout_prob=self.dropout			,			dtype=self.dtype			,			)
										resnets.append(UpperCAmelCase__		)

										A					       = 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(UpperCAmelCase__		)

								A					       = resnets
								A					       = attentions

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







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

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

								if self.add_downsample:
										A					       = self.downsamplers_a(UpperCAmelCase__		)
										output_states += (hidden_states,)

								return hidden_states, output_states



class 			lowerCamelCase__						(   nn.Module			):
						lowerCAmelCase       =     42
						lowerCAmelCase       =     42
						lowerCAmelCase       =     0.0
						lowerCAmelCase       =     1
						lowerCAmelCase       =     True
						lowerCAmelCase       =     jnp.floataa







						def __a						(							self   :    Dict		):
								A					       = []

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

										A					       = FlaxResnetBlockaD(
										    in_channels=UpperCAmelCase__			,			out_channels=self.out_channels			,			dropout_prob=self.dropout			,			dtype=self.dtype			,			)
										resnets.append(UpperCAmelCase__		)
								A					       = resnets

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







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

								for resnet in self.resnets:
										A					       = resnet(UpperCAmelCase__			,			UpperCAmelCase__			,			deterministic=UpperCAmelCase__		)
										output_states += (hidden_states,)

								if self.add_downsample:
										A					       = self.downsamplers_a(UpperCAmelCase__		)
										output_states += (hidden_states,)

								return hidden_states, output_states



class 			lowerCamelCase__						(   nn.Module			):
						lowerCAmelCase       =     42
						lowerCAmelCase       =     42
						lowerCAmelCase       =     42
						lowerCAmelCase       =     0.0
						lowerCAmelCase       =     1
						lowerCAmelCase       =     1
						lowerCAmelCase       =     True
						lowerCAmelCase       =     False
						lowerCAmelCase       =     False
						lowerCAmelCase       =     False
						lowerCAmelCase       =     jnp.floataa







						def __a						(							self   :    Dict		):
								A					       = []
								A					       = []

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

										A					       = FlaxResnetBlockaD(
										    in_channels=resnet_in_channels + res_skip_channels			,			out_channels=self.out_channels			,			dropout_prob=self.dropout			,			dtype=self.dtype			,			)
										resnets.append(UpperCAmelCase__		)

										A					       = 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(UpperCAmelCase__		)

								A					       = resnets
								A					       = attentions

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







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

										A					       = resnet(UpperCAmelCase__			,			UpperCAmelCase__			,			deterministic=UpperCAmelCase__		)
										A					       = attn(UpperCAmelCase__			,			UpperCAmelCase__			,			deterministic=UpperCAmelCase__		)

								if self.add_upsample:
										A					       = self.upsamplers_a(UpperCAmelCase__		)

								return hidden_states



class 			lowerCamelCase__						(   nn.Module			):
						lowerCAmelCase       =     42
						lowerCAmelCase       =     42
						lowerCAmelCase       =     42
						lowerCAmelCase       =     0.0
						lowerCAmelCase       =     1
						lowerCAmelCase       =     True
						lowerCAmelCase       =     jnp.floataa







						def __a						(							self   :    Any		):
								A					       = []

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

										A					       = FlaxResnetBlockaD(
										    in_channels=resnet_in_channels + res_skip_channels			,			out_channels=self.out_channels			,			dropout_prob=self.dropout			,			dtype=self.dtype			,			)
										resnets.append(UpperCAmelCase__		)

								A					       = resnets

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







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

										A					       = resnet(UpperCAmelCase__			,			UpperCAmelCase__			,			deterministic=UpperCAmelCase__		)

								if self.add_upsample:
										A					       = self.upsamplers_a(UpperCAmelCase__		)

								return hidden_states



class 			lowerCamelCase__						(   nn.Module			):
						lowerCAmelCase       =     42
						lowerCAmelCase       =     0.0
						lowerCAmelCase       =     1
						lowerCAmelCase       =     1
						lowerCAmelCase       =     False
						lowerCAmelCase       =     False
						lowerCAmelCase       =     jnp.floataa







						def __a						(							self   :    str		):
								A					       = [
								    FlaxResnetBlockaD(
								        in_channels=self.in_channels			,			out_channels=self.in_channels			,			dropout_prob=self.dropout			,			dtype=self.dtype			,			)
								]

								A					       = []

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

										A					       = FlaxResnetBlockaD(
										    in_channels=self.in_channels			,			out_channels=self.in_channels			,			dropout_prob=self.dropout			,			dtype=self.dtype			,			)
										resnets.append(UpperCAmelCase__		)

								A					       = resnets
								A					       = attentions







						def __call__(							self   :    List[str]			,			_lowercase   :    Dict			,			_lowercase   :    str			,			_lowercase   :    List[str]			,			_lowercase   :    int=True		):
								A					       = self.resnets[0](UpperCAmelCase__			,			UpperCAmelCase__		)
								for attn, resnet in zip(self.attentions			,			self.resnets[1:]		):
										A					       = attn(UpperCAmelCase__			,			UpperCAmelCase__			,			deterministic=UpperCAmelCase__		)
										A					       = resnet(UpperCAmelCase__			,			UpperCAmelCase__			,			deterministic=UpperCAmelCase__		)

								return hidden_states









"""simple docstring"""


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


UpperCamelCase						:				Any             =      {
    "configuration_lxmert": ["LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "LxmertConfig"],
    "tokenization_lxmert": ["LxmertTokenizer"],
}

try:
	if not is_tokenizers_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	UpperCamelCase						:				int             =      ["LxmertTokenizerFast"]

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	UpperCamelCase						:				Union[str, Any]             =      [
	    "LxmertEncoder",
	    "LxmertForPreTraining",
	    "LxmertForQuestionAnswering",
	    "LxmertModel",
	    "LxmertPreTrainedModel",
	    "LxmertVisualFeatureEncoder",
	    "LxmertXLayer",
	]

try:
	if not is_tf_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	UpperCamelCase						:				Union[str, Any]             =      [
	    "TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST",
	    "TFLxmertForPreTraining",
	    "TFLxmertMainLayer",
	    "TFLxmertModel",
	    "TFLxmertPreTrainedModel",
	    "TFLxmertVisualFeatureEncoder",
	]


if TYPE_CHECKING:
	from .configuration_lxmert import LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP, LxmertConfig
	from .tokenization_lxmert import LxmertTokenizer

	try:
		if not is_tokenizers_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_lxmert_fast import LxmertTokenizerFast

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_lxmert import (
		    LxmertEncoder,
		    LxmertForPreTraining,
		    LxmertForQuestionAnswering,
		    LxmertModel,
		    LxmertPreTrainedModel,
		    LxmertVisualFeatureEncoder,
		    LxmertXLayer,
		)

	try:
		if not is_tf_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tf_lxmert import (
		    TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFLxmertForPreTraining,
		    TFLxmertMainLayer,
		    TFLxmertModel,
		    TFLxmertPreTrainedModel,
		    TFLxmertVisualFeatureEncoder,
		)

else:
	import sys

	UpperCamelCase						:				Dict             =      _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)





