



"""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 					a	(  _UpperCamelCase       ):



  def __init__(						self :					List[str]       ,		lowerCAmelCase :					str       ,		lowerCAmelCase :					Union[str, Any]=13       ,		lowerCAmelCase :					int=7       ,		lowerCAmelCase :					Optional[int]=True       ,		lowerCAmelCase :					List[str]=True       ,		lowerCAmelCase :					List[str]=False       ,		lowerCAmelCase :					Optional[int]=True       ,		lowerCAmelCase :					List[Any]=99       ,		lowerCAmelCase :					Union[str, Any]=32       ,		lowerCAmelCase :					Optional[int]=5       ,		lowerCAmelCase :					Union[str, Any]=4       ,		lowerCAmelCase :					List[str]=37       ,		lowerCAmelCase :					Optional[int]="gelu"       ,		lowerCAmelCase :					Any=0.1       ,		lowerCAmelCase :					List[Any]=0.1       ,		lowerCAmelCase :					Union[str, Any]=512       ,		lowerCAmelCase :					Tuple=16       ,		lowerCAmelCase :					Union[str, Any]=2       ,		lowerCAmelCase :					List[Any]=0.0_2       ,		lowerCAmelCase :					Tuple=3       ,		lowerCAmelCase :					Dict=4       ,		lowerCAmelCase :					List[Any]=None       ,		)     ->					Any:


     '''simple docstring'''




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



  def 	lowerCamelCase__       (						self :					List[str]		)     ->					Tuple:


     '''simple docstring'''




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

     SCREAMING_SNAKE_CASE_: Union[str, Any]     			=None
     if self.use_input_mask:
        SCREAMING_SNAKE_CASE_: Optional[Any]     			=random_attention_mask([self.batch_size, self.seq_length]		)

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

     SCREAMING_SNAKE_CASE_: Optional[int]     			=self.get_config()

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



  def 	lowerCamelCase__       (						self :					Optional[int]		)     ->					int:


     '''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 :					Union[str, Any]       ,		lowerCAmelCase :					Any       ,		lowerCAmelCase :					str       ,		lowerCAmelCase :					int       ,		lowerCAmelCase :					List[Any]       ,		lowerCAmelCase :					int       ,		lowerCAmelCase :					Any		)     ->					str:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Any     			=DistilBertModel(config=__a		)
     model.to(__a		)
     model.eval()
     SCREAMING_SNAKE_CASE_: Dict     			=model(__a       ,		__a		)
     SCREAMING_SNAKE_CASE_: str     			=model(__a		)
     self.parent.assertEqual(result.last_hidden_state.shape       ,		(self.batch_size, self.seq_length, self.hidden_size)		)



  def 	lowerCamelCase__       (						self :					Tuple       ,		lowerCAmelCase :					int       ,		lowerCAmelCase :					Optional[Any]       ,		lowerCAmelCase :					List[Any]       ,		lowerCAmelCase :					List[str]       ,		lowerCAmelCase :					Optional[Any]       ,		lowerCAmelCase :					Any		)     ->					int:


     '''simple docstring'''




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



  def 	lowerCamelCase__       (						self :					Optional[int]       ,		lowerCAmelCase :					Tuple       ,		lowerCAmelCase :					Tuple       ,		lowerCAmelCase :					int       ,		lowerCAmelCase :					Dict       ,		lowerCAmelCase :					Tuple       ,		lowerCAmelCase :					Optional[Any]		)     ->					Optional[Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Union[str, Any]     			=DistilBertForQuestionAnswering(config=__a		)
     model.to(__a		)
     model.eval()
     SCREAMING_SNAKE_CASE_: Union[str, Any]     			=model(
         __a       ,		attention_mask=__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 	lowerCamelCase__       (						self :					Union[str, Any]       ,		lowerCAmelCase :					int       ,		lowerCAmelCase :					Any       ,		lowerCAmelCase :					Optional[int]       ,		lowerCAmelCase :					Optional[int]       ,		lowerCAmelCase :					int       ,		lowerCAmelCase :					List[str]		)     ->					Optional[int]:


     '''simple docstring'''




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



  def 	lowerCamelCase__       (						self :					Union[str, Any]       ,		lowerCAmelCase :					Optional[int]       ,		lowerCAmelCase :					Any       ,		lowerCAmelCase :					str       ,		lowerCAmelCase :					Optional[Any]       ,		lowerCAmelCase :					Tuple       ,		lowerCAmelCase :					Dict		)     ->					str:


     '''simple docstring'''




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

     SCREAMING_SNAKE_CASE_: Optional[int]     			=model(__a       ,		attention_mask=__a       ,		labels=__a		)
     self.parent.assertEqual(result.logits.shape       ,		(self.batch_size, self.seq_length, self.num_labels)		)



  def 	lowerCamelCase__       (						self :					Dict       ,		lowerCAmelCase :					List[Any]       ,		lowerCAmelCase :					int       ,		lowerCAmelCase :					Dict       ,		lowerCAmelCase :					str       ,		lowerCAmelCase :					Union[str, Any]       ,		lowerCAmelCase :					Union[str, Any]		)     ->					Optional[int]:


     '''simple docstring'''




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





  def 	lowerCamelCase__       (						self :					Union[str, Any]		)     ->					Union[str, Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Any     			=self.prepare_config_and_inputs()
     (SCREAMING_SNAKE_CASE_): List[str]     			=config_and_inputs
     SCREAMING_SNAKE_CASE_: Tuple     			={"input_ids": input_ids, "attention_mask": input_mask}
     return config, inputs_dict







@require_torch
class 					a	(  _UpperCamelCase	,      _UpperCamelCase	,      unittest.TestCase       ):
  UpperCamelCase	:				Any     						=					(
      (
          DistilBertModel,
          DistilBertForMaskedLM,
          DistilBertForMultipleChoice,
          DistilBertForQuestionAnswering,
          DistilBertForSequenceClassification,
          DistilBertForTokenClassification,
      )
      if is_torch_available()
      else None
  )
  UpperCamelCase	:				Dict     						=					(
      {
          "feature-extraction": DistilBertModel,
          "fill-mask": DistilBertForMaskedLM,
          "question-answering": DistilBertForQuestionAnswering,
          "text-classification": DistilBertForSequenceClassification,
          "token-classification": DistilBertForTokenClassification,
          "zero-shot": DistilBertForSequenceClassification,
      }
      if is_torch_available()
      else {}
  )
  UpperCamelCase	:				List[str]     						=					True
  UpperCamelCase	:				Optional[int]     						=					True
  UpperCamelCase	:				Optional[Any]     						=					True
  UpperCamelCase	:				str     						=					True



  def 	lowerCamelCase__       (						self :					Any		)     ->					Tuple:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Tuple     			=DistilBertModelTester(self		)
     SCREAMING_SNAKE_CASE_: Optional[Any]     			=ConfigTester(self       ,		config_class=__a       ,		dim=37		)



  def 	lowerCamelCase__       (						self :					Optional[Any]		)     ->					Dict:


     '''simple docstring'''




     self.config_tester.run_common_tests()



  def 	lowerCamelCase__       (						self :					List[str]		)     ->					Tuple:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: str     			=self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_distilbert_model(*__a		)



  def 	lowerCamelCase__       (						self :					List[Any]		)     ->					Optional[int]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Optional[Any]     			=self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_distilbert_for_masked_lm(*__a		)



  def 	lowerCamelCase__       (						self :					str		)     ->					List[Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: List[Any]     			=self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_distilbert_for_question_answering(*__a		)



  def 	lowerCamelCase__       (						self :					List[str]		)     ->					List[str]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: List[str]     			=self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_distilbert_for_sequence_classification(*__a		)



  def 	lowerCamelCase__       (						self :					List[str]		)     ->					Any:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Dict     			=self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_distilbert_for_token_classification(*__a		)



  def 	lowerCamelCase__       (						self :					Tuple		)     ->					Dict:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Optional[Any]     			=self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_distilbert_for_multiple_choice(*__a		)



  @slow
  def 	lowerCamelCase__       (						self :					str		)     ->					str:


     '''simple docstring'''




     for model_name in DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        SCREAMING_SNAKE_CASE_: Optional[int]     			=DistilBertModel.from_pretrained(__a		)
        self.assertIsNotNone(__a		)





  @slow
  @require_torch_gpu
  def 	lowerCamelCase__       (						self :					str		)     ->					Tuple:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: str     			=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

        SCREAMING_SNAKE_CASE_: Tuple     			=True
        SCREAMING_SNAKE_CASE_: Tuple     			=model_class(config=__a		)

        SCREAMING_SNAKE_CASE_: int     			=self._prepare_for_class(__a       ,		__a		)
        SCREAMING_SNAKE_CASE_: str     			=torch.jit.trace(
            __a       ,		(inputs_dict["""input_ids"""].to("""cpu"""		), inputs_dict["""attention_mask"""].to("""cpu"""		))		)

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







@require_torch
class 					a	(  unittest.TestCase       ):



  @slow
  def 	lowerCamelCase__       (						self :					str		)     ->					Union[str, Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: List[Any]     			=DistilBertModel.from_pretrained("""distilbert-base-uncased"""		)
     SCREAMING_SNAKE_CASE_: int     			=torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]		)
     SCREAMING_SNAKE_CASE_: Any     			=torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
     with torch.no_grad():
        SCREAMING_SNAKE_CASE_: Any     			=model(__a       ,		attention_mask=__a		)[0]
     SCREAMING_SNAKE_CASE_: str     			=torch.Size((1, 11, 768)		)
     self.assertEqual(output.shape       ,		__a		)
     SCREAMING_SNAKE_CASE_: Optional[int]     			=torch.tensor(
         [[[-0.1_6_3_9, 0.3_2_9_9, 0.1_6_4_8], [-0.1_7_4_6, 0.3_2_8_9, 0.1_7_1_0], [-0.1_8_8_4, 0.3_3_5_7, 0.1_8_1_0]]]		)

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








"""simple docstring"""
from math import pi





def      __magic_name__				(							lowercase							,			lowercase ):
   return 2 * pi * radius * (angle / 360)


if __name__ == "__main__":
   print(arc_length(9_0, 1_0))



