

from __future__ import annotations

import unittest

from transformers import DistilBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
	import tensorflow as tf

	from transformers.models.distilbert.modeling_tf_distilbert import (
	    TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
	    TFDistilBertForMaskedLM,
	    TFDistilBertForMultipleChoice,
	    TFDistilBertForQuestionAnswering,
	    TFDistilBertForSequenceClassification,
	    TFDistilBertForTokenClassification,
	    TFDistilBertModel,
	)

class     a__  :
			"""simple docstring"""







			def __init__(			self					,					lowercase					,					)     ->  List[Any]:
							'''simple docstring'''






							A__						=	parent
							A__						=	13
							A__						=	7
							A__						=	True
							A__						=	True
							A__						=	False
							A__						=	True
							A__						=	99
							A__						=	32
							A__						=	2
							A__						=	4
							A__						=	37
							A__						=	"gelu"
							A__						=	0.1
							A__						=	0.1
							A__						=	512
							A__						=	16
							A__						=	2
							A__						=	0.02
							A__						=	3
							A__						=	4
							A__						=	None


			def    UpperCamelCase						(			self				)     ->  str:
							'''simple docstring'''






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

							A__						=	None
							if self.use_input_mask:
											A__						=	random_attention_mask([self.batch_size, self.seq_length]				)

							A__						=	None
							A__						=	None
							A__						=	None
							if self.use_labels:
											A__						=	ids_tensor([self.batch_size]					,					self.type_sequence_label_size				)
											A__						=	ids_tensor([self.batch_size, self.seq_length]					,					self.num_labels				)
											A__						=	ids_tensor([self.batch_size]					,					self.num_choices				)

							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					,					)

							return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels


			def    UpperCamelCase						(			self					,					lowercase					,					lowercase					,					lowercase					,					lowercase					,					lowercase					,					lowercase				)     ->  int:
							'''simple docstring'''






							A__						=	TFDistilBertModel(config=lowercase				)
							A__						=	{"input_ids": input_ids, "attention_mask": input_mask}

							A__						=	model(lowercase				)

							A__						=	[input_ids, input_mask]

							A__						=	model(lowercase				)

							self.parent.assertEqual(result.last_hidden_state.shape					,					(self.batch_size, self.seq_length, self.hidden_size)				)


			def    UpperCamelCase						(			self					,					lowercase					,					lowercase					,					lowercase					,					lowercase					,					lowercase					,					lowercase				)     ->  Optional[Any]:
							'''simple docstring'''






							A__						=	TFDistilBertForMaskedLM(config=lowercase				)
							A__						=	{"input_ids": input_ids, "attention_mask": input_mask}
							A__						=	model(lowercase				)
							self.parent.assertEqual(result.logits.shape					,					(self.batch_size, self.seq_length, self.vocab_size)				)


			def    UpperCamelCase						(			self					,					lowercase					,					lowercase					,					lowercase					,					lowercase					,					lowercase					,					lowercase				)     ->  str:
							'''simple docstring'''






							A__						=	TFDistilBertForQuestionAnswering(config=lowercase				)
							A__						=	{
							    "input_ids": input_ids,
							    "attention_mask": input_mask,
							}
							A__						=	model(lowercase				)
							self.parent.assertEqual(result.start_logits.shape					,					(self.batch_size, self.seq_length)				)
							self.parent.assertEqual(result.end_logits.shape					,					(self.batch_size, self.seq_length)				)


			def    UpperCamelCase						(			self					,					lowercase					,					lowercase					,					lowercase					,					lowercase					,					lowercase					,					lowercase				)     ->  List[str]:
							'''simple docstring'''






							A__						=	self.num_labels
							A__						=	TFDistilBertForSequenceClassification(lowercase				)
							A__						=	{"input_ids": input_ids, "attention_mask": input_mask}
							A__						=	model(lowercase				)
							self.parent.assertEqual(result.logits.shape					,					(self.batch_size, self.num_labels)				)


			def    UpperCamelCase						(			self					,					lowercase					,					lowercase					,					lowercase					,					lowercase					,					lowercase					,					lowercase				)     ->  int:
							'''simple docstring'''






							A__						=	self.num_choices
							A__						=	TFDistilBertForMultipleChoice(lowercase				)
							A__						=	tf.tile(tf.expand_dims(lowercase					,					1				)					,					(1, self.num_choices, 1)				)
							A__						=	tf.tile(tf.expand_dims(lowercase					,					1				)					,					(1, self.num_choices, 1)				)
							A__						=	{
							    "input_ids": multiple_choice_inputs_ids,
							    "attention_mask": multiple_choice_input_mask,
							}
							A__						=	model(lowercase				)
							self.parent.assertEqual(result.logits.shape					,					(self.batch_size, self.num_choices)				)


			def    UpperCamelCase						(			self					,					lowercase					,					lowercase					,					lowercase					,					lowercase					,					lowercase					,					lowercase				)     ->  int:
							'''simple docstring'''






							A__						=	self.num_labels
							A__						=	TFDistilBertForTokenClassification(lowercase				)
							A__						=	{"input_ids": input_ids, "attention_mask": input_mask}
							A__						=	model(lowercase				)
							self.parent.assertEqual(result.logits.shape					,					(self.batch_size, self.seq_length, self.num_labels)				)


			def    UpperCamelCase						(			self				)     ->  List[Any]:
							'''simple docstring'''






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

@require_tf
class     a__  (    snake_case							,		snake_case							,		unittest.TestCase	):
			"""simple docstring"""







			__lowerCamelCase       				=				(
			    (
			        TFDistilBertModel,
			        TFDistilBertForMaskedLM,
			        TFDistilBertForQuestionAnswering,
			        TFDistilBertForSequenceClassification,
			        TFDistilBertForTokenClassification,
			        TFDistilBertForMultipleChoice,
			    )
			    if is_tf_available()
			    else None
			)
			__lowerCamelCase       				=				(
			    {
			        'feature-extraction': TFDistilBertModel,
			        'fill-mask': TFDistilBertForMaskedLM,
			        'question-answering': TFDistilBertForQuestionAnswering,
			        'text-classification': TFDistilBertForSequenceClassification,
			        'token-classification': TFDistilBertForTokenClassification,
			        'zero-shot': TFDistilBertForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)
			__lowerCamelCase       				=				False
			__lowerCamelCase       				=				False


			def    UpperCamelCase						(			self				)     ->  List[str]:
							'''simple docstring'''






							A__						=	TFDistilBertModelTester(self				)
							A__						=	ConfigTester(self					,					config_class=lowercase					,					dim=37				)


			def    UpperCamelCase						(			self				)     ->  Dict:
							'''simple docstring'''






							self.config_tester.run_common_tests()


			def    UpperCamelCase						(			self				)     ->  Tuple:
							'''simple docstring'''






							A__						=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_model(*lowercase				)


			def    UpperCamelCase						(			self				)     ->  Optional[Any]:
							'''simple docstring'''






							A__						=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_masked_lm(*lowercase				)


			def    UpperCamelCase						(			self				)     ->  Union[str, Any]:
							'''simple docstring'''






							A__						=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_question_answering(*lowercase				)


			def    UpperCamelCase						(			self				)     ->  str:
							'''simple docstring'''






							A__						=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_sequence_classification(*lowercase				)


			def    UpperCamelCase						(			self				)     ->  List[str]:
							'''simple docstring'''






							A__						=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_multiple_choice(*lowercase				)


			def    UpperCamelCase						(			self				)     ->  Tuple:
							'''simple docstring'''






							A__						=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_token_classification(*lowercase				)


			@slow
			def    UpperCamelCase						(			self				)     ->  str:
							'''simple docstring'''






							for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]				):
											A__						=	TFDistilBertModel.from_pretrained(lowercase				)
											self.assertIsNotNone(lowercase				)

@require_tf
class     a__  (    unittest.TestCase	):
			"""simple docstring"""







			@slow
			def    UpperCamelCase						(			self				)     ->  List[Any]:
							'''simple docstring'''






							A__						=	TFDistilBertModel.from_pretrained("distilbert-base-uncased"				)
							A__						=	tf.constant([[0, 1, 2, 3, 4, 5]]				)
							A__						=	model(lowercase				)[0]

							A__						=	[1, 6, 768]
							self.assertEqual(output.shape					,					lowercase				)

							A__						=	tf.constant(
							    [
							        [
							            [0.1926_1885, -0.1373_2955, 0.411_9799],
							            [0.2215_0156, -0.0742_2661, 0.3903_7204],
							            [0.2275_6018, -0.089_6414, 0.370_1467],
							        ]
							    ]				)
							tf.debugging.assert_near(output[:, :3, :3]					,					lowercase					,					atol=1e-4				)


def       A	(    _lowercase		,  _lowercase		,  _lowercase						):
						return round(float(moles / volume						) * nfactor						)
def       A	(    _lowercase		,  _lowercase		,  _lowercase						):
						return round(float((moles * 0.0821 * temperature) / (volume)						)						)
def       A	(    _lowercase		,  _lowercase		,  _lowercase						):
						return round(float((moles * 0.0821 * temperature) / (pressure)						)						)
def       A	(    _lowercase		,  _lowercase		,  _lowercase						):
						return round(float((pressure * volume) / (0.0821 * moles)						)						)


if __name__ == "__main__":
					import doctest

					doctest.testmod()





