





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




					def 		lowerCAmelCase     (						self					)						->							Any:
										_snake_case													=			ids_tensor([self.batch_size, self.seq_length]			,  self.vocab_size					)

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

										_snake_case													=			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_=lowerCAmelCase_			,  )

										return config, input_ids, attention_mask






					def 		lowerCAmelCase     (						self					)						->							Dict:
										_snake_case													=			self.prepare_config_and_inputs()
										_snake_case							,       _snake_case							,       _snake_case													=			config_and_inputs
										_snake_case													=			{'input_ids': input_ids, 'attention_mask': attention_mask}
										return config, inputs_dict





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




					def 		lowerCAmelCase     (						self					)						->							str:
										_snake_case													=			FlaxDistilBertModelTester(self					)






					@slow
					def 		lowerCAmelCase     (						self					)						->							Any:
										for model_class_name in self.all_model_classes:
															_snake_case													=			model_class_name.from_pretrained('distilbert-base-uncased'					)
															_snake_case													=			model(np.ones((1, 1)					)					)
															self.assertIsNotNone(lowerCAmelCase_					)





@require_flax
class      UpperCamelCase_						(					unittest.TestCase   ):




					@slow
					def 		lowerCAmelCase     (						self					)						->							int:
										_snake_case													=			FlaxDistilBertModel.from_pretrained('distilbert-base-uncased'					)
										_snake_case													=			np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]					)
										_snake_case													=			np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]					)
										_snake_case													=			model(lowerCAmelCase_			,  attention_mask=lowerCAmelCase_					)[0]
										_snake_case													=			(1, 11, 768)
										self.assertEqual(output.shape			,  lowerCAmelCase_					)
										_snake_case													=			np.array([[[-0.16_39, 0.32_99, 0.16_48], [-0.17_46, 0.32_89, 0.17_10], [-0.18_84, 0.33_57, 0.18_10]]]					)

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










import warnings

from ...utils import logging
from .image_processing_flava import FlavaImageProcessor


UpperCAmelCase_ 							=       logging.get_logger(__name__)
class      UpperCamelCase_						(					_lowerCamelCase   ):




					def __init__(						self			,  *lowerCAmelCase_			,  **lowerCAmelCase_					)						->							None:
										warnings.warn(
										    'The class FlavaFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please'
										    ' use FlavaImageProcessor instead.'			,  lowerCAmelCase_			,  )
										super().__init__(*lowerCAmelCase_			,  **lowerCAmelCase_					)



