





"""simple docstring"""




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  __UpperCamelCase       (		unittest.TestCase		):






							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   ,      )			->				int:
								a   :	str			=       parent
								a   :	List[str]			=       batch_size
								a   :	str			=       seq_length
								a   :	str			=       is_training
								a   :	Dict			=       use_attention_mask
								a   :	str			=       use_token_type_ids
								a   :	List[str]			=       use_labels
								a   :	Optional[int]			=       vocab_size
								a   :	Tuple			=       hidden_size
								a   :	Optional[int]			=       num_hidden_layers
								a   :	Tuple			=       num_attention_heads
								a   :	Any			=       intermediate_size
								a   :	str			=       hidden_act
								a   :	Any			=       hidden_dropout_prob
								a   :	Optional[Any]			=       attention_probs_dropout_prob
								a   :	Optional[int]			=       max_position_embeddings
								a   :	Tuple			=       type_vocab_size
								a   :	List[str]			=       type_sequence_label_size
								a   :	List[Any]			=       initializer_range
								a   :	str			=       num_choices






							def 					__a     (     self   )			->				List[str]:
								a   :	Optional[Any]			=       ids_tensor([self.batch_size, self.seq_length]   ,      self.vocab_size   )

								a   :	List[Any]			=       None
								if self.use_attention_mask:
									a   :	Optional[int]			=       random_attention_mask([self.batch_size, self.seq_length]   )

								a   :	Dict			=       None
								if self.use_token_type_ids:
									a   :	List[str]			=       ids_tensor([self.batch_size, self.seq_length]   ,      self.type_vocab_size   )

								a   :	List[Any]			=       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 					__a     (     self   )			->				List[str]:
								a   :	Union[str, Any]			=       self.prepare_config_and_inputs()
								a, a, a, a   :	int			=       config_and_inputs
								a   :	Optional[Any]			=       {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": attention_mask}
								return config, inputs_dict


@require_flax
class  __UpperCamelCase       (		a__	, unittest.TestCase		):
							lowerCamelCase     :      Optional[int]         =(
							    (
							        FlaxAlbertModel,
							        FlaxAlbertForPreTraining,
							        FlaxAlbertForMaskedLM,
							        FlaxAlbertForMultipleChoice,
							        FlaxAlbertForQuestionAnswering,
							        FlaxAlbertForSequenceClassification,
							        FlaxAlbertForTokenClassification,
							        FlaxAlbertForQuestionAnswering,
							    )
							    if is_flax_available()
							    else ()
							)






							def 					__a     (     self   )			->				Dict:
								a   :	Dict			=       FlaxAlbertModelTester(self   )






							@slow
							def 					__a     (     self   )			->				int:
								for model_class_name in self.all_model_classes:
									a   :	Optional[int]			=       model_class_name.from_pretrained("albert-base-v2"   )
									a   :	Tuple			=       model(np.ones((1, 1)   )   )
									self.assertIsNotNone(lowerCAmelCase__   )


@require_flax
class  __UpperCamelCase       (		unittest.TestCase		):






							@slow
							def 					__a     (     self   )			->				List[Any]:
								a   :	Any			=       FlaxAlbertModel.from_pretrained("albert-base-v2"   )
								a   :	Union[str, Any]			=       np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]   )
								a   :	int			=       np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]   )
								a   :	Any			=       model(lowerCAmelCase__   ,      attention_mask=lowerCAmelCase__   )[0]
								a   :	List[Any]			=       (1, 11, 768)
								self.assertEqual(output.shape   ,      lowerCAmelCase__   )
								a   :	Optional[int]			=       np.array(
								    [[[-0.6_513, 1.5_035, -0.2_766], [-0.6_515, 1.5_046, -0.2_780], [-0.6_512, 1.5_049, -0.2_784]]]   )

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









"""simple docstring"""




from ..utils import DummyObject, requires_backends


class  __UpperCamelCase       (		metaclass=a__		):
							lowerCamelCase     :      Optional[Any]         =["""transformers""", """torch""", """note_seq"""]






							def __init__(     self   ,      *lowerCAmelCase__   ,      **lowerCAmelCase__   )			->				Union[str, Any]:
								requires_backends(self   ,      ["transformers", "torch", "note_seq"]   )






							@classmethod
							def 					__a     (     cls   ,      *lowerCAmelCase__   ,      **lowerCAmelCase__   )			->				Any:
								requires_backends(cls   ,      ["transformers", "torch", "note_seq"]   )






							@classmethod
							def 					__a     (     cls   ,      *lowerCAmelCase__   ,      **lowerCAmelCase__   )			->				int:
								requires_backends(cls   ,      ["transformers", "torch", "note_seq"]   )


