'''simple docstring'''




import importlib
import inspect
import json
import os
from collections import OrderedDict

# Build the list of all feature extractors
from ...configuration_utils import PretrainedConfig
from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code
from ...feature_extraction_utils import FeatureExtractionMixin
from ...image_processing_utils import ImageProcessingMixin
from ...tokenization_utils import TOKENIZER_CONFIG_FILE
from ...utils import FEATURE_EXTRACTOR_NAME, get_file_from_repo, logging
from .auto_factory import _LazyAutoMapping
from .configuration_auto import (
    CONFIG_MAPPING_NAMES,
    AutoConfig,
    model_type_to_module_name,
    replace_list_option_in_docstrings,
)
from .feature_extraction_auto import AutoFeatureExtractor
from .image_processing_auto import AutoImageProcessor
from .tokenization_auto import AutoTokenizer


__SCREAMING_SNAKE_CASE :  Optional[int]  =						logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE :  Dict  =						OrderedDict(
    [
        ("""align""", """AlignProcessor"""),
        ("""altclip""", """AltCLIPProcessor"""),
        ("""bark""", """BarkProcessor"""),
        ("""blip""", """BlipProcessor"""),
        ("""blip-2""", """Blip2Processor"""),
        ("""bridgetower""", """BridgeTowerProcessor"""),
        ("""chinese_clip""", """ChineseCLIPProcessor"""),
        ("""clap""", """ClapProcessor"""),
        ("""clip""", """CLIPProcessor"""),
        ("""clipseg""", """CLIPSegProcessor"""),
        ("""flava""", """FlavaProcessor"""),
        ("""git""", """GitProcessor"""),
        ("""groupvit""", """CLIPProcessor"""),
        ("""hubert""", """Wav2Vec2Processor"""),
        ("""instructblip""", """InstructBlipProcessor"""),
        ("""layoutlmv2""", """LayoutLMv2Processor"""),
        ("""layoutlmv3""", """LayoutLMv3Processor"""),
        ("""markuplm""", """MarkupLMProcessor"""),
        ("""mctct""", """MCTCTProcessor"""),
        ("""mgp-str""", """MgpstrProcessor"""),
        ("""oneformer""", """OneFormerProcessor"""),
        ("""owlvit""", """OwlViTProcessor"""),
        ("""pix2struct""", """Pix2StructProcessor"""),
        ("""sam""", """SamProcessor"""),
        ("""sew""", """Wav2Vec2Processor"""),
        ("""sew-d""", """Wav2Vec2Processor"""),
        ("""speech_to_text""", """Speech2TextProcessor"""),
        ("""speech_to_text_2""", """Speech2Text2Processor"""),
        ("""speecht5""", """SpeechT5Processor"""),
        ("""trocr""", """TrOCRProcessor"""),
        ("""tvlt""", """TvltProcessor"""),
        ("""unispeech""", """Wav2Vec2Processor"""),
        ("""unispeech-sat""", """Wav2Vec2Processor"""),
        ("""vilt""", """ViltProcessor"""),
        ("""vision-text-dual-encoder""", """VisionTextDualEncoderProcessor"""),
        ("""wav2vec2""", """Wav2Vec2Processor"""),
        ("""wav2vec2-conformer""", """Wav2Vec2Processor"""),
        ("""wavlm""", """Wav2Vec2Processor"""),
        ("""whisper""", """WhisperProcessor"""),
        ("""xclip""", """XCLIPProcessor"""),
    ]
)

__SCREAMING_SNAKE_CASE :  List[Any]  =						_LazyAutoMapping(CONFIG_MAPPING_NAMES, PROCESSOR_MAPPING_NAMES)

def 			UpperCamelCase_							(      _UpperCAmelCase						:   str					)					->					str:


       """simple docstring"""







       for module_name, processors in PROCESSOR_MAPPING_NAMES.items():
              if class_name in processors:
                     _UpperCAmelCase  :						int							   =					model_type_to_module_name(_UpperCAmelCase					)

                     _UpperCAmelCase  :						Tuple							   =					importlib.import_module(F""".{module_name}"""    ,			"transformers.models"					)
                     try:
                            return getattr(_UpperCAmelCase    ,			_UpperCAmelCase					)
                     except AttributeError:
                            continue

       for processor in PROCESSOR_MAPPING._extra_content.values():
              if getattr(_UpperCAmelCase    ,			"__name__"    ,			_UpperCAmelCase					) == class_name:
                     return processor

    # We did not fine the class, but maybe it's because a dep is missing. In that case, the class will be in the main
    # init and we return the proper dummy to get an appropriate error message.
       _UpperCAmelCase  :						Any							   =					importlib.import_module("transformers"					)
       if hasattr(_UpperCAmelCase    ,			_UpperCAmelCase					):
              return getattr(_UpperCAmelCase    ,			_UpperCAmelCase					)

       return None


class 			lowerCamelCase_			:
      '''simple docstring'''

      def __init__( self		:       int ):
             raise EnvironmentError(
                 "AutoProcessor is designed to be instantiated "
                 "using the `AutoProcessor.from_pretrained(pretrained_model_name_or_path)` method." )




      @classmethod
      @replace_list_option_in_docstrings(A )
      def   _A			( cls		:       Any		,      A		:       Any		,      **A		:       Dict ):
             _UpperCAmelCase  :						Any							   =					kwargs.pop("config"		,      A )
             _UpperCAmelCase  :						Tuple							   =					kwargs.pop("trust_remote_code"		,      A )
             _UpperCAmelCase  :						Dict							   =					True

             _UpperCAmelCase  :						Optional[Any]							   =					None
             _UpperCAmelCase  :						int							   =					None

             # First, let's see if we have a preprocessor config.
             # Filter the kwargs for `get_file_from_repo`.
             _UpperCAmelCase  :						List[str]							   =					{
                 key: kwargs[key] for key in inspect.signature(A ).parameters.keys() if key in kwargs
             }
             # Let's start by checking whether the processor class is saved in an image processor
             _UpperCAmelCase  :						str							   =					get_file_from_repo(
                 A		,      A		,      **A )
             if preprocessor_config_file is not None:
                    _UpperCAmelCase   ,						_UpperCAmelCase  :						str							   =					ImageProcessingMixin.get_image_processor_dict(A		,      **A )
                    _UpperCAmelCase  :						Dict							   =					config_dict.get("processor_class"		,      A )
                    if "AutoProcessor" in config_dict.get("auto_map"		,      {} ):
                           _UpperCAmelCase  :						List[str]							   =					config_dict["auto_map"]["AutoProcessor"]

        # If not found, let's check whether the processor class is saved in a feature extractor config
             if preprocessor_config_file is not None and processor_class is None:
                    _UpperCAmelCase   ,						_UpperCAmelCase  :						Union[str, Any]							   =					FeatureExtractionMixin.get_feature_extractor_dict(A		,      **A )
                    _UpperCAmelCase  :						Optional[Any]							   =					config_dict.get("processor_class"		,      A )
                    if "AutoProcessor" in config_dict.get("auto_map"		,      {} ):
                           _UpperCAmelCase  :						str							   =					config_dict["auto_map"]["AutoProcessor"]

             if processor_class is None:
                    # Next, let's check whether the processor class is saved in a tokenizer
                    _UpperCAmelCase  :						int							   =					get_file_from_repo(
                        A		,      A		,      **A )
                    if tokenizer_config_file is not None:
                           with open(A		,      encoding="utf-8" ) as reader:
                                  _UpperCAmelCase  :						Tuple							   =					json.load(A )

                           _UpperCAmelCase  :						Optional[int]							   =					config_dict.get("processor_class"		,      A )
                           if "AutoProcessor" in config_dict.get("auto_map"		,      {} ):
                                  _UpperCAmelCase  :						Optional[Any]							   =					config_dict["auto_map"]["AutoProcessor"]

             if processor_class is None:
                    # Otherwise, load config, if it can be loaded.
                    if not isinstance(A		,      A ):
                           _UpperCAmelCase  :						List[Any]							   =					AutoConfig.from_pretrained(
                               A		,      trust_remote_code=A		,      **A )

                    # And check if the config contains the processor class.
                    _UpperCAmelCase  :						Tuple							   =					getattr(A		,      "processor_class"		,      A )
                    if hasattr(A		,      "auto_map" ) and "AutoProcessor" in config.auto_map:
                           _UpperCAmelCase  :						str							   =					config.auto_map["AutoProcessor"]

             if processor_class is not None:
                    _UpperCAmelCase  :						Optional[Any]							   =					processor_class_from_name(A )

             _UpperCAmelCase  :						Optional[Any]							   =					processor_auto_map is not None
             _UpperCAmelCase  :						Union[str, Any]							   =					processor_class is not None or type(A ) in PROCESSOR_MAPPING
             _UpperCAmelCase  :						Tuple							   =					resolve_trust_remote_code(
                 A		,      A		,      A		,      A )

             if has_remote_code and trust_remote_code:
                    _UpperCAmelCase  :						List[str]							   =					get_class_from_dynamic_module(
                        A		,      A		,      **A )
                    _UpperCAmelCase  :						Any							   =					kwargs.pop("code_revision"		,      A )
                    if os.path.isdir(A ):
                           processor_class.register_for_auto_class()
                    return processor_class.from_pretrained(
                        A		,      trust_remote_code=A		,      **A )
             elif processor_class is not None:
                    return processor_class.from_pretrained(
                        A		,      trust_remote_code=A		,      **A )
             # Last try: we use the PROCESSOR_MAPPING.
             elif type(A ) in PROCESSOR_MAPPING:
                    return PROCESSOR_MAPPING[type(A )].from_pretrained(A		,      **A )

             # At this stage, there doesn't seem to be a `Processor` class available for this model, so let's try a
             # tokenizer.
             try:
                    return AutoTokenizer.from_pretrained(
                        A		,      trust_remote_code=A		,      **A )
             except Exception:
                    try:
                           return AutoImageProcessor.from_pretrained(
                               A		,      trust_remote_code=A		,      **A )
                    except Exception:
                           pass

                    try:
                           return AutoFeatureExtractor.from_pretrained(
                               A		,      trust_remote_code=A		,      **A )
                    except Exception:
                           pass

             raise ValueError(
                 F"""Unrecognized processing class in {pretrained_model_name_or_path}. Can't instantiate a processor, a """
                 "tokenizer, an image processor or a feature extractor for this model. Make sure the repository contains"
                 "the files of at least one of those processing classes." )





      @staticmethod
      def   _A			( A		:       Any		,      A		:       Optional[Any] ):
             PROCESSOR_MAPPING.register(A		,      A )


'''simple docstring'''




import unittest

from transformers import ElectraConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

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


if is_torch_available():
  import torch

  from transformers import (
      MODEL_FOR_PRETRAINING_MAPPING,
      ElectraForCausalLM,
      ElectraForMaskedLM,
      ElectraForMultipleChoice,
      ElectraForPreTraining,
      ElectraForQuestionAnswering,
      ElectraForSequenceClassification,
      ElectraForTokenClassification,
      ElectraModel,
  )
  from transformers.models.electra.modeling_electra import ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST

class 			lowerCamelCase_			:
      '''simple docstring'''

      def __init__( self		:       Dict		,      A		:       Union[str, Any]		,      A		:       int=13		,      A		:       List[str]=7		,      A		:       Tuple=True		,      A		:       Optional[Any]=True		,      A		:       Tuple=True		,      A		:       List[str]=True		,      A		:       List[str]=99		,      A		:       List[Any]=32		,      A		:       List[str]=5		,      A		:       Dict=4		,      A		:       str=37		,      A		:       str="gelu"		,      A		:       int=0.1		,      A		:       List[str]=0.1		,      A		:       List[str]=512		,      A		:       Optional[int]=16		,      A		:       List[Any]=2		,      A		:       Optional[Any]=0.02		,      A		:       Optional[int]=3		,      A		:       List[Any]=4		,      A		:       int=None		,      ):
             _UpperCAmelCase  :						int							   =					parent
             _UpperCAmelCase  :						Any							   =					batch_size
             _UpperCAmelCase  :						Optional[int]							   =					seq_length
             _UpperCAmelCase  :						Any							   =					is_training
             _UpperCAmelCase  :						Union[str, Any]							   =					use_input_mask
             _UpperCAmelCase  :						Optional[Any]							   =					use_token_type_ids
             _UpperCAmelCase  :						Dict							   =					use_labels
             _UpperCAmelCase  :						Tuple							   =					vocab_size
             _UpperCAmelCase  :						Optional[int]							   =					hidden_size
             _UpperCAmelCase  :						List[Any]							   =					num_hidden_layers
             _UpperCAmelCase  :						Union[str, Any]							   =					num_attention_heads
             _UpperCAmelCase  :						List[str]							   =					intermediate_size
             _UpperCAmelCase  :						Optional[int]							   =					hidden_act
             _UpperCAmelCase  :						List[Any]							   =					hidden_dropout_prob
             _UpperCAmelCase  :						Union[str, Any]							   =					attention_probs_dropout_prob
             _UpperCAmelCase  :						str							   =					max_position_embeddings
             _UpperCAmelCase  :						Any							   =					type_vocab_size
             _UpperCAmelCase  :						str							   =					type_sequence_label_size
             _UpperCAmelCase  :						List[str]							   =					initializer_range
             _UpperCAmelCase  :						Union[str, Any]							   =					num_labels
             _UpperCAmelCase  :						Dict							   =					num_choices
             _UpperCAmelCase  :						List[str]							   =					scope




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

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

             _UpperCAmelCase  :						List[str]							   =					None
             if self.use_token_type_ids:
                    _UpperCAmelCase  :						Optional[Any]							   =					ids_tensor([self.batch_size, self.seq_length]		,      self.type_vocab_size )

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

             _UpperCAmelCase  :						Any							   =					self.get_config()

             return (
                 config,
                 input_ids,
                 token_type_ids,
                 input_mask,
                 sequence_labels,
                 token_labels,
                 choice_labels,
                 fake_token_labels,
             )




      def   _A			( self		:       List[str] ):
             return ElectraConfig(
                 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		,      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   _A			( self		:       Union[str, Any] ):
             (
                 (
                 _UpperCAmelCase
             )   ,						(
                 _UpperCAmelCase
             )   ,						(
                 _UpperCAmelCase
             )   ,						(
                 _UpperCAmelCase
             )   ,						(
                 _UpperCAmelCase
             )   ,						(
                 _UpperCAmelCase
             )   ,						(
                 _UpperCAmelCase
             )   ,						(
                 _UpperCAmelCase
             )   ,						
             )  :						Dict							   =					self.prepare_config_and_inputs()

             _UpperCAmelCase  :						int							   =					True
             _UpperCAmelCase  :						Any							   =					floats_tensor([self.batch_size, self.seq_length, self.hidden_size] )
             _UpperCAmelCase  :						List[Any]							   =					ids_tensor([self.batch_size, self.seq_length]		,      vocab_size=2 )

             return (
                 config,
                 input_ids,
                 token_type_ids,
                 input_mask,
                 sequence_labels,
                 token_labels,
                 choice_labels,
                 encoder_hidden_states,
                 encoder_attention_mask,
             )




      def   _A			( self		:       Union[str, Any]		,      A		:       Dict		,      A		:       int		,      A		:       Any		,      A		:       Tuple		,      A		:       Union[str, Any]		,      A		:       int		,      A		:       str		,      A		:       Union[str, Any]		,      ):
             _UpperCAmelCase  :						Any							   =					ElectraModel(config=A )
             model.to(A )
             model.eval()
             _UpperCAmelCase  :						Optional[int]							   =					model(A		,      attention_mask=A		,      token_type_ids=A )
             _UpperCAmelCase  :						Tuple							   =					model(A		,      token_type_ids=A )
             _UpperCAmelCase  :						List[str]							   =					model(A )
             self.parent.assertEqual(result.last_hidden_state.shape		,      (self.batch_size, self.seq_length, self.hidden_size) )




      def   _A			( self		:       List[Any]		,      A		:       Any		,      A		:       Optional[int]		,      A		:       List[Any]		,      A		:       Dict		,      A		:       List[Any]		,      A		:       Optional[int]		,      A		:       List[str]		,      A		:       Dict		,      A		:       str		,      ):
             _UpperCAmelCase  :						Optional[Any]							   =					True
             _UpperCAmelCase  :						List[str]							   =					ElectraModel(A )
             model.to(A )
             model.eval()
             _UpperCAmelCase  :						int							   =					model(
                 A		,      attention_mask=A		,      token_type_ids=A		,      encoder_hidden_states=A		,      encoder_attention_mask=A		,      )
             _UpperCAmelCase  :						Tuple							   =					model(
                 A		,      attention_mask=A		,      token_type_ids=A		,      encoder_hidden_states=A		,      )
             _UpperCAmelCase  :						Union[str, Any]							   =					model(A		,      attention_mask=A		,      token_type_ids=A )
             self.parent.assertEqual(result.last_hidden_state.shape		,      (self.batch_size, self.seq_length, self.hidden_size) )




      def   _A			( self		:       Optional[int]		,      A		:       int		,      A		:       Optional[Any]		,      A		:       int		,      A		:       Tuple		,      A		:       List[str]		,      A		:       Optional[Any]		,      A		:       str		,      A		:       Dict		,      ):
             _UpperCAmelCase  :						Optional[Any]							   =					ElectraForMaskedLM(config=A )
             model.to(A )
             model.eval()
             _UpperCAmelCase  :						int							   =					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   _A			( self		:       Optional[Any]		,      A		:       Optional[int]		,      A		:       Optional[int]		,      A		:       Any		,      A		:       str		,      A		:       Optional[int]		,      A		:       Any		,      A		:       str		,      A		:       int		,      A		:       Dict		,      ):
             _UpperCAmelCase  :						Tuple							   =					ElectraForCausalLM(config=A )
             model.to(A )
             model.eval()
             _UpperCAmelCase  :						List[Any]							   =					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   _A			( self		:       List[str]		,      A		:       Tuple		,      A		:       Dict		,      A		:       Tuple		,      A		:       List[str]		,      A		:       List[Any]		,      A		:       Optional[Any]		,      A		:       str		,      A		:       Dict		,      ):
             _UpperCAmelCase  :						Any							   =					self.num_labels
             _UpperCAmelCase  :						Tuple							   =					ElectraForTokenClassification(config=A )
             model.to(A )
             model.eval()
             _UpperCAmelCase  :						Union[str, Any]							   =					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   _A			( self		:       Union[str, Any]		,      A		:       Optional[Any]		,      A		:       Optional[int]		,      A		:       Union[str, Any]		,      A		:       str		,      A		:       Union[str, Any]		,      A		:       Tuple		,      A		:       Optional[int]		,      A		:       Optional[int]		,      ):
             _UpperCAmelCase  :						Union[str, Any]							   =					self.num_labels
             _UpperCAmelCase  :						int							   =					ElectraForPreTraining(config=A )
             model.to(A )
             model.eval()
             _UpperCAmelCase  :						Dict							   =					model(A		,      attention_mask=A		,      token_type_ids=A		,      labels=A )
             self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.seq_length) )




      def   _A			( self		:       Union[str, Any]		,      A		:       List[Any]		,      A		:       int		,      A		:       int		,      A		:       Optional[int]		,      A		:       Optional[Any]		,      A		:       Dict		,      A		:       str		,      A		:       Any		,      ):
             _UpperCAmelCase  :						Union[str, Any]							   =					self.num_labels
             _UpperCAmelCase  :						List[str]							   =					ElectraForSequenceClassification(A )
             model.to(A )
             model.eval()
             _UpperCAmelCase  :						str							   =					model(A		,      attention_mask=A		,      token_type_ids=A		,      labels=A )
             self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.num_labels) )




      def   _A			( self		:       List[str]		,      A		:       Optional[Any]		,      A		:       Optional[int]		,      A		:       Tuple		,      A		:       Optional[Any]		,      A		:       int		,      A		:       List[str]		,      A		:       Tuple		,      A		:       Optional[int]		,      ):
             _UpperCAmelCase  :						List[str]							   =					ElectraForQuestionAnswering(config=A )
             model.to(A )
             model.eval()
             _UpperCAmelCase  :						Any							   =					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   _A			( self		:       int		,      A		:       Optional[Any]		,      A		:       Optional[Any]		,      A		:       Tuple		,      A		:       Dict		,      A		:       Optional[Any]		,      A		:       Union[str, Any]		,      A		:       Optional[Any]		,      A		:       str		,      ):
             _UpperCAmelCase  :						Tuple							   =					self.num_choices
             _UpperCAmelCase  :						int							   =					ElectraForMultipleChoice(config=A )
             model.to(A )
             model.eval()
             _UpperCAmelCase  :						str							   =					input_ids.unsqueeze(1 ).expand(-1		,      self.num_choices		,      -1 ).contiguous()
             _UpperCAmelCase  :						Dict							   =					token_type_ids.unsqueeze(1 ).expand(-1		,      self.num_choices		,      -1 ).contiguous()
             _UpperCAmelCase  :						Union[str, Any]							   =					input_mask.unsqueeze(1 ).expand(-1		,      self.num_choices		,      -1 ).contiguous()
             _UpperCAmelCase  :						Union[str, Any]							   =					model(
                 A		,      attention_mask=A		,      token_type_ids=A		,      labels=A		,      )
             self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.num_choices) )





      def   _A			( self		:       Any ):
             _UpperCAmelCase  :						List[Any]							   =					self.prepare_config_and_inputs()
             (
                 (
                 _UpperCAmelCase
             )   ,						(
                 _UpperCAmelCase
             )   ,						(
                 _UpperCAmelCase
             )   ,						(
                 _UpperCAmelCase
             )   ,						(
                 _UpperCAmelCase
             )   ,						(
                 _UpperCAmelCase
             )   ,						(
                 _UpperCAmelCase
             )   ,						(
                 _UpperCAmelCase
             )   ,						
             )  :						Tuple							   =					config_and_inputs
             _UpperCAmelCase  :						List[Any]							   =					{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
             return config, inputs_dict

@require_torch
class 			lowerCamelCase_			(snake_case__							,				snake_case__							,				unittest.TestCase					):
      '''simple docstring'''

      __UpperCamelCase:						Tuple      			=		(
          (
              ElectraModel,
              ElectraForPreTraining,
              ElectraForMaskedLM,
              ElectraForCausalLM,
              ElectraForMultipleChoice,
              ElectraForTokenClassification,
              ElectraForSequenceClassification,
              ElectraForQuestionAnswering,
          )
          if is_torch_available()
          else ()
      )
      __UpperCamelCase:						Optional[Any]      			=		(
          {
              "feature-extraction": ElectraModel,
              "fill-mask": ElectraForMaskedLM,
              "question-answering": ElectraForQuestionAnswering,
              "text-classification": ElectraForSequenceClassification,
              "text-generation": ElectraForCausalLM,
              "token-classification": ElectraForTokenClassification,
              "zero-shot": ElectraForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )
      __UpperCamelCase:						str      			=		True




      def   _A			( self		:       Optional[Any]		,      A		:       Tuple		,      A		:       Optional[Any]		,      A		:       List[Any]=False ):
             _UpperCAmelCase  :						int							   =					super()._prepare_for_class(A		,      A		,      return_labels=A )

             if return_labels:
                    if model_class in get_values(A ):
                           _UpperCAmelCase  :						List[str]							   =					torch.zeros(
                               (self.model_tester.batch_size, self.model_tester.seq_length)		,      dtype=torch.long		,      device=A )
             return inputs_dict




      def   _A			( self		:       Optional[int] ):
             _UpperCAmelCase  :						Any							   =					ElectraModelTester(self )
             _UpperCAmelCase  :						Tuple							   =					ConfigTester(self		,      config_class=A		,      hidden_size=37 )




      def   _A			( self		:       Tuple ):
             self.config_tester.run_common_tests()




      def   _A			( self		:       Dict ):
             _UpperCAmelCase  :						Dict							   =					self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_electra_model(*A )




      def   _A			( self		:       int ):
             _UpperCAmelCase  :						List[Any]							   =					self.model_tester.prepare_config_and_inputs_for_decoder()
             self.model_tester.create_and_check_electra_model_as_decoder(*A )




      def   _A			( self		:       Union[str, Any] ):
             _UpperCAmelCase  :						Optional[Any]							   =					self.model_tester.prepare_config_and_inputs()
             for type in ["absolute", "relative_key", "relative_key_query"]:
                    _UpperCAmelCase  :						Optional[int]							   =					type
                    self.model_tester.create_and_check_electra_model(*A )




      def   _A			( self		:       Optional[Any] ):
             _UpperCAmelCase  :						Optional[Any]							   =					self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_electra_for_masked_lm(*A )




      def   _A			( self		:       Any ):
             _UpperCAmelCase  :						Optional[Any]							   =					self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_electra_for_token_classification(*A )




      def   _A			( self		:       str ):
             _UpperCAmelCase  :						int							   =					self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_electra_for_pretraining(*A )




      def   _A			( self		:       Tuple ):
             _UpperCAmelCase  :						List[str]							   =					self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_electra_for_sequence_classification(*A )




      def   _A			( self		:       Dict ):
             _UpperCAmelCase  :						List[Any]							   =					self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_electra_for_question_answering(*A )




      def   _A			( self		:       Dict ):
             _UpperCAmelCase  :						Optional[int]							   =					self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_electra_for_multiple_choice(*A )




      @slow
      def   _A			( self		:       Union[str, Any] ):
             for model_name in ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                    _UpperCAmelCase  :						List[Any]							   =					ElectraModel.from_pretrained(A )
                    self.assertIsNotNone(A )





      def   _A			( self		:       List[Any] ):
             _UpperCAmelCase  :						Union[str, Any]							   =					self.model_tester.prepare_config_and_inputs_for_decoder()
             self.model_tester.create_and_check_electra_for_causal_lm(*A )

@require_torch
class 			lowerCamelCase_			(unittest.TestCase					):
      '''simple docstring'''

      @slow
      def   _A			( self		:       List[Any] ):
             _UpperCAmelCase  :						List[Any]							   =					ElectraModel.from_pretrained("google/electra-small-discriminator" )
             _UpperCAmelCase  :						List[Any]							   =					torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]] )
             _UpperCAmelCase  :						List[str]							   =					torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] )
             _UpperCAmelCase  :						str							   =					model(A		,      attention_mask=A )[0]
             _UpperCAmelCase  :						Union[str, Any]							   =					torch.Size((1, 11, 256) )
             self.assertEqual(output.shape		,      A )
             _UpperCAmelCase  :						Optional[Any]							   =					torch.tensor(
                 [[[0.4_471, 0.6_821, -0.3_265], [0.4_627, 0.5_255, -0.3_668], [0.4_532, 0.3_313, -0.4_344]]] )

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

