


import importlib
import json
import os
from collections import OrderedDict
from typing import Dict, Optional, Union

# 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 ...utils import CONFIG_NAME, 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,
)


lowerCAmelCase__      		= logging.get_logger(__name__)

lowerCAmelCase__      		= OrderedDict(
    [
        ('audio-spectrogram-transformer', 'ASTFeatureExtractor'),
        ('beit', 'BeitFeatureExtractor'),
        ('chinese_clip', 'ChineseCLIPFeatureExtractor'),
        ('clap', 'ClapFeatureExtractor'),
        ('clip', 'CLIPFeatureExtractor'),
        ('clipseg', 'ViTFeatureExtractor'),
        ('conditional_detr', 'ConditionalDetrFeatureExtractor'),
        ('convnext', 'ConvNextFeatureExtractor'),
        ('cvt', 'ConvNextFeatureExtractor'),
        ('data2vec-audio', 'Wav2Vec2FeatureExtractor'),
        ('data2vec-vision', 'BeitFeatureExtractor'),
        ('deformable_detr', 'DeformableDetrFeatureExtractor'),
        ('deit', 'DeiTFeatureExtractor'),
        ('detr', 'DetrFeatureExtractor'),
        ('dinat', 'ViTFeatureExtractor'),
        ('donut-swin', 'DonutFeatureExtractor'),
        ('dpt', 'DPTFeatureExtractor'),
        ('encodec', 'EncodecFeatureExtractor'),
        ('flava', 'FlavaFeatureExtractor'),
        ('glpn', 'GLPNFeatureExtractor'),
        ('groupvit', 'CLIPFeatureExtractor'),
        ('hubert', 'Wav2Vec2FeatureExtractor'),
        ('imagegpt', 'ImageGPTFeatureExtractor'),
        ('layoutlmv2', 'LayoutLMv2FeatureExtractor'),
        ('layoutlmv3', 'LayoutLMv3FeatureExtractor'),
        ('levit', 'LevitFeatureExtractor'),
        ('maskformer', 'MaskFormerFeatureExtractor'),
        ('mctct', 'MCTCTFeatureExtractor'),
        ('mobilenet_v1', 'MobileNetV1FeatureExtractor'),
        ('mobilenet_v2', 'MobileNetV2FeatureExtractor'),
        ('mobilevit', 'MobileViTFeatureExtractor'),
        ('nat', 'ViTFeatureExtractor'),
        ('owlvit', 'OwlViTFeatureExtractor'),
        ('perceiver', 'PerceiverFeatureExtractor'),
        ('poolformer', 'PoolFormerFeatureExtractor'),
        ('regnet', 'ConvNextFeatureExtractor'),
        ('resnet', 'ConvNextFeatureExtractor'),
        ('segformer', 'SegformerFeatureExtractor'),
        ('sew', 'Wav2Vec2FeatureExtractor'),
        ('sew-d', 'Wav2Vec2FeatureExtractor'),
        ('speech_to_text', 'Speech2TextFeatureExtractor'),
        ('speecht5', 'SpeechT5FeatureExtractor'),
        ('swiftformer', 'ViTFeatureExtractor'),
        ('swin', 'ViTFeatureExtractor'),
        ('swinv2', 'ViTFeatureExtractor'),
        ('table-transformer', 'DetrFeatureExtractor'),
        ('timesformer', 'VideoMAEFeatureExtractor'),
        ('tvlt', 'TvltFeatureExtractor'),
        ('unispeech', 'Wav2Vec2FeatureExtractor'),
        ('unispeech-sat', 'Wav2Vec2FeatureExtractor'),
        ('van', 'ConvNextFeatureExtractor'),
        ('videomae', 'VideoMAEFeatureExtractor'),
        ('vilt', 'ViltFeatureExtractor'),
        ('vit', 'ViTFeatureExtractor'),
        ('vit_mae', 'ViTFeatureExtractor'),
        ('vit_msn', 'ViTFeatureExtractor'),
        ('wav2vec2', 'Wav2Vec2FeatureExtractor'),
        ('wav2vec2-conformer', 'Wav2Vec2FeatureExtractor'),
        ('wavlm', 'Wav2Vec2FeatureExtractor'),
        ('whisper', 'WhisperFeatureExtractor'),
        ('xclip', 'CLIPFeatureExtractor'),
        ('yolos', 'YolosFeatureExtractor'),
    ]
)

lowerCAmelCase__      		= _LazyAutoMapping(CONFIG_MAPPING_NAMES, FEATURE_EXTRACTOR_MAPPING_NAMES)
def 							_UpperCAmelCase				(UpperCamelCase__     :  str						):
       for module_name, extractors in FEATURE_EXTRACTOR_MAPPING_NAMES.items():
              if class_name in extractors:
                     _A      :       Dict				    = model_type_to_module_name(UpperCamelCase__						)

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

       for _, extractor in FEATURE_EXTRACTOR_MAPPING._extra_content.items():
              if getattr(UpperCamelCase__				,							"__name__"				,							UpperCamelCase__						) == class_name:
                     return extractor

    # 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.
       _A      :       Any				    = importlib.import_module("transformers"						)
       if hasattr(UpperCamelCase__				,							UpperCamelCase__						):
              return getattr(UpperCamelCase__				,							UpperCamelCase__						)

       return None
def 							_UpperCAmelCase				(UpperCamelCase__     :  Union[str, os.PathLike]				,							UpperCamelCase__     :  Optional[Union[str, os.PathLike]] = None				,							UpperCamelCase__     :  bool = False				,							UpperCamelCase__     :  bool = False				,							UpperCamelCase__     :  Optional[Dict[str, str]] = None				,							UpperCamelCase__     :  Optional[Union[bool, str]] = None				,							UpperCamelCase__     :  Optional[str] = None				,							UpperCamelCase__     :  bool = False				,							**UpperCamelCase__     :  Optional[int]				,							):
       _A      :       Tuple				    = get_file_from_repo(
           UpperCamelCase__				,							UpperCamelCase__				,							cache_dir=UpperCamelCase__				,							force_download=UpperCamelCase__				,							resume_download=UpperCamelCase__				,							proxies=UpperCamelCase__				,							use_auth_token=UpperCamelCase__				,							revision=UpperCamelCase__				,							local_files_only=UpperCamelCase__				,							)
       if resolved_config_file is None:
              logger.info(
                  "Could not locate the feature extractor configuration file, will try to use the model config instead."						)
              return {}

       with open(UpperCamelCase__				,							encoding="utf-8"						) as reader:
              return json.load(UpperCamelCase__						)







class      lowerCAmelCase__       :




     '''simple docstring'''


     def __init__(						self)			->				Any:
            raise EnvironmentError(
                "AutoFeatureExtractor is designed to be instantiated "
                "using the `AutoFeatureExtractor.from_pretrained(pretrained_model_name_or_path)` method.")


     @classmethod
     @replace_list_option_in_docstrings(__lowerCamelCase)
     def  _lowerCamelCase (						cls ,						__lowerCamelCase ,						**__lowerCamelCase)			->				Optional[int]:
            _A      :       Optional[int]				    = kwargs.pop("config" ,						__lowerCamelCase)
            _A      :       Tuple				    = kwargs.pop("trust_remote_code" ,						__lowerCamelCase)
            _A      :       List[Any]				    = True

            _A    ,			_A      :       Optional[int]				    = FeatureExtractionMixin.get_feature_extractor_dict(__lowerCamelCase ,						**__lowerCamelCase)
            _A      :       List[Any]				    = config_dict.get("feature_extractor_type" ,						__lowerCamelCase)
            _A      :       int				    = None
            if "AutoFeatureExtractor" in config_dict.get("auto_map" ,						{}):
                   _A      :       Any				    = config_dict["auto_map"]["AutoFeatureExtractor"]

            # If we don't find the feature extractor class in the feature extractor config, let's try the model config.
            if feature_extractor_class is None and feature_extractor_auto_map is None:
                   if not isinstance(__lowerCamelCase ,						__lowerCamelCase):
                          _A      :       str				    = AutoConfig.from_pretrained(__lowerCamelCase ,						**__lowerCamelCase)
                   # It could be in `config.feature_extractor_type``
                   _A      :       List[Any]				    = getattr(__lowerCamelCase ,						"feature_extractor_type" ,						__lowerCamelCase)
                   if hasattr(__lowerCamelCase ,						"auto_map") and "AutoFeatureExtractor" in config.auto_map:
                          _A      :       Optional[int]				    = config.auto_map["AutoFeatureExtractor"]

            if feature_extractor_class is not None:
                   _A      :       List[Any]				    = feature_extractor_class_from_name(__lowerCamelCase)

            _A      :       Any				    = feature_extractor_auto_map is not None
            _A      :       Optional[int]				    = feature_extractor_class is not None or type(__lowerCamelCase) in FEATURE_EXTRACTOR_MAPPING
            _A      :       int				    = resolve_trust_remote_code(
                __lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase)

            if has_remote_code and trust_remote_code:
                   _A      :       List[Any]				    = get_class_from_dynamic_module(
                       __lowerCamelCase ,						__lowerCamelCase ,						**__lowerCamelCase)
                   _A      :       List[str]				    = kwargs.pop("code_revision" ,						__lowerCamelCase)
                   if os.path.isdir(__lowerCamelCase):
                          feature_extractor_class.register_for_auto_class()
                   return feature_extractor_class.from_dict(__lowerCamelCase ,						**__lowerCamelCase)
            elif feature_extractor_class is not None:
                   return feature_extractor_class.from_dict(__lowerCamelCase ,						**__lowerCamelCase)
            # Last try: we use the FEATURE_EXTRACTOR_MAPPING.
            elif type(__lowerCamelCase) in FEATURE_EXTRACTOR_MAPPING:
                   _A      :       Dict				    = FEATURE_EXTRACTOR_MAPPING[type(__lowerCamelCase)]
                   return feature_extractor_class.from_dict(__lowerCamelCase ,						**__lowerCamelCase)

            raise ValueError(
                F"Unrecognized feature extractor in {pretrained_model_name_or_path}. Should have a "
                F"`feature_extractor_type` key in its {FEATURE_EXTRACTOR_NAME} of {CONFIG_NAME}, or one of the following "
                F"`model_type` keys in its {CONFIG_NAME}: {', '.join(c for c in FEATURE_EXTRACTOR_MAPPING_NAMES.keys())}")


     @staticmethod
     def  _lowerCamelCase (						__lowerCamelCase ,						__lowerCamelCase)			->				Union[str, Any]:
            FEATURE_EXTRACTOR_MAPPING.register(__lowerCamelCase ,						__lowerCamelCase)








"""simple docstring"""
import unittest

from transformers import DebertaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

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


if is_torch_available():
			import torch

			from transformers import (
			    DebertaForMaskedLM,
			    DebertaForQuestionAnswering,
			    DebertaForSequenceClassification,
			    DebertaForTokenClassification,
			    DebertaModel,
			)
			from transformers.models.deberta.modeling_deberta import DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST







class 			UpperCamelCase_       (__A     ):





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





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[Any]						)						->			Dict:
				UpperCAmelCase_     : Any			     =					ids_tensor([self.batch_size, self.seq_length]	,	self.vocab_size						)

				UpperCAmelCase_     : Tuple			     =					None
				if self.use_input_mask:
							UpperCAmelCase_     : List[str]			     =					ids_tensor([self.batch_size, self.seq_length]	,	vocab_size=2						)

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

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

				UpperCAmelCase_     : int			     =					self.get_config()

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





	def      _SCREAMING_SNAKE_CASE      (      self					: Dict						)						->			Dict:
				return DebertaConfig(
				    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	,	initializer_range=self.initializer_range	,	relative_attention=self.relative_attention	,	position_biased_input=self.position_biased_input	,	pos_att_type=self.pos_att_type	,	)





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]						)						->			Union[str, Any]:
				UpperCAmelCase_     : List[str]			     =					self.get_config()
				UpperCAmelCase_     : int			     =					300
				return config





	def      _SCREAMING_SNAKE_CASE      (      self					: Any	,	lowerCAmelCase_					: int						)						->			List[Any]:
				self.parent.assertListEqual(list(result.loss.size()						)	,	[]						)





	def      _SCREAMING_SNAKE_CASE      (      self					: int	,	lowerCAmelCase_					: List[Any]	,	lowerCAmelCase_					: Dict	,	lowerCAmelCase_					: Any	,	lowerCAmelCase_					: Any	,	lowerCAmelCase_					: List[str]	,	lowerCAmelCase_					: Dict	,	lowerCAmelCase_					: List[Any]						)						->			List[Any]:
				UpperCAmelCase_     : Optional[Any]			     =					DebertaModel(config=lowerCAmelCase_						)
				model.to(lowerCAmelCase_						)
				model.eval()
				UpperCAmelCase_     : Optional[Any]			     =					model(lowerCAmelCase_	,	attention_mask=lowerCAmelCase_	,	token_type_ids=lowerCAmelCase_						)[0]
				UpperCAmelCase_     : Optional[int]			     =					model(lowerCAmelCase_	,	token_type_ids=lowerCAmelCase_						)[0]
				UpperCAmelCase_     : Optional[Any]			     =					model(lowerCAmelCase_						)[0]

				self.parent.assertListEqual(list(sequence_output.size()						)	,	[self.batch_size, self.seq_length, self.hidden_size]						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: Optional[int]	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: List[Any]	,	lowerCAmelCase_					: str	,	lowerCAmelCase_					: Dict	,	lowerCAmelCase_					: Optional[int]						)						->			List[Any]:
				UpperCAmelCase_     : Union[str, Any]			     =					DebertaForMaskedLM(config=lowerCAmelCase_						)
				model.to(lowerCAmelCase_						)
				model.eval()
				UpperCAmelCase_     : List[Any]			     =					model(lowerCAmelCase_	,	attention_mask=lowerCAmelCase_	,	token_type_ids=lowerCAmelCase_	,	labels=lowerCAmelCase_						)

				self.parent.assertEqual(result.logits.shape	,	(self.batch_size, self.seq_length, self.vocab_size)						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Any	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: Dict	,	lowerCAmelCase_					: Optional[Any]	,	lowerCAmelCase_					: Any	,	lowerCAmelCase_					: str	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: Optional[Any]						)						->			Optional[Any]:
				UpperCAmelCase_     : Any			     =					self.num_labels
				UpperCAmelCase_     : List[Any]			     =					DebertaForSequenceClassification(lowerCAmelCase_						)
				model.to(lowerCAmelCase_						)
				model.eval()
				UpperCAmelCase_     : Optional[Any]			     =					model(lowerCAmelCase_	,	attention_mask=lowerCAmelCase_	,	token_type_ids=lowerCAmelCase_	,	labels=lowerCAmelCase_						)
				self.parent.assertListEqual(list(result.logits.size()						)	,	[self.batch_size, self.num_labels]						)
				self.check_loss_output(lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: List[Any]	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: Optional[int]	,	lowerCAmelCase_					: Optional[int]	,	lowerCAmelCase_					: Optional[Any]	,	lowerCAmelCase_					: Union[str, Any]	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: Tuple						)						->			str:
				UpperCAmelCase_     : Optional[int]			     =					self.num_labels
				UpperCAmelCase_     : Optional[int]			     =					DebertaForTokenClassification(config=lowerCAmelCase_						)
				model.to(lowerCAmelCase_						)
				model.eval()
				UpperCAmelCase_     : Optional[Any]			     =					model(lowerCAmelCase_	,	attention_mask=lowerCAmelCase_	,	token_type_ids=lowerCAmelCase_	,	labels=lowerCAmelCase_						)
				self.parent.assertEqual(result.logits.shape	,	(self.batch_size, self.seq_length, self.num_labels)						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Tuple	,	lowerCAmelCase_					: List[Any]	,	lowerCAmelCase_					: Optional[int]	,	lowerCAmelCase_					: List[Any]	,	lowerCAmelCase_					: Union[str, Any]	,	lowerCAmelCase_					: Optional[int]	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: str						)						->			List[Any]:
				UpperCAmelCase_     : Dict			     =					DebertaForQuestionAnswering(config=lowerCAmelCase_						)
				model.to(lowerCAmelCase_						)
				model.eval()
				UpperCAmelCase_     : Any			     =					model(
				    lowerCAmelCase_	,	attention_mask=lowerCAmelCase_	,	token_type_ids=lowerCAmelCase_	,	start_positions=lowerCAmelCase_	,	end_positions=lowerCAmelCase_	,	)
				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      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]						)						->			Union[str, Any]:
				UpperCAmelCase_     : Union[str, Any]			     =					self.prepare_config_and_inputs()
				(
				    (
				    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 			UpperCamelCase_       (__A				,						__A				,						unittest.TestCase     ):
	__magic_name__	      =				(
	    (
	        DebertaModel,
	        DebertaForMaskedLM,
	        DebertaForSequenceClassification,
	        DebertaForTokenClassification,
	        DebertaForQuestionAnswering,
	    )
	    if is_torch_available()
	    else ()
	)
	__magic_name__	      =				(
	    {
	        '''feature-extraction''': DebertaModel,
	        '''fill-mask''': DebertaForMaskedLM,
	        '''question-answering''': DebertaForQuestionAnswering,
	        '''text-classification''': DebertaForSequenceClassification,
	        '''token-classification''': DebertaForTokenClassification,
	        '''zero-shot''': DebertaForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)

	__magic_name__	      =				True
	__magic_name__	      =				False
	__magic_name__	      =				False
	__magic_name__	      =				False
	__magic_name__	      =				False





	def      _SCREAMING_SNAKE_CASE      (      self					: Dict						)						->			int:
				UpperCAmelCase_     : int			     =					DebertaModelTester(self						)
				UpperCAmelCase_     : Any			     =					ConfigTester(self	,	config_class=lowerCAmelCase_	,	hidden_size=37						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Union[str, Any]						)						->			Optional[Any]:
				self.config_tester.run_common_tests()





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]						)						->			Optional[Any]:
				UpperCAmelCase_     : Union[str, Any]			     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_deberta_model(*lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: List[str]						)						->			Union[str, Any]:
				UpperCAmelCase_     : int			     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_deberta_for_sequence_classification(*lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[Any]						)						->			Optional[int]:
				UpperCAmelCase_     : Any			     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_deberta_for_masked_lm(*lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: int						)						->			Union[str, Any]:
				UpperCAmelCase_     : Tuple			     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_deberta_for_question_answering(*lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[Any]						)						->			Union[str, Any]:
				UpperCAmelCase_     : Any			     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_deberta_for_token_classification(*lowerCAmelCase_						)





	@slow
	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[int]						)						->			Tuple:
				for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							UpperCAmelCase_     : Optional[int]			     =					DebertaModel.from_pretrained(lowerCAmelCase_						)
							self.assertIsNotNone(lowerCAmelCase_						)







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





	@unittest.skip(reason="Model not available yet"						)
	def      _SCREAMING_SNAKE_CASE      (      self					: List[Any]						)						->			Optional[Any]:
				pass





	@slow
	def      _SCREAMING_SNAKE_CASE      (      self					: int						)						->			List[Any]:
				UpperCAmelCase_     : Optional[int]			     =					DebertaModel.from_pretrained("microsoft/deberta-base"						)

				UpperCAmelCase_     : List[Any]			     =					torch.tensor([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]						)
				UpperCAmelCase_     : Tuple			     =					torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
				with torch.no_grad():
							UpperCAmelCase_     : Optional[Any]			     =					model(lowerCAmelCase_	,	attention_mask=lowerCAmelCase_						)[0]
				# compare the actual values for a slice.
				UpperCAmelCase_     : Tuple			     =					torch.tensor(
				    [[[-0.5_9_8_6, -0.8_0_5_5, -0.8_4_6_2], [1.4_4_8_4, -0.9_3_4_8, -0.8_0_5_9], [0.3_1_2_3, 0.0_0_3_2, -1.4_1_3_1]]]						)
				self.assertTrue(torch.allclose(output[:, 1:4, 1:4]	,	lowerCAmelCase_	,	atol=1e-4						)	,	f"""{output[:, 1:4, 1:4]}"""						)



