"""simple docstring"""



import os
import tempfile
import unittest

from transformers import DistilBertConfig, is_torch_available
from transformers.testing_utils import require_torch, require_torch_gpu, 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 (
				    DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    DistilBertForMaskedLM,
				    DistilBertForMultipleChoice,
				    DistilBertForQuestionAnswering,
				    DistilBertForSequenceClassification,
				    DistilBertForTokenClassification,
				    DistilBertModel,
				)
class 						__UpperCAmelCase    (A__     ):







			'''simple docstring'''





			def __init__(			self   ,      snake_case_   ,      snake_case_=13   ,      snake_case_=7   ,      snake_case_=True   ,      snake_case_=True   ,      snake_case_=False   ,      snake_case_=True   ,      snake_case_=99   ,      snake_case_=32   ,      snake_case_=5   ,      snake_case_=4   ,      snake_case_=37   ,      snake_case_="gelu"   ,      snake_case_=0.1   ,      snake_case_=0.1   ,      snake_case_=512   ,      snake_case_=16   ,      snake_case_=2   ,      snake_case_=0.02   ,      snake_case_=3   ,      snake_case_=4   ,      snake_case_=None   ,      ):







										'''simple docstring'''


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





			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										A__       :     Union[str, Any]								=			ids_tensor([self.batch_size, self.seq_length]   ,      self.vocab_size							)

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

										A__       :     Any								=			None
										A__       :     Tuple								=			None
										A__       :     str								=			None
										if self.use_labels:
																	A__       :     Any								=			ids_tensor([self.batch_size]   ,      self.type_sequence_label_size							)
																	A__       :     Optional[Any]								=			ids_tensor([self.batch_size, self.seq_length]   ,      self.num_labels							)
																	A__       :     int								=			ids_tensor([self.batch_size]   ,      self.num_choices							)

										A__       :     List[Any]								=			self.get_config()

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





			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


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





			def 		lowerCamelCase					(			self   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_							):







										'''simple docstring'''


										A__       :     int								=			DistilBertModel(config=__UpperCAmelCase							)
										model.to(__UpperCAmelCase							)
										model.eval()
										A__       :     Optional[int]								=			model(__UpperCAmelCase   ,      __UpperCAmelCase							)
										A__       :     Union[str, Any]								=			model(__UpperCAmelCase							)
										self.parent.assertEqual(result.last_hidden_state.shape   ,      (self.batch_size, self.seq_length, self.hidden_size)							)





			def 		lowerCamelCase					(			self   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_							):







										'''simple docstring'''


										A__       :     List[str]								=			DistilBertForMaskedLM(config=__UpperCAmelCase							)
										model.to(__UpperCAmelCase							)
										model.eval()
										A__       :     Optional[Any]								=			model(__UpperCAmelCase   ,      attention_mask=__UpperCAmelCase   ,      labels=__UpperCAmelCase							)
										self.parent.assertEqual(result.logits.shape   ,      (self.batch_size, self.seq_length, self.vocab_size)							)





			def 		lowerCamelCase					(			self   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_							):







										'''simple docstring'''


										A__       :     Tuple								=			DistilBertForQuestionAnswering(config=__UpperCAmelCase							)
										model.to(__UpperCAmelCase							)
										model.eval()
										A__       :     Dict								=			model(
										    __UpperCAmelCase   ,      attention_mask=__UpperCAmelCase   ,      start_positions=__UpperCAmelCase   ,      end_positions=__UpperCAmelCase							)
										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 		lowerCamelCase					(			self   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_							):







										'''simple docstring'''


										A__       :     Any								=			self.num_labels
										A__       :     List[str]								=			DistilBertForSequenceClassification(__UpperCAmelCase							)
										model.to(__UpperCAmelCase							)
										model.eval()
										A__       :     Dict								=			model(__UpperCAmelCase   ,      attention_mask=__UpperCAmelCase   ,      labels=__UpperCAmelCase							)
										self.parent.assertEqual(result.logits.shape   ,      (self.batch_size, self.num_labels)							)





			def 		lowerCamelCase					(			self   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_							):







										'''simple docstring'''


										A__       :     Dict								=			self.num_labels
										A__       :     Optional[int]								=			DistilBertForTokenClassification(config=__UpperCAmelCase							)
										model.to(__UpperCAmelCase							)
										model.eval()

										A__       :     int								=			model(__UpperCAmelCase   ,      attention_mask=__UpperCAmelCase   ,      labels=__UpperCAmelCase							)
										self.parent.assertEqual(result.logits.shape   ,      (self.batch_size, self.seq_length, self.num_labels)							)





			def 		lowerCamelCase					(			self   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_   ,      snake_case_							):







										'''simple docstring'''


										A__       :     List[str]								=			self.num_choices
										A__       :     Tuple								=			DistilBertForMultipleChoice(config=__UpperCAmelCase							)
										model.to(__UpperCAmelCase							)
										model.eval()
										A__       :     int								=			input_ids.unsqueeze(1							).expand(-1   ,      self.num_choices   ,      -1							).contiguous()
										A__       :     Tuple								=			input_mask.unsqueeze(1							).expand(-1   ,      self.num_choices   ,      -1							).contiguous()
										A__       :     Dict								=			model(
										    __UpperCAmelCase   ,      attention_mask=__UpperCAmelCase   ,      labels=__UpperCAmelCase   ,      )
										self.parent.assertEqual(result.logits.shape   ,      (self.batch_size, self.num_choices)							)





			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


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





@require_torch
class 						__UpperCAmelCase    (A__							,   A__							,   unittest.TestCase     ):







			'''simple docstring'''
			_UpperCamelCase  :						str					     =				(
			    (
			        DistilBertModel,
			        DistilBertForMaskedLM,
			        DistilBertForMultipleChoice,
			        DistilBertForQuestionAnswering,
			        DistilBertForSequenceClassification,
			        DistilBertForTokenClassification,
			    )
			    if is_torch_available()
			    else None
			)
			_UpperCamelCase  :						List[Any]					     =				(
			    {
			        'feature-extraction': DistilBertModel,
			        'fill-mask': DistilBertForMaskedLM,
			        'question-answering': DistilBertForQuestionAnswering,
			        'text-classification': DistilBertForSequenceClassification,
			        'token-classification': DistilBertForTokenClassification,
			        'zero-shot': DistilBertForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			_UpperCamelCase  :						Union[str, Any]					     =				True
			_UpperCamelCase  :						Optional[Any]					     =				True
			_UpperCamelCase  :						int					     =				True
			_UpperCamelCase  :						List[str]					     =				True





			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										A__       :     Tuple								=			DistilBertModelTester(self							)
										A__       :     List[Any]								=			ConfigTester(self   ,      config_class=__UpperCAmelCase   ,      dim=37							)





			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										self.config_tester.run_common_tests()





			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										A__       :     Optional[int]								=			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_distilbert_model(*__UpperCAmelCase							)





			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										A__       :     Dict								=			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_distilbert_for_masked_lm(*__UpperCAmelCase							)





			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										A__       :     List[Any]								=			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_distilbert_for_question_answering(*__UpperCAmelCase							)





			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										A__       :     Optional[int]								=			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_distilbert_for_sequence_classification(*__UpperCAmelCase							)





			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										A__       :     Any								=			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_distilbert_for_token_classification(*__UpperCAmelCase							)





			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										A__       :     Union[str, Any]								=			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_distilbert_for_multiple_choice(*__UpperCAmelCase							)





			@slow
			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										for model_name in DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	A__       :     List[Any]								=			DistilBertModel.from_pretrained(__UpperCAmelCase							)
																	self.assertIsNotNone(__UpperCAmelCase							)





			@slow
			@require_torch_gpu
			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										A__				,							A__       :     int								=			self.model_tester.prepare_config_and_inputs_for_common()
										for model_class in self.all_model_classes:
																	# BertForMultipleChoice behaves incorrectly in JIT environments.
																	if model_class == DistilBertForMultipleChoice:
																								return

																	A__       :     List[Any]								=			True
																	A__       :     str								=			model_class(config=__UpperCAmelCase							)

																	A__       :     List[Any]								=			self._prepare_for_class(__UpperCAmelCase   ,      __UpperCAmelCase							)
																	A__       :     Optional[Any]								=			torch.jit.trace(
																	    __UpperCAmelCase   ,      (inputs_dict["""input_ids"""].to("""cpu"""							), inputs_dict["""attention_mask"""].to("""cpu"""							))							)

																	with tempfile.TemporaryDirectory() as tmp:
																								torch.jit.save(__UpperCAmelCase   ,      os.path.join(__UpperCAmelCase   ,      """traced_model.pt"""							)							)
																								A__       :     Any								=			torch.jit.load(os.path.join(__UpperCAmelCase   ,      """traced_model.pt"""							)   ,      map_location=__UpperCAmelCase							)
																								loaded(inputs_dict["""input_ids"""].to(__UpperCAmelCase							)   ,      inputs_dict["""attention_mask"""].to(__UpperCAmelCase							)							)





@require_torch
class 						__UpperCAmelCase    (unittest.TestCase     ):







			'''simple docstring'''





			@slow
			def 		lowerCamelCase					(			self							):







										'''simple docstring'''


										A__       :     List[Any]								=			DistilBertModel.from_pretrained("""distilbert-base-uncased"""							)
										A__       :     Union[str, Any]								=			torch.tensor([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]							)
										A__       :     List[Any]								=			torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]							)
										with torch.no_grad():
																	A__       :     Any								=			model(__UpperCAmelCase   ,      attention_mask=__UpperCAmelCase							)[0]
										A__       :     Tuple								=			torch.Size((1, 11, 768)							)
										self.assertEqual(output.shape   ,      __UpperCAmelCase							)
										A__       :     Dict								=			torch.tensor(
										    [[[-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(torch.allclose(output[:, 1:4, 1:4]   ,      __UpperCAmelCase   ,      atol=1E-4							)							)








"""simple docstring"""




def 						A							(  snake_case__     ):




			'''simple docstring'''


			SCREAMING_SNAKE_CASE__										=   1
			SCREAMING_SNAKE_CASE__										=   2
			while i * i <= n:
						SCREAMING_SNAKE_CASE__										=   0
						while n % i == 0:
									n //= i
									multiplicity += 1
						n_divisors *= multiplicity + 1
						i += 1
			if n > 1:
						n_divisors *= 2
			return n_divisors

def 						A							(  ):




			'''simple docstring'''


			SCREAMING_SNAKE_CASE__										=   1
			SCREAMING_SNAKE_CASE__										=   1

			while True:
						i += 1
						t_num += i

						if count_divisors(snake_case__     ) > 5_00:
									break

			return t_num


if __name__ == "__main__":
						print(solution())


