



from __future__ import annotations

import inspect
import unittest
from math import floor

import numpy as np

from transformers import CvtConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
	import tensorflow as tf

	from transformers import TFCvtForImageClassification, TFCvtModel
	from transformers.models.cvt.modeling_tf_cvt import TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
	from PIL import Image

	from transformers import AutoImageProcessor





class 					__lowerCAmelCase (     lowerCamelCase__       ):




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    self.config_class(**self.inputs_dict		)
									self.parent.assertTrue(hasattr(_snake_case						,				"""embed_dim"""		)		)
									self.parent.assertTrue(hasattr(_snake_case						,				"""num_heads"""		)		)





class 					__lowerCAmelCase :




				def __init__(							self						,				_snake_case						,				_snake_case=13						,				_snake_case=64						,				_snake_case=3						,				_snake_case=[16, 48, 96]						,				_snake_case=[1, 3, 6]						,				_snake_case=[1, 2, 10]						,				_snake_case=[7, 3, 3]						,				_snake_case=[4, 2, 2]						,				_snake_case=[2, 1, 1]						,				_snake_case=[2, 2, 2]						,				_snake_case=[False, False, True]						,				_snake_case=[0.0, 0.0, 0.0]						,				_snake_case=0.02						,				_snake_case=1e-12						,				_snake_case=True						,				_snake_case=True						,				_snake_case=2						,				):



									"""simple docstring"""





									_lowerCAmelCase						=    parent
									_lowerCAmelCase						=    batch_size
									_lowerCAmelCase						=    image_size
									_lowerCAmelCase						=    patch_sizes
									_lowerCAmelCase						=    patch_stride
									_lowerCAmelCase						=    patch_padding
									_lowerCAmelCase						=    is_training
									_lowerCAmelCase						=    use_labels
									_lowerCAmelCase						=    num_labels
									_lowerCAmelCase						=    num_channels
									_lowerCAmelCase						=    embed_dim
									_lowerCAmelCase						=    num_heads
									_lowerCAmelCase						=    stride_kv
									_lowerCAmelCase						=    depth
									_lowerCAmelCase						=    cls_token
									_lowerCAmelCase						=    attention_drop_rate
									_lowerCAmelCase						=    initializer_range
									_lowerCAmelCase						=    layer_norm_eps




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

									_lowerCAmelCase						=    None
									if self.use_labels:
														# create a random int32 tensor of given shape
														_lowerCAmelCase						=    ids_tensor([self.batch_size]						,				self.num_labels		)

									_lowerCAmelCase						=    self.get_config()
									return config, pixel_values, labels




				def 							snake_case   (							self		):



									"""simple docstring"""





									return CvtConfig(
									    image_size=self.image_size						,				num_labels=self.num_labels						,				num_channels=self.num_channels						,				embed_dim=self.embed_dim						,				num_heads=self.num_heads						,				patch_sizes=self.patch_sizes						,				patch_padding=self.patch_padding						,				patch_stride=self.patch_stride						,				stride_kv=self.stride_kv						,				depth=self.depth						,				cls_token=self.cls_token						,				attention_drop_rate=self.attention_drop_rate						,				initializer_range=self.initializer_range						,				)




				def 							snake_case   (							self						,				_snake_case						,				_snake_case						,				_snake_case		):



									"""simple docstring"""





									_lowerCAmelCase						=    TFCvtModel(config=_snake_case		)
									_lowerCAmelCase						=    model(_snake_case						,				training=_snake_case		)
									_lowerCAmelCase						=    (self.image_size, self.image_size)
									_lowerCAmelCase	,	_lowerCAmelCase						=    image_size[0], image_size[1]
									for i in range(len(self.depth		)		):
														_lowerCAmelCase						=    floor(((height + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1		)
														_lowerCAmelCase						=    floor(((width + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1		)
									self.parent.assertEqual(result.last_hidden_state.shape						,				(self.batch_size, self.embed_dim[-1], height, width)		)




				def 							snake_case   (							self						,				_snake_case						,				_snake_case						,				_snake_case		):



									"""simple docstring"""





									_lowerCAmelCase						=    self.num_labels
									_lowerCAmelCase						=    TFCvtForImageClassification(_snake_case		)
									_lowerCAmelCase						=    model(_snake_case						,				labels=_snake_case						,				training=_snake_case		)
									self.parent.assertEqual(result.logits.shape						,				(self.batch_size, self.num_labels)		)




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    self.prepare_config_and_inputs()
									_lowerCAmelCase	,	_lowerCAmelCase	,	_lowerCAmelCase						=    config_and_inputs
									_lowerCAmelCase						=    {"""pixel_values""": pixel_values}
									return config, inputs_dict





@require_tf
class 					__lowerCAmelCase (     lowerCamelCase__       ,						lowerCamelCase__       ,						unittest.TestCase       ):
				__lowerCamelCase =				(TFCvtModel, TFCvtForImageClassification) if is_tf_available() else ()
				__lowerCamelCase =				(
				    {'''feature-extraction''': TFCvtModel, '''image-classification''': TFCvtForImageClassification}
				    if is_tf_available()
				    else {}
				)
				__lowerCamelCase =				False
				__lowerCamelCase =				False
				__lowerCamelCase =				False
				__lowerCamelCase =				False
				__lowerCamelCase =				False




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    TFCvtModelTester(self		)
									_lowerCAmelCase						=    TFCvtConfigTester(self						,				config_class=_snake_case						,				has_text_modality=_snake_case						,				hidden_size=37		)




				def 							snake_case   (							self		):



									"""simple docstring"""





									self.config_tester.create_and_test_config_common_properties()
									self.config_tester.create_and_test_config_to_json_string()
									self.config_tester.create_and_test_config_to_json_file()
									self.config_tester.create_and_test_config_from_and_save_pretrained()
									self.config_tester.create_and_test_config_with_num_labels()
									self.config_tester.check_config_can_be_init_without_params()
									self.config_tester.check_config_arguments_init()




				@unittest.skip(reason="""Cvt does not output attentions"""		)
				def 							snake_case   (							self		):



									"""simple docstring"""





									pass




				@unittest.skip(reason="""Cvt does not use inputs_embeds"""		)
				def 							snake_case   (							self		):



									"""simple docstring"""





									pass




				@unittest.skip(reason="""Cvt does not support input and output embeddings"""		)
				def 							snake_case   (							self		):



									"""simple docstring"""





									pass




				@unittest.skipIf(
				    not is_tf_available() or len(tf.config.list_physical_devices("""GPU"""		)		) == 0						,				reason="""TF does not support backprop for grouped convolutions on CPU."""						,				)
				def 							snake_case   (							self		):



									"""simple docstring"""





									super().test_dataset_conversion()




				@unittest.skipIf(
				    not is_tf_available() or len(tf.config.list_physical_devices("""GPU"""		)		) == 0						,				reason="""TF does not support backprop for grouped convolutions on CPU."""						,				)
				@slow
				def 							snake_case   (							self		):



									"""simple docstring"""





									super().test_keras_fit()




				@unittest.skip(reason="""Get `Failed to determine best cudnn convolution algo.` error after using TF 2.12+cuda 11.8"""		)
				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    tf.keras.mixed_precision.Policy("""mixed_float16"""		)
									tf.keras.mixed_precision.set_global_policy(_snake_case		)
									super().test_keras_fit()
									tf.keras.mixed_precision.set_global_policy("""float32"""		)




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase	,	_lowerCAmelCase						=    self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
														_lowerCAmelCase						=    model_class(_snake_case		)
														_lowerCAmelCase						=    inspect.signature(model.call		)
														# signature.parameters is an OrderedDict => so arg_names order is deterministic
														_lowerCAmelCase						=    [*signature.parameters.keys()]

														_lowerCAmelCase						=    ["""pixel_values"""]
														self.assertListEqual(arg_names[:1]						,				_snake_case		)




				def 							snake_case   (							self		):



									"""simple docstring"""





									def check_hidden_states_output(_snake_case						,				_snake_case						,				_snake_case		):
														_lowerCAmelCase						=    model_class(_snake_case		)

														_lowerCAmelCase						=    model(**self._prepare_for_class(_snake_case						,				_snake_case		)		)
														_lowerCAmelCase						=    outputs.hidden_states

														_lowerCAmelCase						=    len(self.model_tester.depth		)
														self.assertEqual(len(_snake_case		)						,				_snake_case		)

														# verify the first hidden states (first block)
														self.assertListEqual(
														    list(hidden_states[0].shape[-3:]		)						,				[
														        self.model_tester.embed_dim[0],
														        self.model_tester.image_size // 4,
														        self.model_tester.image_size // 4,
														    ]						,				)

									_lowerCAmelCase	,	_lowerCAmelCase						=    self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
														_lowerCAmelCase						=    True
														check_hidden_states_output(_snake_case						,				_snake_case						,				_snake_case		)

														# check that output_hidden_states also work using config
														del inputs_dict["output_hidden_states"]
														_lowerCAmelCase						=    True

														check_hidden_states_output(_snake_case						,				_snake_case						,				_snake_case		)




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_snake_case		)




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_image_classification(*_snake_case		)




				@slow
				def 							snake_case   (							self		):



									"""simple docstring"""





									for model_name in TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
														_lowerCAmelCase						=    TFCvtModel.from_pretrained(_snake_case		)
														self.assertIsNotNone(_snake_case		)


def 		_UpperCAmelCase				(      ):





					"""simple docstring"""

					_lowerCAmelCase						=    Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""			)
					return image





@require_tf
@require_vision
class 					__lowerCAmelCase (     unittest.TestCase       ):




				@cached_property
				def 							snake_case   (							self		):



									"""simple docstring"""





									return AutoImageProcessor.from_pretrained(TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]		)




				@slow
				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    TFCvtForImageClassification.from_pretrained(TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]		)

									_lowerCAmelCase						=    self.default_image_processor
									_lowerCAmelCase						=    prepare_img()
									_lowerCAmelCase						=    image_processor(images=_snake_case						,				return_tensors="""tf"""		)

									# forward pass
									_lowerCAmelCase						=    model(**_snake_case		)

									# verify the logits
									_lowerCAmelCase						=    tf.TensorShape((1, 1000)		)
									self.assertEqual(outputs.logits.shape						,				_snake_case		)

									_lowerCAmelCase						=    tf.constant([0.9285, 0.9015, -0.3150]		)
									self.assertTrue(np.allclose(outputs.logits[0, :3].numpy()						,				_snake_case						,				atol=1e-4		)		)






'''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 			lowercase_	(lowerCamelCase__      ):




  """simple docstring"""




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






  def 					SCREAMING_SNAKE_CASE      (      self   :     Tuple			):
   __lowercase							  = ids_tensor([self.batch_size, self.seq_length]					,self.vocab_size			)

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

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

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

   __lowercase							  = self.get_config()

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






  def 					SCREAMING_SNAKE_CASE      (      self   :     Optional[Any]			):
   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   :     List[str]			):
   __lowercase							  = self.get_config()
   __lowercase							  = 3_0_0
   return config






  def 					SCREAMING_SNAKE_CASE      (      self   :     Union[str, Any]					,lowercase__   :     Optional[Any]			):
   self.parent.assertListEqual(list(result.loss.size()			)					,[]			)






  def 					SCREAMING_SNAKE_CASE      (      self   :     Union[str, Any]					,lowercase__   :     List[Any]					,lowercase__   :     Dict					,lowercase__   :     List[Any]					,lowercase__   :     Tuple					,lowercase__   :     Dict					,lowercase__   :     str					,lowercase__   :     Union[str, Any]			):
   __lowercase							  = DebertaModel(config=lowercase__			)
   model.to(lowercase__			)
   model.eval()
   __lowercase							  = model(lowercase__					,attention_mask=lowercase__					,token_type_ids=lowercase__			)[0]
   __lowercase							  = model(lowercase__					,token_type_ids=lowercase__			)[0]
   __lowercase							  = model(lowercase__			)[0]

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






  def 					SCREAMING_SNAKE_CASE      (      self   :     Tuple					,lowercase__   :     str					,lowercase__   :     Tuple					,lowercase__   :     Optional[Any]					,lowercase__   :     Dict					,lowercase__   :     int					,lowercase__   :     Tuple					,lowercase__   :     int			):
   __lowercase							  = DebertaForMaskedLM(config=lowercase__			)
   model.to(lowercase__			)
   model.eval()
   __lowercase							  = model(lowercase__					,attention_mask=lowercase__					,token_type_ids=lowercase__					,labels=lowercase__			)

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






  def 					SCREAMING_SNAKE_CASE      (      self   :     int					,lowercase__   :     Optional[int]					,lowercase__   :     Optional[int]					,lowercase__   :     int					,lowercase__   :     Union[str, Any]					,lowercase__   :     Dict					,lowercase__   :     List[Any]					,lowercase__   :     Optional[Any]			):
   __lowercase							  = self.num_labels
   __lowercase							  = DebertaForSequenceClassification(lowercase__			)
   model.to(lowercase__			)
   model.eval()
   __lowercase							  = model(lowercase__					,attention_mask=lowercase__					,token_type_ids=lowercase__					,labels=lowercase__			)
   self.parent.assertListEqual(list(result.logits.size()			)					,[self.batch_size, self.num_labels]			)
   self.check_loss_output(lowercase__			)






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






  def 					SCREAMING_SNAKE_CASE      (      self   :     Any					,lowercase__   :     Any					,lowercase__   :     Any					,lowercase__   :     Dict					,lowercase__   :     Any					,lowercase__   :     Optional[Any]					,lowercase__   :     int					,lowercase__   :     List[str]			):
   __lowercase							  = DebertaForQuestionAnswering(config=lowercase__			)
   model.to(lowercase__			)
   model.eval()
   __lowercase							  = model(
       lowercase__					,attention_mask=lowercase__					,token_type_ids=lowercase__					,start_positions=lowercase__					,end_positions=lowercase__					,)
   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   :     Dict			):
   __lowercase							  = self.prepare_config_and_inputs()
   (
       (
       __lowercase
   )  ,	(
       __lowercase
   )  ,	(
       __lowercase
   )  ,	(
       __lowercase
   )  ,	(
       __lowercase
   )  ,	(
       __lowercase
   )  ,	(
       __lowercase
   )  ,	
   )							  = config_and_inputs
   __lowercase							  = {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
   return config, inputs_dict






@require_torch
class 			lowercase_	(lowerCamelCase__				,       lowerCamelCase__				,       unittest.TestCase      ):




  """simple docstring"""




  SCREAMING_SNAKE_CASE    :  Tuple							=			(
      (
          DebertaModel,
          DebertaForMaskedLM,
          DebertaForSequenceClassification,
          DebertaForTokenClassification,
          DebertaForQuestionAnswering,
      )
      if is_torch_available()
      else ()
  )
  SCREAMING_SNAKE_CASE    :  Union[str, Any]							=			(
      {
          'feature-extraction': DebertaModel,
          'fill-mask': DebertaForMaskedLM,
          'question-answering': DebertaForQuestionAnswering,
          'text-classification': DebertaForSequenceClassification,
          'token-classification': DebertaForTokenClassification,
          'zero-shot': DebertaForSequenceClassification,
      }
      if is_torch_available()
      else {}
  )

  SCREAMING_SNAKE_CASE    :  Tuple							=			True
  SCREAMING_SNAKE_CASE    :  List[str]							=			False
  SCREAMING_SNAKE_CASE    :  List[str]							=			False
  SCREAMING_SNAKE_CASE    :  Any							=			False
  SCREAMING_SNAKE_CASE    :  List[Any]							=			False






  def 					SCREAMING_SNAKE_CASE      (      self   :     int			):
   __lowercase							  = DebertaModelTester(self			)
   __lowercase							  = ConfigTester(self					,config_class=lowercase__					,hidden_size=3_7			)






  def 					SCREAMING_SNAKE_CASE      (      self   :     int			):
   self.config_tester.run_common_tests()






  def 					SCREAMING_SNAKE_CASE      (      self   :     List[str]			):
   __lowercase							  = self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_deberta_model(*lowercase__			)






  def 					SCREAMING_SNAKE_CASE      (      self   :     Union[str, Any]			):
   __lowercase							  = self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_deberta_for_sequence_classification(*lowercase__			)






  def 					SCREAMING_SNAKE_CASE      (      self   :     Dict			):
   __lowercase							  = self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_deberta_for_masked_lm(*lowercase__			)






  def 					SCREAMING_SNAKE_CASE      (      self   :     Optional[int]			):
   __lowercase							  = self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_deberta_for_question_answering(*lowercase__			)






  def 					SCREAMING_SNAKE_CASE      (      self   :     Dict			):
   __lowercase							  = self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_deberta_for_token_classification(*lowercase__			)






  @slow
  def 					SCREAMING_SNAKE_CASE      (      self   :     Tuple			):
   for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
    __lowercase							  = DebertaModel.from_pretrained(lowercase__			)
    self.assertIsNotNone(lowercase__			)






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




  """simple docstring"""




  @unittest.skip(reason='''Model not available yet'''			)
  def 					SCREAMING_SNAKE_CASE      (      self   :     str			):
   pass






  @slow
  def 					SCREAMING_SNAKE_CASE      (      self   :     Optional[int]			):
   __lowercase							  = DebertaModel.from_pretrained('''microsoft/deberta-base'''			)

   __lowercase							  = torch.tensor([[0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 4_6_0_7_8, 1_5_8_8, 2]]			)
   __lowercase							  = torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]			)
   with torch.no_grad():
    __lowercase							  = model(lowercase__					,attention_mask=lowercase__			)[0]
   # compare the actual values for a slice.
   __lowercase							  = 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]					,lowercase__					,atol=1e-4			)					,F"{output[:, 1:4, 1:4]}"			)

