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


						def __init__( self			:       Dict					,	UpperCamelCase__			:       Any					,	UpperCamelCase__			:       Optional[Any]=13					,	UpperCamelCase__			:       Optional[int]=7					,	UpperCamelCase__			:       str=True					,	UpperCamelCase__			:       Tuple=True					,	UpperCamelCase__			:       Tuple=True					,	UpperCamelCase__			:       Dict=True					,	UpperCamelCase__			:       Tuple=99					,	UpperCamelCase__			:       Tuple=32					,	UpperCamelCase__			:       List[str]=5					,	UpperCamelCase__			:       Tuple=4					,	UpperCamelCase__			:       Tuple=37					,	UpperCamelCase__			:       str="gelu"					,	UpperCamelCase__			:       List[Any]=0.1					,	UpperCamelCase__			:       Optional[Any]=0.1					,	UpperCamelCase__			:       Tuple=512					,	UpperCamelCase__			:       Optional[Any]=16					,	UpperCamelCase__			:       Any=2					,	UpperCamelCase__			:       int=0.02					,	UpperCamelCase__			:       Tuple=4					,	):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Optional[Any]           =							parent
												SCREAMING_SNAKE_CASE							:					Any           =							batch_size
												SCREAMING_SNAKE_CASE							:					Any           =							seq_length
												SCREAMING_SNAKE_CASE							:					List[Any]           =							is_training
												SCREAMING_SNAKE_CASE							:					str           =							use_attention_mask
												SCREAMING_SNAKE_CASE							:					List[Any]           =							use_token_type_ids
												SCREAMING_SNAKE_CASE							:					Dict           =							use_labels
												SCREAMING_SNAKE_CASE							:					Optional[int]           =							vocab_size
												SCREAMING_SNAKE_CASE							:					List[Any]           =							hidden_size
												SCREAMING_SNAKE_CASE							:					List[Any]           =							num_hidden_layers
												SCREAMING_SNAKE_CASE							:					Optional[Any]           =							num_attention_heads
												SCREAMING_SNAKE_CASE							:					List[str]           =							intermediate_size
												SCREAMING_SNAKE_CASE							:					List[str]           =							hidden_act
												SCREAMING_SNAKE_CASE							:					str           =							hidden_dropout_prob
												SCREAMING_SNAKE_CASE							:					List[str]           =							attention_probs_dropout_prob
												SCREAMING_SNAKE_CASE							:					List[str]           =							max_position_embeddings
												SCREAMING_SNAKE_CASE							:					List[str]           =							type_vocab_size
												SCREAMING_SNAKE_CASE							:					List[str]           =							type_sequence_label_size
												SCREAMING_SNAKE_CASE							:					Dict           =							initializer_range
												SCREAMING_SNAKE_CASE							:					Union[str, Any]           =							num_choices


						def  __A ( self			:       List[Any]		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					List[Any]           =							ids_tensor([self.batch_size, self.seq_length]					,	self.vocab_size		)

												SCREAMING_SNAKE_CASE							:					int           =							None
												if self.use_attention_mask:
																		SCREAMING_SNAKE_CASE							:					List[str]           =							random_attention_mask([self.batch_size, self.seq_length]		)

												SCREAMING_SNAKE_CASE							:					Union[str, Any]           =							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_=UpperCamelCase__					,	)

												return config, input_ids, attention_mask



						def  __A ( self			:       int		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Any           =							self.prepare_config_and_inputs()
												SCREAMING_SNAKE_CASE							:					Tuple           =							config_and_inputs
												SCREAMING_SNAKE_CASE							:					str           =							{'''input_ids''': input_ids, '''attention_mask''': attention_mask}
												return config, inputs_dict






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


						def  __A ( self			:       Any		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Union[str, Any]           =							FlaxDistilBertModelTester(self		)



						@slow
						def  __A ( self			:       Any		):





												'''simple docstring'''





												for model_class_name in self.all_model_classes:
																		SCREAMING_SNAKE_CASE							:					str           =							model_class_name.from_pretrained('''distilbert-base-uncased'''		)
																		SCREAMING_SNAKE_CASE							:					Dict           =							model(np.ones((1, 1)		)		)
																		self.assertIsNotNone(UpperCamelCase__		)






@require_flax
class       lowercase__		(     unittest.TestCase):


						@slow
						def  __A ( self			:       int		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Any           =							FlaxDistilBertModel.from_pretrained('''distilbert-base-uncased'''		)
												SCREAMING_SNAKE_CASE							:					List[Any]           =							np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]		)
												SCREAMING_SNAKE_CASE							:					Any           =							np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
												SCREAMING_SNAKE_CASE							:					Tuple           =							model(UpperCamelCase__					,	attention_mask=UpperCamelCase__		)[0]
												SCREAMING_SNAKE_CASE							:					Tuple           =							(1, 11, 768)
												self.assertEqual(output.shape					,	UpperCamelCase__		)
												SCREAMING_SNAKE_CASE							:					str           =							np.array([[[-0.1639, 0.3299, 0.1648], [-0.1746, 0.3289, 0.1710], [-0.1884, 0.3357, 0.1810]]]		)

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






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


__UpperCamelCase	: Tuple    		=  {
    'configuration_ctrl': ['CTRL_PRETRAINED_CONFIG_ARCHIVE_MAP', 'CTRLConfig'],
    'tokenization_ctrl': ['CTRLTokenizer'],
}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					__UpperCamelCase	: Dict    		=  [
					    'CTRL_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'CTRLForSequenceClassification',
					    'CTRLLMHeadModel',
					    'CTRLModel',
					    'CTRLPreTrainedModel',
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					__UpperCamelCase	: Any    		=  [
					    'TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'TFCTRLForSequenceClassification',
					    'TFCTRLLMHeadModel',
					    'TFCTRLModel',
					    'TFCTRLPreTrainedModel',
					]


if TYPE_CHECKING:
					from .configuration_ctrl import CTRL_PRETRAINED_CONFIG_ARCHIVE_MAP, CTRLConfig
					from .tokenization_ctrl import CTRLTokenizer

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_ctrl import (
										    CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
										    CTRLForSequenceClassification,
										    CTRLLMHeadModel,
										    CTRLModel,
										    CTRLPreTrainedModel,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_ctrl import (
										    TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFCTRLForSequenceClassification,
										    TFCTRLLMHeadModel,
										    TFCTRLModel,
										    TFCTRLPreTrainedModel,
										)

else:
					import sys

					__UpperCamelCase	: Optional[Any]    		=  _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





