





import flax.linen as nn
import jax
import jax.numpy as jnp

class 		SCREAMING_SNAKE_CASE__				(       nn.Module  ):
      A_						:				int
      A_						:				jnp.dtype							=    jnp.floataa


      def    a (self       :      str      ):





         """simple docstring"""



         __snake_case							       =   nn.Conv(
             self.out_channels				,			kernel_size=(3, 3)				,			strides=(1, 1)				,			padding=((1, 1), (1, 1))				,			dtype=self.dtype				,			)


      def __call__(self       :      Dict				,			a__       :      Any      ):





         """simple docstring"""



         __snake_case       ,	__snake_case       ,	__snake_case       ,	__snake_case							       =   hidden_states.shape
         __snake_case							       =   jax.image.resize(
             a__				,			shape=(batch, height * 2, width * 2, channels)				,			method='''nearest'''				,			)
         __snake_case							       =   self.conv(a__      )
         return hidden_states






class 		SCREAMING_SNAKE_CASE__				(       nn.Module  ):
      A_						:				int
      A_						:				jnp.dtype							=    jnp.floataa


      def    a (self       :      Dict      ):





         """simple docstring"""



         __snake_case							       =   nn.Conv(
             self.out_channels				,			kernel_size=(3, 3)				,			strides=(2, 2)				,			padding=((1, 1), (1, 1))				,			dtype=self.dtype				,			)


      def __call__(self       :      Dict				,			a__       :      List[Any]      ):





         """simple docstring"""



         __snake_case							       =   self.conv(a__      )
         return hidden_states






class 		SCREAMING_SNAKE_CASE__				(       nn.Module  ):
      A_						:				int
      A_						:				int							=    None
      A_						:				float							=    0.0
      A_						:				bool							=    None
      A_						:				jnp.dtype							=    jnp.floataa


      def    a (self       :      Union[str, Any]      ):





         """simple docstring"""



         __snake_case							       =   self.in_channels if self.out_channels is None else self.out_channels

         __snake_case							       =   nn.GroupNorm(num_groups=32				,			epsilon=1E-5      )
         __snake_case							       =   nn.Conv(
             a__				,			kernel_size=(3, 3)				,			strides=(1, 1)				,			padding=((1, 1), (1, 1))				,			dtype=self.dtype				,			)

         __snake_case							       =   nn.Dense(a__				,			dtype=self.dtype      )

         __snake_case							       =   nn.GroupNorm(num_groups=32				,			epsilon=1E-5      )
         __snake_case							       =   nn.Dropout(self.dropout_prob      )
         __snake_case							       =   nn.Conv(
             a__				,			kernel_size=(3, 3)				,			strides=(1, 1)				,			padding=((1, 1), (1, 1))				,			dtype=self.dtype				,			)

         __snake_case							       =   self.in_channels != out_channels if self.use_nin_shortcut is None else self.use_nin_shortcut

         __snake_case							       =   None
         if use_nin_shortcut:
            __snake_case							       =   nn.Conv(
                a__				,			kernel_size=(1, 1)				,			strides=(1, 1)				,			padding='''VALID'''				,			dtype=self.dtype				,			)


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





         """simple docstring"""



         __snake_case							       =   hidden_states
         __snake_case							       =   self.norma(a__      )
         __snake_case							       =   nn.swish(a__      )
         __snake_case							       =   self.conva(a__      )

         __snake_case							       =   self.time_emb_proj(nn.swish(a__      )      )
         __snake_case							       =   jnp.expand_dims(jnp.expand_dims(a__				,			1      )				,			1      )
         __snake_case							       =   hidden_states + temb

         __snake_case							       =   self.norma(a__      )
         __snake_case							       =   nn.swish(a__      )
         __snake_case							       =   self.dropout(a__				,			a__      )
         __snake_case							       =   self.conva(a__      )

         if self.conv_shortcut is not None:
            __snake_case							       =   self.conv_shortcut(a__      )

         return hidden_states + residual






import unittest

import numpy as np

from transformers import AlbertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
     import jax.numpy as jnp

     from transformers.models.albert.modeling_flax_albert import (
         FlaxAlbertForMaskedLM,
         FlaxAlbertForMultipleChoice,
         FlaxAlbertForPreTraining,
         FlaxAlbertForQuestionAnswering,
         FlaxAlbertForSequenceClassification,
         FlaxAlbertForTokenClassification,
         FlaxAlbertModel,
     )






class SCREAMING_SNAKE_CASE__     (		unittest.TestCase    ):




    '''simple docstring'''






    def __init__(       self,		lowerCamelCase__,		lowerCamelCase__=13,		lowerCamelCase__=7,		lowerCamelCase__=True,		lowerCamelCase__=True,		lowerCamelCase__=True,		lowerCamelCase__=True,		lowerCamelCase__=99,		lowerCamelCase__=32,		lowerCamelCase__=5,		lowerCamelCase__=4,		lowerCamelCase__=37,		lowerCamelCase__="gelu",		lowerCamelCase__=0.1,		lowerCamelCase__=0.1,		lowerCamelCase__=512,		lowerCamelCase__=16,		lowerCamelCase__=2,		lowerCamelCase__=0.02,		lowerCamelCase__=4,		):
        A :       List[str]          =   parent
        A :       Optional[int]          =   batch_size
        A :       Union[str, Any]          =   seq_length
        A :       Any          =   is_training
        A :       List[str]          =   use_attention_mask
        A :       Union[str, Any]          =   use_token_type_ids
        A :       Any          =   use_labels
        A :       str          =   vocab_size
        A :       Union[str, Any]          =   hidden_size
        A :       str          =   num_hidden_layers
        A :       List[Any]          =   num_attention_heads
        A :       Optional[int]          =   intermediate_size
        A :       Optional[Any]          =   hidden_act
        A :       Dict          =   hidden_dropout_prob
        A :       List[Any]          =   attention_probs_dropout_prob
        A :       Optional[int]          =   max_position_embeddings
        A :       int          =   type_vocab_size
        A :       str          =   type_sequence_label_size
        A :       List[Any]          =   initializer_range
        A :       str          =   num_choices






    def 			_lowerCAmelCase					(       self		):
        A :       Optional[int]          =   ids_tensor([self.batch_size, self.seq_length],		self.vocab_size		)

        A :       Union[str, Any]          =   None
        if self.use_attention_mask:
            A :       Optional[int]          =   random_attention_mask([self.batch_size, self.seq_length]		)

        A :       int          =   None
        if self.use_token_type_ids:
            A :       List[Any]          =   ids_tensor([self.batch_size, self.seq_length],		self.type_vocab_size		)

        A :       Optional[int]          =   AlbertConfig(
            vocab_size=self.vocab_size,		hidden_size=self.hidden_size,		num_hidden_layers=self.num_hidden_layers,		num_attention_heads=self.num_attention_heads,		intermediate_size=self.intermediate_size,		hidden_act=self.hidden_act,		hidden_dropout_prob=self.hidden_dropout_prob,		attention_probs_dropout_prob=self.attention_probs_dropout_prob,		max_position_embeddings=self.max_position_embeddings,		type_vocab_size=self.type_vocab_size,		is_decoder=lowerCamelCase__,		initializer_range=self.initializer_range,		)

        return config, input_ids, token_type_ids, attention_mask






    def 			_lowerCAmelCase					(       self		):
        A :       Dict          =   self.prepare_config_and_inputs()
        A     ,							A     ,							A     ,							A :       str          =   config_and_inputs
        A :       Union[str, Any]          =   {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": attention_mask}
        return config, inputs_dict






@require_flax
class SCREAMING_SNAKE_CASE__     (		SCREAMING_SNAKE_CASE__ ,						unittest.TestCase    ):




    '''simple docstring'''






    __lowerCamelCase			: Any					=      (
        (
            FlaxAlbertModel,
            FlaxAlbertForPreTraining,
            FlaxAlbertForMaskedLM,
            FlaxAlbertForMultipleChoice,
            FlaxAlbertForQuestionAnswering,
            FlaxAlbertForSequenceClassification,
            FlaxAlbertForTokenClassification,
            FlaxAlbertForQuestionAnswering,
        )
        if is_flax_available()
        else ()
    )






    def 			_lowerCAmelCase					(       self		):
        A :       Dict          =   FlaxAlbertModelTester(self		)






    @slow
    def 			_lowerCAmelCase					(       self		):
        for model_class_name in self.all_model_classes:
            A :       Dict          =   model_class_name.from_pretrained("""albert-base-v2"""		)
            A :       Optional[int]          =   model(np.ones((1, 1)		)		)
            self.assertIsNotNone(lowerCamelCase__		)






@require_flax
class SCREAMING_SNAKE_CASE__     (		unittest.TestCase    ):




    '''simple docstring'''






    @slow
    def 			_lowerCAmelCase					(       self		):
        A :       Dict          =   FlaxAlbertModel.from_pretrained("""albert-base-v2"""		)
        A :       List[str]          =   np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]		)
        A :       str          =   np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
        A :       Optional[int]          =   model(lowerCamelCase__,		attention_mask=lowerCamelCase__		)[0]
        A :       str          =   (1, 11, 768)
        self.assertEqual(output.shape,		lowerCamelCase__		)
        A :       Optional[int]          =   np.array(
            [[[-0.6513, 1.5035, -0.2766], [-0.6515, 1.5046, -0.2780], [-0.6512, 1.5049, -0.2784]]]		)

        self.assertTrue(jnp.allclose(output[:, 1:4, 1:4],		lowerCamelCase__,		atol=1e-4		)		)


