

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




			"""simple docstring"""







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



			def 	_SCREAMING_SNAKE_CASE      (			self  :					Any):
									SCREAMING_SNAKE_CASE_:			int  		=	ids_tensor([self.batch_size, self.seq_length]       ,						self.vocab_size)

									SCREAMING_SNAKE_CASE_:			Tuple  		=	None
									if self.use_attention_mask:
															SCREAMING_SNAKE_CASE_:			List[Any]  		=	random_attention_mask([self.batch_size, self.seq_length])

									SCREAMING_SNAKE_CASE_:			int  		=	None
									if self.use_token_type_ids:
															SCREAMING_SNAKE_CASE_:			Dict  		=	ids_tensor([self.batch_size, self.seq_length]       ,						self.type_vocab_size)

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

									return config, input_ids, token_type_ids, attention_mask




			def 	_SCREAMING_SNAKE_CASE      (			self  :					int):
									SCREAMING_SNAKE_CASE_:			Any  		=	self.prepare_config_and_inputs()
									SCREAMING_SNAKE_CASE_:			List[Any]  		=	config_and_inputs
									SCREAMING_SNAKE_CASE_:			Dict  		=	{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': attention_mask}
									return config, inputs_dict







@require_flax
class   __lowercase    (			UpperCAmelCase_		,	unittest.TestCase     ):




			"""simple docstring"""







			_UpperCAmelCase       :							Dict      							=					(
			    (
			        FlaxAlbertModel,
			        FlaxAlbertForPreTraining,
			        FlaxAlbertForMaskedLM,
			        FlaxAlbertForMultipleChoice,
			        FlaxAlbertForQuestionAnswering,
			        FlaxAlbertForSequenceClassification,
			        FlaxAlbertForTokenClassification,
			        FlaxAlbertForQuestionAnswering,
			    )
			    if is_flax_available()
			    else ()
			)



			def 	_SCREAMING_SNAKE_CASE      (			self  :					Any):
									SCREAMING_SNAKE_CASE_:			str  		=	FlaxAlbertModelTester(self)




			@slow
			def 	_SCREAMING_SNAKE_CASE      (			self  :					Optional[Any]):
									for model_class_name in self.all_model_classes:
															SCREAMING_SNAKE_CASE_:			str  		=	model_class_name.from_pretrained("albert-base-v2")
															SCREAMING_SNAKE_CASE_:			Optional[int]  		=	model(np.ones((1, 1)))
															self.assertIsNotNone(__lowercase)







@require_flax
class   __lowercase    (			unittest.TestCase     ):




			"""simple docstring"""







			@slow
			def 	_SCREAMING_SNAKE_CASE      (			self  :					List[Any]):
									SCREAMING_SNAKE_CASE_:			Tuple  		=	FlaxAlbertModel.from_pretrained("albert-base-v2")
									SCREAMING_SNAKE_CASE_:			List[Any]  		=	np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]])
									SCREAMING_SNAKE_CASE_:			List[Any]  		=	np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
									SCREAMING_SNAKE_CASE_:			Dict  		=	model(__lowercase       ,						attention_mask=__lowercase)[0]
									SCREAMING_SNAKE_CASE_:			Optional[int]  		=	(1, 11, 768)
									self.assertEqual(output.shape       ,						__lowercase)
									SCREAMING_SNAKE_CASE_:			List[str]  		=	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))









def       A_				(   _UpperCAmelCase    ,     _UpperCAmelCase   ):

						if density <= 0:
												raise ValueError("Impossible fluid density"   )
						if bulk_modulus <= 0:
												raise ValueError("Impossible bulk modulus"   )

						return (bulk_modulus / density) ** 0.5


if __name__ == "__main__":
						import doctest

						doctest.testmod()






