"""simple docstring"""





from collections import OrderedDict

from ...utils import logging
from .auto_factory import _BaseAutoModelClass, _LazyAutoMapping, auto_class_update
from .configuration_auto import CONFIG_MAPPING_NAMES


_UpperCamelCase     :		Tuple											=					logging.get_logger(__name__)


_UpperCamelCase     :		Tuple											=					OrderedDict(
    [
        # Base model mapping
        ("albert", "FlaxAlbertModel"),
        ("bart", "FlaxBartModel"),
        ("beit", "FlaxBeitModel"),
        ("bert", "FlaxBertModel"),
        ("big_bird", "FlaxBigBirdModel"),
        ("blenderbot", "FlaxBlenderbotModel"),
        ("blenderbot-small", "FlaxBlenderbotSmallModel"),
        ("clip", "FlaxCLIPModel"),
        ("distilbert", "FlaxDistilBertModel"),
        ("electra", "FlaxElectraModel"),
        ("gpt-sw3", "FlaxGPT2Model"),
        ("gpt2", "FlaxGPT2Model"),
        ("gpt_neo", "FlaxGPTNeoModel"),
        ("gptj", "FlaxGPTJModel"),
        ("longt5", "FlaxLongT5Model"),
        ("marian", "FlaxMarianModel"),
        ("mbart", "FlaxMBartModel"),
        ("mt5", "FlaxMT5Model"),
        ("opt", "FlaxOPTModel"),
        ("pegasus", "FlaxPegasusModel"),
        ("regnet", "FlaxRegNetModel"),
        ("resnet", "FlaxResNetModel"),
        ("roberta", "FlaxRobertaModel"),
        ("roberta-prelayernorm", "FlaxRobertaPreLayerNormModel"),
        ("roformer", "FlaxRoFormerModel"),
        ("t5", "FlaxT5Model"),
        ("vision-text-dual-encoder", "FlaxVisionTextDualEncoderModel"),
        ("vit", "FlaxViTModel"),
        ("wav2vec2", "FlaxWav2Vec2Model"),
        ("whisper", "FlaxWhisperModel"),
        ("xglm", "FlaxXGLMModel"),
        ("xlm-roberta", "FlaxXLMRobertaModel"),
    ]
)

_UpperCamelCase     :		str											=					OrderedDict(
    [
        # Model for pre-training mapping
        ("albert", "FlaxAlbertForPreTraining"),
        ("bart", "FlaxBartForConditionalGeneration"),
        ("bert", "FlaxBertForPreTraining"),
        ("big_bird", "FlaxBigBirdForPreTraining"),
        ("electra", "FlaxElectraForPreTraining"),
        ("longt5", "FlaxLongT5ForConditionalGeneration"),
        ("mbart", "FlaxMBartForConditionalGeneration"),
        ("mt5", "FlaxMT5ForConditionalGeneration"),
        ("roberta", "FlaxRobertaForMaskedLM"),
        ("roberta-prelayernorm", "FlaxRobertaPreLayerNormForMaskedLM"),
        ("roformer", "FlaxRoFormerForMaskedLM"),
        ("t5", "FlaxT5ForConditionalGeneration"),
        ("wav2vec2", "FlaxWav2Vec2ForPreTraining"),
        ("whisper", "FlaxWhisperForConditionalGeneration"),
        ("xlm-roberta", "FlaxXLMRobertaForMaskedLM"),
    ]
)

_UpperCamelCase     :		int											=					OrderedDict(
    [
        # Model for Masked LM mapping
        ("albert", "FlaxAlbertForMaskedLM"),
        ("bart", "FlaxBartForConditionalGeneration"),
        ("bert", "FlaxBertForMaskedLM"),
        ("big_bird", "FlaxBigBirdForMaskedLM"),
        ("distilbert", "FlaxDistilBertForMaskedLM"),
        ("electra", "FlaxElectraForMaskedLM"),
        ("mbart", "FlaxMBartForConditionalGeneration"),
        ("roberta", "FlaxRobertaForMaskedLM"),
        ("roberta-prelayernorm", "FlaxRobertaPreLayerNormForMaskedLM"),
        ("roformer", "FlaxRoFormerForMaskedLM"),
        ("xlm-roberta", "FlaxXLMRobertaForMaskedLM"),
    ]
)

_UpperCamelCase     :		List[Any]											=					OrderedDict(
    [
        # Model for Seq2Seq Causal LM mapping
        ("bart", "FlaxBartForConditionalGeneration"),
        ("blenderbot", "FlaxBlenderbotForConditionalGeneration"),
        ("blenderbot-small", "FlaxBlenderbotSmallForConditionalGeneration"),
        ("encoder-decoder", "FlaxEncoderDecoderModel"),
        ("longt5", "FlaxLongT5ForConditionalGeneration"),
        ("marian", "FlaxMarianMTModel"),
        ("mbart", "FlaxMBartForConditionalGeneration"),
        ("mt5", "FlaxMT5ForConditionalGeneration"),
        ("pegasus", "FlaxPegasusForConditionalGeneration"),
        ("t5", "FlaxT5ForConditionalGeneration"),
    ]
)

_UpperCamelCase     :		Optional[int]											=					OrderedDict(
    [
        # Model for Image-classsification
        ("beit", "FlaxBeitForImageClassification"),
        ("regnet", "FlaxRegNetForImageClassification"),
        ("resnet", "FlaxResNetForImageClassification"),
        ("vit", "FlaxViTForImageClassification"),
    ]
)

_UpperCamelCase     :		List[str]											=					OrderedDict(
    [
        ("vision-encoder-decoder", "FlaxVisionEncoderDecoderModel"),
    ]
)

_UpperCamelCase     :		List[Any]											=					OrderedDict(
    [
        # Model for Causal LM mapping
        ("bart", "FlaxBartForCausalLM"),
        ("bert", "FlaxBertForCausalLM"),
        ("big_bird", "FlaxBigBirdForCausalLM"),
        ("electra", "FlaxElectraForCausalLM"),
        ("gpt-sw3", "FlaxGPT2LMHeadModel"),
        ("gpt2", "FlaxGPT2LMHeadModel"),
        ("gpt_neo", "FlaxGPTNeoForCausalLM"),
        ("gptj", "FlaxGPTJForCausalLM"),
        ("opt", "FlaxOPTForCausalLM"),
        ("roberta", "FlaxRobertaForCausalLM"),
        ("roberta-prelayernorm", "FlaxRobertaPreLayerNormForCausalLM"),
        ("xglm", "FlaxXGLMForCausalLM"),
        ("xlm-roberta", "FlaxXLMRobertaForCausalLM"),
    ]
)

_UpperCamelCase     :		Optional[Any]											=					OrderedDict(
    [
        # Model for Sequence Classification mapping
        ("albert", "FlaxAlbertForSequenceClassification"),
        ("bart", "FlaxBartForSequenceClassification"),
        ("bert", "FlaxBertForSequenceClassification"),
        ("big_bird", "FlaxBigBirdForSequenceClassification"),
        ("distilbert", "FlaxDistilBertForSequenceClassification"),
        ("electra", "FlaxElectraForSequenceClassification"),
        ("mbart", "FlaxMBartForSequenceClassification"),
        ("roberta", "FlaxRobertaForSequenceClassification"),
        ("roberta-prelayernorm", "FlaxRobertaPreLayerNormForSequenceClassification"),
        ("roformer", "FlaxRoFormerForSequenceClassification"),
        ("xlm-roberta", "FlaxXLMRobertaForSequenceClassification"),
    ]
)

_UpperCamelCase     :		Optional[int]											=					OrderedDict(
    [
        # Model for Question Answering mapping
        ("albert", "FlaxAlbertForQuestionAnswering"),
        ("bart", "FlaxBartForQuestionAnswering"),
        ("bert", "FlaxBertForQuestionAnswering"),
        ("big_bird", "FlaxBigBirdForQuestionAnswering"),
        ("distilbert", "FlaxDistilBertForQuestionAnswering"),
        ("electra", "FlaxElectraForQuestionAnswering"),
        ("mbart", "FlaxMBartForQuestionAnswering"),
        ("roberta", "FlaxRobertaForQuestionAnswering"),
        ("roberta-prelayernorm", "FlaxRobertaPreLayerNormForQuestionAnswering"),
        ("roformer", "FlaxRoFormerForQuestionAnswering"),
        ("xlm-roberta", "FlaxXLMRobertaForQuestionAnswering"),
    ]
)

_UpperCamelCase     :		Tuple											=					OrderedDict(
    [
        # Model for Token Classification mapping
        ("albert", "FlaxAlbertForTokenClassification"),
        ("bert", "FlaxBertForTokenClassification"),
        ("big_bird", "FlaxBigBirdForTokenClassification"),
        ("distilbert", "FlaxDistilBertForTokenClassification"),
        ("electra", "FlaxElectraForTokenClassification"),
        ("roberta", "FlaxRobertaForTokenClassification"),
        ("roberta-prelayernorm", "FlaxRobertaPreLayerNormForTokenClassification"),
        ("roformer", "FlaxRoFormerForTokenClassification"),
        ("xlm-roberta", "FlaxXLMRobertaForTokenClassification"),
    ]
)

_UpperCamelCase     :		str											=					OrderedDict(
    [
        # Model for Multiple Choice mapping
        ("albert", "FlaxAlbertForMultipleChoice"),
        ("bert", "FlaxBertForMultipleChoice"),
        ("big_bird", "FlaxBigBirdForMultipleChoice"),
        ("distilbert", "FlaxDistilBertForMultipleChoice"),
        ("electra", "FlaxElectraForMultipleChoice"),
        ("roberta", "FlaxRobertaForMultipleChoice"),
        ("roberta-prelayernorm", "FlaxRobertaPreLayerNormForMultipleChoice"),
        ("roformer", "FlaxRoFormerForMultipleChoice"),
        ("xlm-roberta", "FlaxXLMRobertaForMultipleChoice"),
    ]
)

_UpperCamelCase     :		Optional[int]											=					OrderedDict(
    [
        ("bert", "FlaxBertForNextSentencePrediction"),
    ]
)

_UpperCamelCase     :		Optional[int]											=					OrderedDict(
    [
        ("speech-encoder-decoder", "FlaxSpeechEncoderDecoderModel"),
        ("whisper", "FlaxWhisperForConditionalGeneration"),
    ]
)

_UpperCamelCase     :		List[Any]											=					OrderedDict(
    [
        ("whisper", "FlaxWhisperForAudioClassification"),
    ]
)

_UpperCamelCase     :		str											=					_LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_MAPPING_NAMES)
_UpperCamelCase     :		str											=					_LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_PRETRAINING_MAPPING_NAMES)
_UpperCamelCase     :		str											=					_LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_MASKED_LM_MAPPING_NAMES)
_UpperCamelCase     :		Dict											=					_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES
)
_UpperCamelCase     :		Optional[int]											=					_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES
)
_UpperCamelCase     :		Tuple											=					_LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES)
_UpperCamelCase     :		str											=					_LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_CAUSAL_LM_MAPPING_NAMES)
_UpperCamelCase     :		Tuple											=					_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES
)
_UpperCamelCase     :		Optional[Any]											=					_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES
)
_UpperCamelCase     :		Optional[Any]											=					_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES
)
_UpperCamelCase     :		Union[str, Any]											=					_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING_NAMES
)
_UpperCamelCase     :		List[str]											=					_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING_NAMES
)
_UpperCamelCase     :		str											=					_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES
)
_UpperCamelCase     :		str											=					_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES
)


class   UpperCAmelCase_			(					_BaseAutoModelClass):
      lowerCamelCase__	:					Union[str, Any]										=						FLAX_MODEL_MAPPING





_UpperCamelCase     :		Optional[Any]											=					auto_class_update(FlaxAutoModel)


class   UpperCAmelCase_			(					_BaseAutoModelClass):
      lowerCamelCase__	:					Optional[int]										=						FLAX_MODEL_FOR_PRETRAINING_MAPPING





_UpperCamelCase     :		Tuple											=					auto_class_update(FlaxAutoModelForPreTraining, head_doc="pretraining")


class   UpperCAmelCase_			(					_BaseAutoModelClass):
      lowerCamelCase__	:					str										=						FLAX_MODEL_FOR_CAUSAL_LM_MAPPING





_UpperCamelCase     :		Union[str, Any]											=					auto_class_update(FlaxAutoModelForCausalLM, head_doc="causal language modeling")


class   UpperCAmelCase_			(					_BaseAutoModelClass):
      lowerCamelCase__	:					Any										=						FLAX_MODEL_FOR_MASKED_LM_MAPPING





_UpperCamelCase     :		str											=					auto_class_update(FlaxAutoModelForMaskedLM, head_doc="masked language modeling")


class   UpperCAmelCase_			(					_BaseAutoModelClass):
      lowerCamelCase__	:					Optional[int]										=						FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING





_UpperCamelCase     :		Tuple											=					auto_class_update(
    FlaxAutoModelForSeqaSeqLM, head_doc="sequence-to-sequence language modeling", checkpoint_for_example="t5-base"
)


class   UpperCAmelCase_			(					_BaseAutoModelClass):
      lowerCamelCase__	:					Union[str, Any]										=						FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING





_UpperCamelCase     :		Optional[Any]											=					auto_class_update(
    FlaxAutoModelForSequenceClassification, head_doc="sequence classification"
)


class   UpperCAmelCase_			(					_BaseAutoModelClass):
      lowerCamelCase__	:					str										=						FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING





_UpperCamelCase     :		Union[str, Any]											=					auto_class_update(FlaxAutoModelForQuestionAnswering, head_doc="question answering")


class   UpperCAmelCase_			(					_BaseAutoModelClass):
      lowerCamelCase__	:					Tuple										=						FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING





_UpperCamelCase     :		Optional[Any]											=					auto_class_update(
    FlaxAutoModelForTokenClassification, head_doc="token classification"
)


class   UpperCAmelCase_			(					_BaseAutoModelClass):
      lowerCamelCase__	:					Any										=						FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING





_UpperCamelCase     :		List[Any]											=					auto_class_update(FlaxAutoModelForMultipleChoice, head_doc="multiple choice")


class   UpperCAmelCase_			(					_BaseAutoModelClass):
      lowerCamelCase__	:					Optional[int]										=						FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING





_UpperCamelCase     :		List[Any]											=					auto_class_update(
    FlaxAutoModelForNextSentencePrediction, head_doc="next sentence prediction"
)


class   UpperCAmelCase_			(					_BaseAutoModelClass):
      lowerCamelCase__	:					Optional[int]										=						FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING





_UpperCamelCase     :		int											=					auto_class_update(
    FlaxAutoModelForImageClassification, head_doc="image classification"
)


class   UpperCAmelCase_			(					_BaseAutoModelClass):
      lowerCamelCase__	:					Union[str, Any]										=						FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING





_UpperCamelCase     :		Union[str, Any]											=					auto_class_update(FlaxAutoModelForVisionaSeq, head_doc="vision-to-text modeling")


class   UpperCAmelCase_			(					_BaseAutoModelClass):
      lowerCamelCase__	:					List[str]										=						FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING





_UpperCamelCase     :		Optional[int]											=					auto_class_update(
    FlaxAutoModelForSpeechSeqaSeq, head_doc="sequence-to-sequence speech-to-text modeling"
)


"""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):


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


      def 	_UpperCAmelCase (     self							) ->      Any:
             lowercase__    :	List[Any]     					=			ids_tensor([self.batch_size, self.seq_length]	,    self.vocab_size							)

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

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

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

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


      def 	_UpperCAmelCase (     self							) ->      Optional[int]:
             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 	_UpperCAmelCase (     self	,    a	,    a	,    a	,    a	,    a	,    a							) ->      Dict:
             lowercase__    :	Tuple     					=			DistilBertModel(config=a							)
             model.to(a							)
             model.eval()
             lowercase__    :	Any     					=			model(a	,    a							)
             lowercase__    :	str     					=			model(a							)
             self.parent.assertEqual(result.last_hidden_state.shape	,    (self.batch_size, self.seq_length, self.hidden_size)							)


      def 	_UpperCAmelCase (     self	,    a	,    a	,    a	,    a	,    a	,    a							) ->      Dict:
             lowercase__    :	Optional[int]     					=			DistilBertForMaskedLM(config=a							)
             model.to(a							)
             model.eval()
             lowercase__    :	Union[str, Any]     					=			model(a	,    attention_mask=a	,    labels=a							)
             self.parent.assertEqual(result.logits.shape	,    (self.batch_size, self.seq_length, self.vocab_size)							)


      def 	_UpperCAmelCase (     self	,    a	,    a	,    a	,    a	,    a	,    a							) ->      int:
             lowercase__    :	Tuple     					=			DistilBertForQuestionAnswering(config=a							)
             model.to(a							)
             model.eval()
             lowercase__    :	Tuple     					=			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 	_UpperCAmelCase (     self	,    a	,    a	,    a	,    a	,    a	,    a							) ->      List[str]:
             lowercase__    :	int     					=			self.num_labels
             lowercase__    :	Dict     					=			DistilBertForSequenceClassification(a							)
             model.to(a							)
             model.eval()
             lowercase__    :	Optional[Any]     					=			model(a	,    attention_mask=a	,    labels=a							)
             self.parent.assertEqual(result.logits.shape	,    (self.batch_size, self.num_labels)							)


      def 	_UpperCAmelCase (     self	,    a	,    a	,    a	,    a	,    a	,    a							) ->      Any:
             lowercase__    :	Any     					=			self.num_labels
             lowercase__    :	List[str]     					=			DistilBertForTokenClassification(config=a							)
             model.to(a							)
             model.eval()

             lowercase__    :	Any     					=			model(a	,    attention_mask=a	,    labels=a							)
             self.parent.assertEqual(result.logits.shape	,    (self.batch_size, self.seq_length, self.num_labels)							)


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


      def 	_UpperCAmelCase (     self							) ->      str:
             lowercase__    :	Union[str, Any]     					=			self.prepare_config_and_inputs()
             ((lowercase__)					,   (lowercase__)					,   (lowercase__)					,   (lowercase__)					,   (lowercase__)					,   (lowercase__))    :	List[str]     					=			config_and_inputs
             lowercase__    :	Optional[Any]     					=			{'input_ids': input_ids, 'attention_mask': input_mask}
             return config, inputs_dict





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


      def 	_UpperCAmelCase (     self							) ->      Union[str, Any]:
             lowercase__    :	str     					=			DistilBertModelTester(self							)
             lowercase__    :	int     					=			ConfigTester(self	,    config_class=a	,    dim=3_7							)


      def 	_UpperCAmelCase (     self							) ->      Dict:
             self.config_tester.run_common_tests()


      def 	_UpperCAmelCase (     self							) ->      Optional[Any]:
             lowercase__    :	int     					=			self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_distilbert_model(*a							)


      def 	_UpperCAmelCase (     self							) ->      Any:
             lowercase__    :	int     					=			self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_distilbert_for_masked_lm(*a							)


      def 	_UpperCAmelCase (     self							) ->      Optional[int]:
             lowercase__    :	str     					=			self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_distilbert_for_question_answering(*a							)


      def 	_UpperCAmelCase (     self							) ->      int:
             lowercase__    :	List[str]     					=			self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_distilbert_for_sequence_classification(*a							)


      def 	_UpperCAmelCase (     self							) ->      List[str]:
             lowercase__    :	Dict     					=			self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_distilbert_for_token_classification(*a							)


      def 	_UpperCAmelCase (     self							) ->      str:
             lowercase__    :	Any     					=			self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_distilbert_for_multiple_choice(*a							)


      @slow
      def 	_UpperCAmelCase (     self							) ->      str:
             for model_name in DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                    lowercase__    :	str     					=			DistilBertModel.from_pretrained(a							)
                    self.assertIsNotNone(a							)


      @slow
      @require_torch_gpu
      def 	_UpperCAmelCase (     self							) ->      Any:
             lowercase__					,   lowercase__    :	Dict     					=			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

                    lowercase__    :	Optional[int]     					=			True
                    lowercase__    :	Union[str, Any]     					=			model_class(config=a							)

                    lowercase__    :	int     					=			self._prepare_for_class(a	,    a							)
                    lowercase__    :	Tuple     					=			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'							)							)
                           lowercase__    :	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   UpperCAmelCase_			(					unittest.TestCase):


      @slow
      def 	_UpperCAmelCase (     self							) ->      List[str]:
             lowercase__    :	int     					=			DistilBertModel.from_pretrained('distilbert-base-uncased'							)
             lowercase__    :	Union[str, Any]     					=			torch.tensor([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]]							)
             lowercase__    :	Optional[Any]     					=			torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]							)
             with torch.no_grad():
                    lowercase__    :	Optional[Any]     					=			model(a	,    attention_mask=a							)[0]
             lowercase__    :	Tuple     					=			torch.Size((1, 1_1, 7_6_8)							)
             self.assertEqual(output.shape	,    a							)
             lowercase__    :	List[Any]     					=			torch.tensor(
                 [[[-0.1_639, 0.3_299, 0.1_648], [-0.1_746, 0.3_289, 0.1_710], [-0.1_884, 0.3_357, 0.1_810]]]							)

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

