import math
import os
import unittest

from transformers import MegatronBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import (
					    MODEL_FOR_PRETRAINING_MAPPING,
					    MegatronBertForCausalLM,
					    MegatronBertForMaskedLM,
					    MegatronBertForMultipleChoice,
					    MegatronBertForNextSentencePrediction,
					    MegatronBertForPreTraining,
					    MegatronBertForQuestionAnswering,
					    MegatronBertForSequenceClassification,
					    MegatronBertForTokenClassification,
					    MegatronBertModel,
					)






class 						A   :





							def __init__(      self				:							Optional[int]     ,		__a				:							Any     ,		__a				:							List[Any]=1_3     ,		__a				:							Any=7     ,		__a				:							str=True     ,		__a				:							Optional[Any]=True     ,		__a				:							Optional[Any]=True     ,		__a				:							Optional[int]=True     ,		__a				:							Optional[Any]=9_9     ,		__a				:							Any=6_4     ,		__a				:							Any=3_2     ,		__a				:							int=5     ,		__a				:							int=4     ,		__a				:							List[Any]=3_7     ,		__a				:							Optional[int]="gelu"     ,		__a				:							Optional[Any]=0.1     ,		__a				:							Union[str, Any]=0.1     ,		__a				:							str=5_1_2     ,		__a				:							List[Any]=1_6     ,		__a				:							Optional[int]=2     ,		__a				:							int=0.0_2     ,		__a				:							Dict=3     ,		__a				:							Optional[Any]=4     ,		__a				:							Any=None     ,		)							->	str:
								__UpperCAmelCase							=			parent
								__UpperCAmelCase							=			batch_size
								__UpperCAmelCase							=			seq_length
								__UpperCAmelCase							=			is_training
								__UpperCAmelCase							=			use_input_mask
								__UpperCAmelCase							=			use_token_type_ids
								__UpperCAmelCase							=			use_labels
								__UpperCAmelCase							=			vocab_size
								__UpperCAmelCase							=			hidden_size
								__UpperCAmelCase							=			embedding_size
								__UpperCAmelCase							=			num_hidden_layers
								__UpperCAmelCase							=			num_attention_heads
								__UpperCAmelCase							=			intermediate_size
								__UpperCAmelCase							=			hidden_act
								__UpperCAmelCase							=			hidden_dropout_prob
								__UpperCAmelCase							=			attention_probs_dropout_prob
								__UpperCAmelCase							=			max_position_embeddings
								__UpperCAmelCase							=			type_vocab_size
								__UpperCAmelCase							=			type_sequence_label_size
								__UpperCAmelCase							=			initializer_range
								__UpperCAmelCase							=			num_labels
								__UpperCAmelCase							=			num_choices
								__UpperCAmelCase							=			scope





							def       snake_case__						(      self				:							Optional[Any]	)							->	Union[str, Any]:
								__UpperCAmelCase							=			ids_tensor([self.batch_size, self.seq_length]     ,		self.vocab_size	)

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

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

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

								__UpperCAmelCase							=			self.get_config()

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





							def       snake_case__						(      self				:							List[str]	)							->	Dict:
								return MegatronBertConfig(
								    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     ,		embedding_size=self.embedding_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=__a     ,		initializer_range=self.initializer_range     ,		)





							def       snake_case__						(      self				:							List[Any]     ,		__a				:							Any     ,		__a				:							Optional[Any]     ,		__a				:							List[Any]     ,		__a				:							Dict     ,		__a				:							int     ,		__a				:							Optional[int]     ,		__a				:							Tuple	)							->	Union[str, Any]:
								__UpperCAmelCase							=			MegatronBertModel(config=__a	)
								model.to(__a	)
								model.eval()
								__UpperCAmelCase							=			model(__a     ,		attention_mask=__a     ,		token_type_ids=__a	)
								__UpperCAmelCase							=			model(__a     ,		token_type_ids=__a	)
								__UpperCAmelCase							=			model(__a	)

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





							def       snake_case__						(      self				:							int     ,		__a				:							Optional[Any]     ,		__a				:							int     ,		__a				:							List[str]     ,		__a				:							Union[str, Any]     ,		__a				:							Tuple     ,		__a				:							Any     ,		__a				:							List[Any]	)							->	Optional[int]:
								__UpperCAmelCase							=			MegatronBertForMaskedLM(config=__a	)
								model.to(__a	)
								model.eval()
								__UpperCAmelCase							=			model(__a     ,		attention_mask=__a     ,		token_type_ids=__a     ,		labels=__a	)
								self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, self.seq_length, self.vocab_size)	)





							def       snake_case__						(      self				:							Optional[Any]     ,		__a				:							Optional[int]     ,		__a				:							Optional[int]     ,		__a				:							Any     ,		__a				:							Any     ,		__a				:							Tuple     ,		__a				:							int     ,		__a				:							Optional[int]	)							->	List[Any]:
								__UpperCAmelCase							=			MegatronBertForCausalLM(config=__a	)
								model.to(__a	)
								model.eval()
								__UpperCAmelCase							=			model(__a     ,		attention_mask=__a     ,		token_type_ids=__a     ,		labels=__a	)
								self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, self.seq_length, self.vocab_size)	)





							def       snake_case__						(      self				:							Any     ,		__a				:							Tuple     ,		__a				:							Tuple     ,		__a				:							List[str]     ,		__a				:							Optional[int]     ,		__a				:							Union[str, Any]     ,		__a				:							Union[str, Any]     ,		__a				:							int	)							->	Tuple:
								__UpperCAmelCase							=			MegatronBertForNextSentencePrediction(config=__a	)
								model.to(__a	)
								model.eval()
								__UpperCAmelCase							=			model(
								    __a     ,		attention_mask=__a     ,		token_type_ids=__a     ,		labels=__a     ,		)
								self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, 2)	)





							def       snake_case__						(      self				:							List[Any]     ,		__a				:							Tuple     ,		__a				:							List[str]     ,		__a				:							Tuple     ,		__a				:							Tuple     ,		__a				:							Any     ,		__a				:							Optional[Any]     ,		__a				:							int	)							->	List[str]:
								__UpperCAmelCase							=			MegatronBertForPreTraining(config=__a	)
								model.to(__a	)
								model.eval()
								__UpperCAmelCase							=			model(
								    __a     ,		attention_mask=__a     ,		token_type_ids=__a     ,		labels=__a     ,		next_sentence_label=__a     ,		)
								self.parent.assertEqual(result.prediction_logits.shape     ,		(self.batch_size, self.seq_length, self.vocab_size)	)
								self.parent.assertEqual(result.seq_relationship_logits.shape     ,		(self.batch_size, 2)	)





							def       snake_case__						(      self				:							Dict     ,		__a				:							List[str]     ,		__a				:							Optional[Any]     ,		__a				:							Tuple     ,		__a				:							str     ,		__a				:							Dict     ,		__a				:							Optional[int]     ,		__a				:							Any	)							->	List[str]:
								__UpperCAmelCase							=			MegatronBertForQuestionAnswering(config=__a	)
								model.to(__a	)
								model.eval()
								__UpperCAmelCase							=			model(
								    __a     ,		attention_mask=__a     ,		token_type_ids=__a     ,		start_positions=__a     ,		end_positions=__a     ,		)
								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       snake_case__						(      self				:							str     ,		__a				:							Dict     ,		__a				:							List[Any]     ,		__a				:							str     ,		__a				:							Union[str, Any]     ,		__a				:							List[str]     ,		__a				:							Any     ,		__a				:							List[str]	)							->	int:
								__UpperCAmelCase							=			self.num_labels
								__UpperCAmelCase							=			MegatronBertForSequenceClassification(__a	)
								model.to(__a	)
								model.eval()
								__UpperCAmelCase							=			model(__a     ,		attention_mask=__a     ,		token_type_ids=__a     ,		labels=__a	)
								self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, self.num_labels)	)





							def       snake_case__						(      self				:							Union[str, Any]     ,		__a				:							List[Any]     ,		__a				:							List[Any]     ,		__a				:							Any     ,		__a				:							List[str]     ,		__a				:							Optional[int]     ,		__a				:							Optional[int]     ,		__a				:							Any	)							->	str:
								__UpperCAmelCase							=			self.num_labels
								__UpperCAmelCase							=			MegatronBertForTokenClassification(config=__a	)
								model.to(__a	)
								model.eval()
								__UpperCAmelCase							=			model(__a     ,		attention_mask=__a     ,		token_type_ids=__a     ,		labels=__a	)
								self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, self.seq_length, self.num_labels)	)





							def       snake_case__						(      self				:							Optional[int]     ,		__a				:							Any     ,		__a				:							List[Any]     ,		__a				:							Any     ,		__a				:							Dict     ,		__a				:							str     ,		__a				:							Union[str, Any]     ,		__a				:							Union[str, Any]	)							->	List[str]:
								__UpperCAmelCase							=			self.num_choices
								__UpperCAmelCase							=			MegatronBertForMultipleChoice(config=__a	)
								model.to(__a	)
								model.eval()
								__UpperCAmelCase							=			input_ids.unsqueeze(1	).expand(-1     ,		self.num_choices     ,		-1	).contiguous()
								__UpperCAmelCase							=			token_type_ids.unsqueeze(1	).expand(-1     ,		self.num_choices     ,		-1	).contiguous()
								__UpperCAmelCase							=			input_mask.unsqueeze(1	).expand(-1     ,		self.num_choices     ,		-1	).contiguous()
								__UpperCAmelCase							=			model(
								    __a     ,		attention_mask=__a     ,		token_type_ids=__a     ,		labels=__a     ,		)
								self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, self.num_choices)	)






							def       snake_case__						(      self				:							str	)							->	str:
								__UpperCAmelCase							=			self.prepare_config_and_inputs()
								(
								    (
								    __UpperCAmelCase			
								)				,			(
								    __UpperCAmelCase			
								)				,			(
								    __UpperCAmelCase			
								)				,			(
								    __UpperCAmelCase			
								)				,			(
								    __UpperCAmelCase			
								)				,			(
								    __UpperCAmelCase			
								)				,			(
								    __UpperCAmelCase			
								)				,						
								)							=			config_and_inputs
								__UpperCAmelCase							=			{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
								return config, inputs_dict






@require_torch
class 						A   (   UpperCAmelCase       ,	UpperCAmelCase       ,	unittest.TestCase   ):
							a_        =      (
							    (
							        MegatronBertModel,
							        MegatronBertForMaskedLM,
							        MegatronBertForCausalLM,
							        MegatronBertForMultipleChoice,
							        MegatronBertForNextSentencePrediction,
							        MegatronBertForPreTraining,
							        MegatronBertForQuestionAnswering,
							        MegatronBertForSequenceClassification,
							        MegatronBertForTokenClassification,
							    )
							    if is_torch_available()
							    else ()
							)
							a_        =      (
							    {
							        '''feature-extraction''': MegatronBertModel,
							        '''fill-mask''': MegatronBertForMaskedLM,
							        '''question-answering''': MegatronBertForQuestionAnswering,
							        '''text-classification''': MegatronBertForSequenceClassification,
							        '''text-generation''': MegatronBertForCausalLM,
							        '''token-classification''': MegatronBertForTokenClassification,
							        '''zero-shot''': MegatronBertForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							a_        =      True
							# test_resize_embeddings = False
							a_        =      False





							def       snake_case__						(      self				:							Any     ,		__a				:							List[Any]     ,		__a				:							Optional[int]     ,		__a				:							Optional[int]=False	)							->	Any:
								__UpperCAmelCase							=			super()._prepare_for_class(__a     ,		__a     ,		return_labels=__a	)

								if return_labels:
									if model_class in get_values(__a	):
										__UpperCAmelCase							=			torch.zeros(
										    (self.model_tester.batch_size, self.model_tester.seq_length)     ,		dtype=torch.long     ,		device=__a	)
										__UpperCAmelCase							=			torch.zeros(
										    self.model_tester.batch_size     ,		dtype=torch.long     ,		device=__a	)
								return inputs_dict





							def       snake_case__						(      self				:							List[str]	)							->	List[str]:
								__UpperCAmelCase							=			MegatronBertModelTester(self	)
								__UpperCAmelCase							=			ConfigTester(self     ,		config_class=__a     ,		hidden_size=3_7	)





							def       snake_case__						(      self				:							List[Any]	)							->	Optional[int]:
								self.config_tester.run_common_tests()





							def       snake_case__						(      self				:							List[str]	)							->	int:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_megatron_bert_model(*__a	)





							def       snake_case__						(      self				:							Any	)							->	Union[str, Any]:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_megatron_bert_for_masked_lm(*__a	)





							def       snake_case__						(      self				:							str	)							->	List[Any]:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_megatron_bert_for_multiple_choice(*__a	)





							def       snake_case__						(      self				:							Optional[int]	)							->	Dict:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_megatron_bert_for_next_sequence_prediction(*__a	)





							def       snake_case__						(      self				:							Tuple	)							->	Optional[int]:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_megatron_bert_for_pretraining(*__a	)





							def       snake_case__						(      self				:							Any	)							->	List[str]:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_megatron_bert_for_question_answering(*__a	)





							def       snake_case__						(      self				:							Dict	)							->	List[Any]:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_megatron_bert_for_sequence_classification(*__a	)






							def       snake_case__						(      self				:							List[str]	)							->	Union[str, Any]:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_megatron_bert_for_token_classification(*__a	)





def       lowerCAmelCase					(		UpperCamelCase__				:   Optional[Any]       ):


	"""simple docstring"""
	return torch.tensor(
	    UpperCamelCase__    ,					dtype=torch.long    ,					device=UpperCamelCase__    ,					)


__lowerCAmelCase	:       Optional[Any]						       =	1e-4






@require_torch
@require_sentencepiece
@require_tokenizers
class 						A   (   unittest.TestCase   ):





							@slow
							@unittest.skip('''Model is not available.'''	)
							def       snake_case__						(      self				:							Optional[int]	)							->	Union[str, Any]:
								__UpperCAmelCase							=			'''nvidia/megatron-bert-uncased-345m'''
								if "MYDIR" in os.environ:
									__UpperCAmelCase							=			os.path.join(os.environ['''MYDIR''']     ,		__a	)
								__UpperCAmelCase							=			MegatronBertModel.from_pretrained(__a	)
								model.to(__a	)
								model.half()
								__UpperCAmelCase							=			_long_tensor([[1_0_1, 7_1_1_0, 1_0_0_5, 1_0_5_6, 2_0_2_3, 1_1_3_3_3, 1_7_4_1_3, 1_0_2_9, 1_0_2]]	)
								with torch.no_grad():
									__UpperCAmelCase							=			model(__a	)[0]
								__UpperCAmelCase							=			torch.Size((1, 9, 1_0_2_4)	)
								self.assertEqual(output.shape     ,		__a	)

								__UpperCAmelCase							=			[-0.6_0_4_0, -0.2_5_1_7, -0.1_0_2_5, 0.3_4_2_0, -0.6_7_5_8, -0.0_0_1_7, -0.1_0_8_9, -0.1_9_9_0, 0.5_7_2_8]
								for ii in range(3	):
									for jj in range(3	):
										__UpperCAmelCase							=			output[0, ii, jj]
										__UpperCAmelCase							=			expected[3 * ii + jj]
										__UpperCAmelCase							=			'''ii={} jj={} a={} b={}'''.format(__a     ,		__a     ,		__a     ,		__a	)
										self.assertTrue(math.isclose(__a     ,		__a     ,		rel_tol=__a     ,		abs_tol=__a	)     ,		msg=__a	)

'''simple docstring'''


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   :





							def __init__(      self				:							List[Any]     ,		__a				:							Any     ,		)							->	Dict:
								__UpperCAmelCase							=			parent
								__UpperCAmelCase							=			1_3
								__UpperCAmelCase							=			7
								__UpperCAmelCase							=			True
								__UpperCAmelCase							=			True
								__UpperCAmelCase							=			False
								__UpperCAmelCase							=			True
								__UpperCAmelCase							=			9_9
								__UpperCAmelCase							=			3_2
								__UpperCAmelCase							=			2
								__UpperCAmelCase							=			4
								__UpperCAmelCase							=			3_7
								__UpperCAmelCase							=			'''gelu'''
								__UpperCAmelCase							=			0.1
								__UpperCAmelCase							=			0.1
								__UpperCAmelCase							=			5_1_2
								__UpperCAmelCase							=			1_6
								__UpperCAmelCase							=			2
								__UpperCAmelCase							=			0.0_2
								__UpperCAmelCase							=			3
								__UpperCAmelCase							=			4
								__UpperCAmelCase							=			None





							def       snake_case__						(      self				:							Optional[int]	)							->	Dict:
								__UpperCAmelCase							=			ids_tensor([self.batch_size, self.seq_length]     ,		self.vocab_size	)

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

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

								__UpperCAmelCase							=			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       snake_case__						(      self				:							Union[str, Any]     ,		__a				:							List[str]     ,		__a				:							int     ,		__a				:							Union[str, Any]     ,		__a				:							Union[str, Any]     ,		__a				:							List[Any]     ,		__a				:							int	)							->	Any:
								__UpperCAmelCase							=			TFDistilBertModel(config=__a	)
								__UpperCAmelCase							=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}

								__UpperCAmelCase							=			model(__a	)

								__UpperCAmelCase							=			[input_ids, input_mask]

								__UpperCAmelCase							=			model(__a	)

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





							def       snake_case__						(      self				:							Tuple     ,		__a				:							List[Any]     ,		__a				:							int     ,		__a				:							Tuple     ,		__a				:							List[Any]     ,		__a				:							Union[str, Any]     ,		__a				:							List[Any]	)							->	int:
								__UpperCAmelCase							=			TFDistilBertForMaskedLM(config=__a	)
								__UpperCAmelCase							=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
								__UpperCAmelCase							=			model(__a	)
								self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, self.seq_length, self.vocab_size)	)





							def       snake_case__						(      self				:							Optional[int]     ,		__a				:							Any     ,		__a				:							Union[str, Any]     ,		__a				:							Optional[int]     ,		__a				:							int     ,		__a				:							Optional[Any]     ,		__a				:							Optional[int]	)							->	Dict:
								__UpperCAmelCase							=			TFDistilBertForQuestionAnswering(config=__a	)
								__UpperCAmelCase							=			{
								    '''input_ids''': input_ids,
								    '''attention_mask''': input_mask,
								}
								__UpperCAmelCase							=			model(__a	)
								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       snake_case__						(      self				:							Any     ,		__a				:							Optional[Any]     ,		__a				:							List[str]     ,		__a				:							Dict     ,		__a				:							Dict     ,		__a				:							int     ,		__a				:							List[Any]	)							->	Dict:
								__UpperCAmelCase							=			self.num_labels
								__UpperCAmelCase							=			TFDistilBertForSequenceClassification(__a	)
								__UpperCAmelCase							=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
								__UpperCAmelCase							=			model(__a	)
								self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, self.num_labels)	)





							def       snake_case__						(      self				:							Union[str, Any]     ,		__a				:							int     ,		__a				:							str     ,		__a				:							Union[str, Any]     ,		__a				:							Optional[int]     ,		__a				:							List[str]     ,		__a				:							Dict	)							->	str:
								__UpperCAmelCase							=			self.num_choices
								__UpperCAmelCase							=			TFDistilBertForMultipleChoice(__a	)
								__UpperCAmelCase							=			tf.tile(tf.expand_dims(__a     ,		1	)     ,		(1, self.num_choices, 1)	)
								__UpperCAmelCase							=			tf.tile(tf.expand_dims(__a     ,		1	)     ,		(1, self.num_choices, 1)	)
								__UpperCAmelCase							=			{
								    '''input_ids''': multiple_choice_inputs_ids,
								    '''attention_mask''': multiple_choice_input_mask,
								}
								__UpperCAmelCase							=			model(__a	)
								self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, self.num_choices)	)





							def       snake_case__						(      self				:							int     ,		__a				:							Optional[Any]     ,		__a				:							int     ,		__a				:							Tuple     ,		__a				:							int     ,		__a				:							Optional[int]     ,		__a				:							Optional[int]	)							->	int:
								__UpperCAmelCase							=			self.num_labels
								__UpperCAmelCase							=			TFDistilBertForTokenClassification(__a	)
								__UpperCAmelCase							=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
								__UpperCAmelCase							=			model(__a	)
								self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, self.seq_length, self.num_labels)	)






							def       snake_case__						(      self				:							str	)							->	Any:
								__UpperCAmelCase							=			self.prepare_config_and_inputs()
								((__UpperCAmelCase)				,			(__UpperCAmelCase)				,			(__UpperCAmelCase)				,			(__UpperCAmelCase)				,			(__UpperCAmelCase)				,			(__UpperCAmelCase))							=			config_and_inputs
								__UpperCAmelCase							=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
								return config, inputs_dict






@require_tf
class 						A   (   UpperCAmelCase       ,	UpperCAmelCase       ,	unittest.TestCase   ):
							a_        =      (
							    (
							        TFDistilBertModel,
							        TFDistilBertForMaskedLM,
							        TFDistilBertForQuestionAnswering,
							        TFDistilBertForSequenceClassification,
							        TFDistilBertForTokenClassification,
							        TFDistilBertForMultipleChoice,
							    )
							    if is_tf_available()
							    else None
							)
							a_        =      (
							    {
							        '''feature-extraction''': TFDistilBertModel,
							        '''fill-mask''': TFDistilBertForMaskedLM,
							        '''question-answering''': TFDistilBertForQuestionAnswering,
							        '''text-classification''': TFDistilBertForSequenceClassification,
							        '''token-classification''': TFDistilBertForTokenClassification,
							        '''zero-shot''': TFDistilBertForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)
							a_        =      False
							a_        =      False





							def       snake_case__						(      self				:							Any	)							->	Any:
								__UpperCAmelCase							=			TFDistilBertModelTester(self	)
								__UpperCAmelCase							=			ConfigTester(self     ,		config_class=__a     ,		dim=3_7	)





							def       snake_case__						(      self				:							List[Any]	)							->	Optional[int]:
								self.config_tester.run_common_tests()





							def       snake_case__						(      self				:							Any	)							->	str:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_model(*__a	)





							def       snake_case__						(      self				:							Tuple	)							->	Dict:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_for_masked_lm(*__a	)





							def       snake_case__						(      self				:							Union[str, Any]	)							->	Any:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_for_question_answering(*__a	)





							def       snake_case__						(      self				:							Optional[Any]	)							->	Dict:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_for_sequence_classification(*__a	)





							def       snake_case__						(      self				:							Any	)							->	int:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_for_multiple_choice(*__a	)





							def       snake_case__						(      self				:							List[str]	)							->	List[Any]:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_for_token_classification(*__a	)






							@slow
							def       snake_case__						(      self				:							Dict	)							->	Tuple:
								for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]	):
									__UpperCAmelCase							=			TFDistilBertModel.from_pretrained(__a	)
									self.assertIsNotNone(__a	)






@require_tf
class 						A   (   unittest.TestCase   ):





							@slow
							def       snake_case__						(      self				:							int	)							->	Dict:
								__UpperCAmelCase							=			TFDistilBertModel.from_pretrained('''distilbert-base-uncased'''	)
								__UpperCAmelCase							=			tf.constant([[0, 1, 2, 3, 4, 5]]	)
								__UpperCAmelCase							=			model(__a	)[0]

								__UpperCAmelCase							=			[1, 6, 7_6_8]
								self.assertEqual(output.shape     ,		__a	)

								__UpperCAmelCase							=			tf.constant(
								    [
								        [
								            [0.1_9_2_6_1_8_8_5, -0.1_3_7_3_2_9_5_5, 0.4_1_1_9_7_9_9],
								            [0.2_2_1_5_0_1_5_6, -0.0_7_4_2_2_6_6_1, 0.3_9_0_3_7_2_0_4],
								            [0.2_2_7_5_6_0_1_8, -0.0_8_9_6_4_1_4, 0.3_7_0_1_4_6_7],
								        ]
								    ]	)
								tf.debugging.assert_near(output[:, :3, :3]     ,		__a     ,		atol=1e-4	)
