



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



		def __init__(     self     :Dict   ,__lowercase     :Dict   ,__lowercase     :int=1_3   ,__lowercase     :Any=7   ,__lowercase     :Optional[Any]=True   ,__lowercase     :Optional[Any]=True   ,__lowercase     :Dict=True   ,__lowercase     :Optional[Any]=True   ,__lowercase     :Dict=9_9   ,__lowercase     :str=3_2   ,__lowercase     :Optional[Any]=5   ,__lowercase     :Any=4   ,__lowercase     :Optional[Any]=3_7   ,__lowercase     :Tuple="gelu"   ,__lowercase     :Dict=0.1   ,__lowercase     :Dict=0.1   ,__lowercase     :Union[str, Any]=5_1_2   ,__lowercase     :Tuple=1_6   ,__lowercase     :Optional[int]=2   ,__lowercase     :Optional[int]=0.02   ,__lowercase     :int=4   ,):
						snake_case__	:      List[Any]     		=	parent
						snake_case__	:      Optional[Any]     		=	batch_size
						snake_case__	:      int     		=	seq_length
						snake_case__	:      str     		=	is_training
						snake_case__	:      List[str]     		=	use_attention_mask
						snake_case__	:      int     		=	use_token_type_ids
						snake_case__	:      Dict     		=	use_labels
						snake_case__	:      str     		=	vocab_size
						snake_case__	:      str     		=	hidden_size
						snake_case__	:      Any     		=	num_hidden_layers
						snake_case__	:      Union[str, Any]     		=	num_attention_heads
						snake_case__	:      str     		=	intermediate_size
						snake_case__	:      str     		=	hidden_act
						snake_case__	:      Union[str, Any]     		=	hidden_dropout_prob
						snake_case__	:      Optional[int]     		=	attention_probs_dropout_prob
						snake_case__	:      Any     		=	max_position_embeddings
						snake_case__	:      Tuple     		=	type_vocab_size
						snake_case__	:      Dict     		=	type_sequence_label_size
						snake_case__	:      Optional[int]     		=	initializer_range
						snake_case__	:      List[str]     		=	num_choices



		def 	__lowerCamelCase			(     self     :List[Any]  ):
						snake_case__	:      Optional[int]     		=	ids_tensor([self.batch_size, self.seq_length]   ,self.vocab_size  )

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

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

						snake_case__	:      Dict     		=	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=__lowercase   ,initializer_range=self.initializer_range   ,)

						return config, input_ids, token_type_ids, attention_mask






		def 	__lowerCamelCase			(     self     :int  ):
						snake_case__	:      str     		=	self.prepare_config_and_inputs()
						snake_case__		, snake_case__		, snake_case__		, snake_case__	:      Union[str, Any]     		=	config_and_inputs
						snake_case__	:      str     		=	{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': attention_mask}
						return config, inputs_dict


@require_flax
class       a							(			__lowerCamelCase  ,							unittest.TestCase				):
		__lowerCAmelCase	:    List[str]											=					(
		    (
		        FlaxAlbertModel,
		        FlaxAlbertForPreTraining,
		        FlaxAlbertForMaskedLM,
		        FlaxAlbertForMultipleChoice,
		        FlaxAlbertForQuestionAnswering,
		        FlaxAlbertForSequenceClassification,
		        FlaxAlbertForTokenClassification,
		        FlaxAlbertForQuestionAnswering,
		    )
		    if is_flax_available()
		    else ()
		)



		def 	__lowerCamelCase			(     self     :Optional[int]  ):
						snake_case__	:      int     		=	FlaxAlbertModelTester(self  )






		@slow
		def 	__lowerCamelCase			(     self     :Tuple  ):
						for model_class_name in self.all_model_classes:
										snake_case__	:      Tuple     		=	model_class_name.from_pretrained('''albert-base-v2'''  )
										snake_case__	:      Any     		=	model(np.ones((1, 1)  )  )
										self.assertIsNotNone(__lowercase  )


@require_flax
class       a							(			unittest.TestCase				):



		@slow
		def 	__lowerCamelCase			(     self     :int  ):
						snake_case__	:      List[str]     		=	FlaxAlbertModel.from_pretrained('''albert-base-v2'''  )
						snake_case__	:      str     		=	np.array([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]]  )
						snake_case__	:      int     		=	np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]  )
						snake_case__	:      str     		=	model(__lowercase   ,attention_mask=__lowercase  )[0]
						snake_case__	:      Any     		=	(1, 1_1, 7_6_8)
						self.assertEqual(output.shape   ,__lowercase  )
						snake_case__	:      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]   ,__lowercase   ,atol=1e-4  )  )






# tests directory-specific settings - this file is run automatically
# by pytest before any tests are run

import sys
import warnings
from os.path import abspath, dirname, join


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
A__								=						abspath(join(dirname(dirname(dirname(__file__))), '''src'''))
sys.path.insert(1, git_repo_path)


# silence FutureWarning warnings in tests since often we can't act on them until
# they become normal warnings - i.e. the tests still need to test the current functionality
warnings.simplefilter(action='''ignore''', category=FutureWarning)



def 			_lowerCAmelCase       (					__lowerCAmelCase      )   ->					str:


				"""simple docstring"""

				from transformers.testing_utils import pytest_addoption_shared

				pytest_addoption_shared(__lowerCAmelCase      )





def 			_lowerCAmelCase       (					__lowerCAmelCase      )   ->					List[Any]:


				"""simple docstring"""

				from transformers.testing_utils import pytest_terminal_summary_main

				snake_case__	:      Dict     		=	terminalreporter.config.getoption('''--make-reports'''      )
				if make_reports:
								pytest_terminal_summary_main(__lowerCAmelCase  ,  id=__lowerCAmelCase      )

