

"""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      _UpperCAmelCase      (		nn.Module):
			__a			:							int
			__a			:							int
			__a			:							float					       =				0.0
			__a			:							int					       =				1
			__a			:							int					       =				1
			__a			:							bool					       =				True
			__a			:							bool					       =				False
			__a			:							bool					       =				False
			__a			:							bool					       =				False
			__a			:							jnp.dtype					       =				jnp.floataa
			def 				__snake_case			(		self  )     ->     Tuple:






				'''simple docstring'''







				_UpperCAmelCase     :				Dict          =       []
				_UpperCAmelCase     :				List[Any]          =       []

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

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

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

				_UpperCAmelCase     :				Dict          =       resnets
				_UpperCAmelCase     :				int          =       attentions

				if self.add_downsample:
					_UpperCAmelCase     :				List[str]          =       FlaxDownsampleaD(self.out_channels   ,		dtype=self.dtype  )
			def __call__(		self   ,		_A   ,		_A   ,		_A   ,		_A=True  )     ->     Any:






				'''simple docstring'''







				_UpperCAmelCase     :				Optional[int]          =       ()

				for resnet, attn in zip(self.resnets   ,		self.attentions  ):
					_UpperCAmelCase     :				Union[str, Any]          =       resnet(lowerCamelCase__   ,		lowerCamelCase__   ,		deterministic=lowerCamelCase__  )
					_UpperCAmelCase     :				Tuple          =       attn(lowerCamelCase__   ,		lowerCamelCase__   ,		deterministic=lowerCamelCase__  )
					output_states += (hidden_states,)

				if self.add_downsample:
					_UpperCAmelCase     :				Dict          =       self.downsamplers_a(lowerCamelCase__  )
					output_states += (hidden_states,)

				return hidden_states, output_states






class      _UpperCAmelCase      (		nn.Module):
			__a			:							int
			__a			:							int
			__a			:							float					       =				0.0
			__a			:							int					       =				1
			__a			:							bool					       =				True
			__a			:							jnp.dtype					       =				jnp.floataa
			def 				__snake_case			(		self  )     ->     Optional[Any]:






				'''simple docstring'''







				_UpperCAmelCase     :				Optional[int]          =       []

				for i in range(self.num_layers  ):
					_UpperCAmelCase     :				List[str]          =       self.in_channels if i == 0 else self.out_channels

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

				if self.add_downsample:
					_UpperCAmelCase     :				int          =       FlaxDownsampleaD(self.out_channels   ,		dtype=self.dtype  )
			def __call__(		self   ,		_A   ,		_A   ,		_A=True  )     ->     str:






				'''simple docstring'''







				_UpperCAmelCase     :				Union[str, Any]          =       ()

				for resnet in self.resnets:
					_UpperCAmelCase     :				Tuple          =       resnet(lowerCamelCase__   ,		lowerCamelCase__   ,		deterministic=lowerCamelCase__  )
					output_states += (hidden_states,)

				if self.add_downsample:
					_UpperCAmelCase     :				List[Any]          =       self.downsamplers_a(lowerCamelCase__  )
					output_states += (hidden_states,)

				return hidden_states, output_states






class      _UpperCAmelCase      (		nn.Module):
			__a			:							int
			__a			:							int
			__a			:							int
			__a			:							float					       =				0.0
			__a			:							int					       =				1
			__a			:							int					       =				1
			__a			:							bool					       =				True
			__a			:							bool					       =				False
			__a			:							bool					       =				False
			__a			:							bool					       =				False
			__a			:							jnp.dtype					       =				jnp.floataa
			def 				__snake_case			(		self  )     ->     Any:






				'''simple docstring'''







				_UpperCAmelCase     :				int          =       []
				_UpperCAmelCase     :				List[str]          =       []

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

					_UpperCAmelCase     :				List[str]          =       FlaxResnetBlockaD(
					    in_channels=resnet_in_channels + res_skip_channels   ,		out_channels=self.out_channels   ,		dropout_prob=self.dropout   ,		dtype=self.dtype   ,		)
					resnets.append(lowerCamelCase__  )

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

				_UpperCAmelCase     :				Dict          =       resnets
				_UpperCAmelCase     :				Union[str, Any]          =       attentions

				if self.add_upsample:
					_UpperCAmelCase     :				List[str]          =       FlaxUpsampleaD(self.out_channels   ,		dtype=self.dtype  )
			def __call__(		self   ,		_A   ,		_A   ,		_A   ,		_A   ,		_A=True  )     ->     Union[str, Any]:






				'''simple docstring'''







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

					_UpperCAmelCase     :				Tuple          =       resnet(lowerCamelCase__   ,		lowerCamelCase__   ,		deterministic=lowerCamelCase__  )
					_UpperCAmelCase     :				Dict          =       attn(lowerCamelCase__   ,		lowerCamelCase__   ,		deterministic=lowerCamelCase__  )

				if self.add_upsample:
					_UpperCAmelCase     :				Union[str, Any]          =       self.upsamplers_a(lowerCamelCase__  )

				return hidden_states






class      _UpperCAmelCase      (		nn.Module):
			__a			:							int
			__a			:							int
			__a			:							int
			__a			:							float					       =				0.0
			__a			:							int					       =				1
			__a			:							bool					       =				True
			__a			:							jnp.dtype					       =				jnp.floataa
			def 				__snake_case			(		self  )     ->     Dict:






				'''simple docstring'''







				_UpperCAmelCase     :				Union[str, Any]          =       []

				for i in range(self.num_layers  ):
					_UpperCAmelCase     :				Optional[int]          =       self.in_channels if (i == self.num_layers - 1) else self.out_channels
					_UpperCAmelCase     :				Dict          =       self.prev_output_channel if i == 0 else self.out_channels

					_UpperCAmelCase     :				Dict          =       FlaxResnetBlockaD(
					    in_channels=resnet_in_channels + res_skip_channels   ,		out_channels=self.out_channels   ,		dropout_prob=self.dropout   ,		dtype=self.dtype   ,		)
					resnets.append(lowerCamelCase__  )

				_UpperCAmelCase     :				List[Any]          =       resnets

				if self.add_upsample:
					_UpperCAmelCase     :				int          =       FlaxUpsampleaD(self.out_channels   ,		dtype=self.dtype  )
			def __call__(		self   ,		_A   ,		_A   ,		_A   ,		_A=True  )     ->     Optional[int]:






				'''simple docstring'''







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

					_UpperCAmelCase     :				Union[str, Any]          =       resnet(lowerCamelCase__   ,		lowerCamelCase__   ,		deterministic=lowerCamelCase__  )

				if self.add_upsample:
					_UpperCAmelCase     :				Any          =       self.upsamplers_a(lowerCamelCase__  )

				return hidden_states






class      _UpperCAmelCase      (		nn.Module):
			__a			:							int
			__a			:							float					       =				0.0
			__a			:							int					       =				1
			__a			:							int					       =				1
			__a			:							bool					       =				False
			__a			:							bool					       =				False
			__a			:							jnp.dtype					       =				jnp.floataa
			def 				__snake_case			(		self  )     ->     Union[str, Any]:






				'''simple docstring'''







				_UpperCAmelCase     :				int          =       [
				    FlaxResnetBlockaD(
				        in_channels=self.in_channels   ,		out_channels=self.in_channels   ,		dropout_prob=self.dropout   ,		dtype=self.dtype   ,		)
				]

				_UpperCAmelCase     :				Dict          =       []

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

					_UpperCAmelCase     :				List[str]          =       FlaxResnetBlockaD(
					    in_channels=self.in_channels   ,		out_channels=self.in_channels   ,		dropout_prob=self.dropout   ,		dtype=self.dtype   ,		)
					resnets.append(lowerCamelCase__  )

				_UpperCAmelCase     :				Union[str, Any]          =       resnets
				_UpperCAmelCase     :				Optional[int]          =       attentions
			def __call__(		self   ,		_A   ,		_A   ,		_A   ,		_A=True  )     ->     List[Any]:






				'''simple docstring'''







				_UpperCAmelCase     :				List[str]          =       self.resnets[0](lowerCamelCase__   ,		lowerCamelCase__  )
				for attn, resnet in zip(self.attentions   ,		self.resnets[1:]  ):
					_UpperCAmelCase     :				Optional[Any]          =       attn(lowerCamelCase__   ,		lowerCamelCase__   ,		deterministic=lowerCamelCase__  )
					_UpperCAmelCase     :				List[str]          =       resnet(lowerCamelCase__   ,		lowerCamelCase__   ,		deterministic=lowerCamelCase__  )

				return hidden_states









"""simple docstring"""


from typing import TYPE_CHECKING

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__snake_case    					=					{'configuration_mmbt': ['MMBTConfig']}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   __snake_case    					=					['MMBTForClassification', 'MMBTModel', 'ModalEmbeddings']


if TYPE_CHECKING:
   from .configuration_mmbt import MMBTConfig

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_mmbt import MMBTForClassification, MMBTModel, ModalEmbeddings

else:
   import sys

   __snake_case    					=					_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)