


"""simple docstring"""


import unittest

import numpy as np

from transformers import DistilBertConfig, 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.distilbert.modeling_flax_distilbert import (
		    FlaxDistilBertForMaskedLM,
		    FlaxDistilBertForMultipleChoice,
		    FlaxDistilBertForQuestionAnswering,
		    FlaxDistilBertForSequenceClassification,
		    FlaxDistilBertForTokenClassification,
		    FlaxDistilBertModel,
		)
class snake_case      (  unittest.TestCase):







		def __init__(					self      :       int    ,   a__      :       Dict    ,   a__      :       Optional[Any]=13    ,   a__      :       str=7    ,   a__      :       Optional[int]=True    ,   a__      :       int=True    ,   a__      :       Optional[Any]=True    ,   a__      :       List[Any]=True    ,   a__      :       Optional[int]=99    ,   a__      :       str=32    ,   a__      :       Union[str, Any]=5    ,   a__      :       Union[str, Any]=4    ,   a__      :       Tuple=37    ,   a__      :       str="gelu"    ,   a__      :       str=0.1    ,   a__      :       List[str]=0.1    ,   a__      :       Dict=5_12    ,   a__      :       Any=16    ,   a__      :       List[str]=2    ,   a__      :       Optional[Any]=0.0_2    ,   a__      :       int=4    ,   )       ->						Dict:





						'''simple docstring'''







						_A					  =			parent
						_A					  =			batch_size
						_A					  =			seq_length
						_A					  =			is_training
						_A					  =			use_attention_mask
						_A					  =			use_token_type_ids
						_A					  =			use_labels
						_A					  =			vocab_size
						_A					  =			hidden_size
						_A					  =			num_hidden_layers
						_A					  =			num_attention_heads
						_A					  =			intermediate_size
						_A					  =			hidden_act
						_A					  =			hidden_dropout_prob
						_A					  =			attention_probs_dropout_prob
						_A					  =			max_position_embeddings
						_A					  =			type_vocab_size
						_A					  =			type_sequence_label_size
						_A					  =			initializer_range
						_A					  =			num_choices







		def  a_ (					self      :       Union[str, Any]		)       ->						int:





						'''simple docstring'''







						_A					  =			ids_tensor([self.batch_size, self.seq_length]    ,   self.vocab_size		)

						_A					  =			None
						if self.use_attention_mask:
										_A					  =			random_attention_mask([self.batch_size, self.seq_length]		)

						_A					  =			DistilBertConfig(
						    vocab_size=self.vocab_size    ,   dim=self.hidden_size    ,   n_layers=self.num_hidden_layers    ,   n_heads=self.num_attention_heads    ,   hidden_dim=self.intermediate_size    ,   hidden_act=self.hidden_act    ,   dropout=self.hidden_dropout_prob    ,   attention_dropout=self.attention_probs_dropout_prob    ,   max_position_embeddings=self.max_position_embeddings    ,   initializer_range=self.initializer_range    ,   tie_weights_=a__    ,   )

						return config, input_ids, attention_mask







		def  a_ (					self      :       int		)       ->						Optional[int]:





						'''simple docstring'''







						_A					  =			self.prepare_config_and_inputs()
						_A  ,		_A  ,		_A					  =			config_and_inputs
						_A					  =			{"input_ids": input_ids, "attention_mask": attention_mask}
						return config, inputs_dict





@require_flax
class snake_case      (  _UpperCamelCase     ,				unittest.TestCase):
		__UpperCamelCase           =			(
		    (
		        FlaxDistilBertModel,
		        FlaxDistilBertForMaskedLM,
		        FlaxDistilBertForMultipleChoice,
		        FlaxDistilBertForQuestionAnswering,
		        FlaxDistilBertForSequenceClassification,
		        FlaxDistilBertForTokenClassification,
		        FlaxDistilBertForQuestionAnswering,
		    )
		    if is_flax_available()
		    else ()
		)







		def  a_ (					self      :       Any		)       ->						Union[str, Any]:





						'''simple docstring'''







						_A					  =			FlaxDistilBertModelTester(self		)







		@slow
		def  a_ (					self      :       List[str]		)       ->						Union[str, Any]:





						'''simple docstring'''







						for model_class_name in self.all_model_classes:
										_A					  =			model_class_name.from_pretrained("distilbert-base-uncased"		)
										_A					  =			model(np.ones((1, 1)		)		)
										self.assertIsNotNone(a__		)





@require_flax
class snake_case      (  unittest.TestCase):







		@slow
		def  a_ (					self      :       Tuple		)       ->						Tuple:





						'''simple docstring'''







						_A					  =			FlaxDistilBertModel.from_pretrained("distilbert-base-uncased"		)
						_A					  =			np.array([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]]		)
						_A					  =			np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
						_A					  =			model(a__    ,   attention_mask=a__		)[0]
						_A					  =			(1, 11, 7_68)
						self.assertEqual(output.shape    ,   a__		)
						_A					  =			np.array([[[-0.1_6_3_9, 0.3_2_9_9, 0.1_6_4_8], [-0.1_7_4_6, 0.3_2_8_9, 0.1_7_1_0], [-0.1_8_8_4, 0.3_3_5_7, 0.1_8_1_0]]]		)

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



"""simple docstring"""


def      a__ (				__lowercase     ,			__lowercase   )	->	int:
				while a != 0:
								_A  ,		_A					  =			b % a, a
				return b






def      a__ (				__lowercase     ,			__lowercase   )	->	int:
				if gcd(__lowercase     ,			__lowercase   ) != 1:
								_A					  =			f"""mod inverse of {a!r} and {m!r} does not exist"""
								raise ValueError(__lowercase   )
				_A  ,		_A  ,		_A					  =			1, 0, a
				_A  ,		_A  ,		_A					  =			0, 1, m
				while va != 0:
								_A					  =			ua // va
								_A  ,		_A  ,		_A  ,		_A  ,		_A  ,		_A					  =			(ua - q * va), (ua - q * va), (ua - q * va), va, va, va
				return ua % m