
"""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 				lowerCAmelCase_				(      _lowercase    ):



						'''simple docstring'''


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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      int      )     ->   List[Any]:
							A						   =   ids_tensor([self.batch_size, self.seq_length]  ,self.vocab_size      )

							A						   =   None
							if self.use_input_mask:
								A						   =   ids_tensor([self.batch_size, self.seq_length]  ,vocab_size=2      )

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

							A						   =   None
							A						   =   None
							A						   =   None
							if self.use_labels:
								A						   =   ids_tensor([self.batch_size]  ,self.type_sequence_label_size      )
								A						   =   ids_tensor([self.batch_size, self.seq_length]  ,self.num_labels      )
								A						   =   ids_tensor([self.batch_size]  ,self.num_choices      )

							A						   =   self.get_config()

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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[Any]      )     ->   str:
							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     :      str      )     ->   str:
							A						   =   self.get_config()
							A						   =   300
							return config


						def 						_SCREAMING_SNAKE_CASE      ( self     :      str  ,A_     :      Tuple      )     ->   Union[str, Any]:
							self.parent.assertListEqual(list(result.loss.size()      )  ,[]      )


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

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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      str  ,A_     :      Dict  ,A_     :      int  ,A_     :      List[str]  ,A_     :      Tuple  ,A_     :      str  ,A_     :      Union[str, Any]  ,A_     :      Dict      )     ->   List[str]:
							A						   =   DebertaForMaskedLM(config=A_      )
							model.to(A_      )
							model.eval()
							A						   =   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 						_SCREAMING_SNAKE_CASE      ( self     :      List[Any]  ,A_     :      Optional[Any]  ,A_     :      List[str]  ,A_     :      Tuple  ,A_     :      List[str]  ,A_     :      Any  ,A_     :      Any  ,A_     :      Any      )     ->   List[str]:
							A						   =   self.num_labels
							A						   =   DebertaForSequenceClassification(A_      )
							model.to(A_      )
							model.eval()
							A						   =   model(A_  ,attention_mask=A_  ,token_type_ids=A_  ,labels=A_      )
							self.parent.assertListEqual(list(result.logits.size()      )  ,[self.batch_size, self.num_labels]      )
							self.check_loss_output(A_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]  ,A_     :      Optional[Any]  ,A_     :      Any  ,A_     :      List[Any]  ,A_     :      Any  ,A_     :      Union[str, Any]  ,A_     :      str  ,A_     :      int      )     ->   str:
							A						   =   self.num_labels
							A						   =   DebertaForTokenClassification(config=A_      )
							model.to(A_      )
							model.eval()
							A						   =   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 						_SCREAMING_SNAKE_CASE      ( self     :      List[str]  ,A_     :      List[Any]  ,A_     :      List[str]  ,A_     :      Dict  ,A_     :      Tuple  ,A_     :      Optional[int]  ,A_     :      List[Any]  ,A_     :      Union[str, Any]      )     ->   int:
							A						   =   DebertaForQuestionAnswering(config=A_      )
							model.to(A_      )
							model.eval()
							A						   =   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 						_SCREAMING_SNAKE_CASE      ( self     :      str      )     ->   Union[str, Any]:
							A						   =   self.prepare_config_and_inputs()
							(
							    A       
							)						   =   config_and_inputs
							A						   =   {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
							return config, inputs_dict







@require_torch
class 				lowerCAmelCase_				(      _lowercase		,					_lowercase		,					unittest.TestCase    ):



						'''simple docstring'''


						_lowerCamelCase:    Dict      =    (
						    (
						        DebertaModel,
						        DebertaForMaskedLM,
						        DebertaForSequenceClassification,
						        DebertaForTokenClassification,
						        DebertaForQuestionAnswering,
						    )
						    if is_torch_available()
						    else ()
						)
						_lowerCamelCase:    Tuple      =    (
						    {
						        '''feature-extraction''': DebertaModel,
						        '''fill-mask''': DebertaForMaskedLM,
						        '''question-answering''': DebertaForQuestionAnswering,
						        '''text-classification''': DebertaForSequenceClassification,
						        '''token-classification''': DebertaForTokenClassification,
						        '''zero-shot''': DebertaForSequenceClassification,
						    }
						    if is_torch_available()
						    else {}
						)

						_lowerCamelCase:    str      =    True
						_lowerCamelCase:    Optional[int]      =    False
						_lowerCamelCase:    Any      =    False
						_lowerCamelCase:    Any      =    False
						_lowerCamelCase:    str      =    False


						def 						_SCREAMING_SNAKE_CASE      ( self     :      str      )     ->   Tuple:
							A						   =   DebertaModelTester(self      )
							A						   =   ConfigTester(self  ,config_class=A_  ,hidden_size=37      )


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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[int]      )     ->   int:
							A						   =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_model(*A_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Tuple      )     ->   int:
							A						   =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_sequence_classification(*A_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]      )     ->   List[Any]:
							A						   =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_masked_lm(*A_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[int]      )     ->   List[str]:
							A						   =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_question_answering(*A_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[str]      )     ->   Tuple:
							A						   =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_token_classification(*A_      )




						@slow
						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[str]      )     ->   Dict:







							for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								A						   =   DebertaModel.from_pretrained(A_      )
								self.assertIsNotNone(A_      )







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



						'''simple docstring'''


						@unittest.skip(reason='Model not available yet'      )
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]      )     ->   Dict:
							pass




						@slow
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]      )     ->   str:
							A						   =   DebertaModel.from_pretrained('microsoft/deberta-base'      )

							A						   =   torch.tensor([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]      )
							A						   =   torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
							with torch.no_grad():
								A						   =   model(A_  ,attention_mask=A_      )[0]
							# compare the actual values for a slice.
							A						   =   torch.tensor(
							    [[[-0.59_86, -0.80_55, -0.84_62], [1.44_84, -0.93_48, -0.80_59], [0.31_23, 0.00_32, -1.41_31]]]      )
							self.assertTrue(torch.allclose(output[:, 1:4, 1:4]  ,A_  ,atol=1e-4      )  ,F'{output[:, 1:4, 1:4]}'      )

"""simple docstring"""


from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


_lowercase							   =				logging.get_logger(__name__)

_lowercase							   =				{
    '''hustvl/yolos-small''': '''https://huggingface.co/hustvl/yolos-small/resolve/main/config.json''',
    # See all YOLOS models at https://huggingface.co/models?filter=yolos
}







class 				lowerCAmelCase_				(      _lowercase    ):



						'''simple docstring'''


						_lowerCamelCase:    List[str]      =    '''yolos'''


						def __init__( self     :      Dict  ,A_     :      Optional[Any]=768  ,A_     :      int=12  ,A_     :      List[str]=12  ,A_     :      str=3072  ,A_     :      Tuple="gelu"  ,A_     :      Dict=0.0  ,A_     :      List[Any]=0.0  ,A_     :      Any=0.02  ,A_     :      str=1e-12  ,A_     :      List[Any]=[512, 864]  ,A_     :      Union[str, Any]=16  ,A_     :      List[str]=3  ,A_     :      Optional[int]=True  ,A_     :      Tuple=100  ,A_     :      str=True  ,A_     :      Optional[Any]=False  ,A_     :      Any=1  ,A_     :      Optional[Any]=5  ,A_     :      Optional[Any]=2  ,A_     :      Optional[int]=5  ,A_     :      List[Any]=2  ,A_     :      Union[str, Any]=0.1  ,**A_     :      Tuple  ,)     ->   Any:
							super().__init__(**A_      )

							A						   =   hidden_size
							A						   =   num_hidden_layers
							A						   =   num_attention_heads
							A						   =   intermediate_size
							A						   =   hidden_act
							A						   =   hidden_dropout_prob
							A						   =   attention_probs_dropout_prob
							A						   =   initializer_range
							A						   =   layer_norm_eps
							A						   =   image_size
							A						   =   patch_size
							A						   =   num_channels
							A						   =   qkv_bias
							A						   =   num_detection_tokens
							A						   =   use_mid_position_embeddings
							A						   =   auxiliary_loss
							# Hungarian matcher
							A						   =   class_cost
							A						   =   bbox_cost
							A						   =   giou_cost
							# Loss coefficients
							A						   =   bbox_loss_coefficient
							A						   =   giou_loss_coefficient
							A						   =   eos_coefficient







class 				lowerCAmelCase_				(      _lowercase    ):



						'''simple docstring'''


						_lowerCamelCase:    Any      =    version.parse('''1.11'''    )


						@property
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[int]      )     ->   Mapping[str, Mapping[int, str]]:
							return OrderedDict(
							    [
							        ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
							    ]      )


						@property
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Any      )     ->   float:
							return 1e-4




						@property
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Tuple      )     ->   int:
							return 12