





import gc
import math
import unittest

import torch

from diffusers import UNetaDModel
from diffusers.utils import floats_tensor, logging, slow, torch_all_close, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin


UpperCAmelCase_     							= logging.get_logger(__name__)

enable_full_determinism()






class     lowercase__       (	SCREAMING_SNAKE_CASE_			,				SCREAMING_SNAKE_CASE_			,				unittest.TestCase				):

   '''simple docstring'''


   a						:							Optional[int]   		=		UNetaDModel
   a						:							int   		=		"sample"




   @property
   def       UpperCamelCase__  (    self							) ->      str:






       """simple docstring"""
       UpperCamelCase__							:				Optional[int]          =      4
       UpperCamelCase__							:				Optional[int]          =      3
       UpperCamelCase__							:				List[str]          =      (32, 32)

       UpperCamelCase__							:				str          =      floats_tensor((batch_size, num_channels) + sizes							).to(a__							)
       UpperCamelCase__							:				Dict          =      torch.tensor([10]							).to(a__							)

       return {"sample": noise, "timestep": time_step}




   @property
   def       UpperCamelCase__  (    self							) ->      str:






       """simple docstring"""
       return (3, 32, 32)




   @property
   def       UpperCamelCase__  (    self							) ->      List[Any]:






       """simple docstring"""
       return (3, 32, 32)




   def       UpperCamelCase__  (    self							) ->      Optional[Any]:






       """simple docstring"""
       UpperCamelCase__							:				str          =      {
           """block_out_channels""": (32, 64),
           """down_block_types""": ("""DownBlock2D""", """AttnDownBlock2D"""),
           """up_block_types""": ("""AttnUpBlock2D""", """UpBlock2D"""),
           """attention_head_dim""": 3,
           """out_channels""": 3,
           """in_channels""": 3,
           """layers_per_block""": 2,
           """sample_size""": 32,
       }
       UpperCamelCase__							:				int          =      self.dummy_input
       return init_dict, inputs_dict






class     lowercase__       (	SCREAMING_SNAKE_CASE_			,				SCREAMING_SNAKE_CASE_			,				unittest.TestCase				):

   '''simple docstring'''


   a						:							Tuple   		=		UNetaDModel
   a						:							Dict   		=		"sample"




   @property
   def       UpperCamelCase__  (    self							) ->      Optional[Any]:






       """simple docstring"""
       UpperCamelCase__							:				Optional[int]          =      4
       UpperCamelCase__							:				int          =      4
       UpperCamelCase__							:				Optional[int]          =      (32, 32)

       UpperCamelCase__							:				List[Any]          =      floats_tensor((batch_size, num_channels) + sizes							).to(a__							)
       UpperCamelCase__							:				int          =      torch.tensor([10]							).to(a__							)

       return {"sample": noise, "timestep": time_step}




   @property
   def       UpperCamelCase__  (    self							) ->      Optional[Any]:






       """simple docstring"""
       return (4, 32, 32)




   @property
   def       UpperCamelCase__  (    self							) ->      int:






       """simple docstring"""
       return (4, 32, 32)




   def       UpperCamelCase__  (    self							) ->      Optional[Any]:






       """simple docstring"""
       UpperCamelCase__							:				Dict          =      {
           """sample_size""": 32,
           """in_channels""": 4,
           """out_channels""": 4,
           """layers_per_block""": 2,
           """block_out_channels""": (32, 64),
           """attention_head_dim""": 32,
           """down_block_types""": ("""DownBlock2D""", """DownBlock2D"""),
           """up_block_types""": ("""UpBlock2D""", """UpBlock2D"""),
       }
       UpperCamelCase__							:				int          =      self.dummy_input
       return init_dict, inputs_dict




   def       UpperCamelCase__  (    self							) ->      List[Any]:






       """simple docstring"""
       UpperCamelCase__							:				List[str]          =      UNetaDModel.from_pretrained('''fusing/unet-ldm-dummy-update''',		output_loading_info=a__							)

       self.assertIsNotNone(a__							)
       self.assertEqual(len(loading_info['''missing_keys''']							),		0							)

       model.to(a__							)
       UpperCamelCase__							:				Any          =      model(**self.dummy_input							).sample

       assert image is not None, "Make sure output is not None"




   @unittest.skipIf(torch_device != '''cuda''',		'''This test is supposed to run on GPU'''							)
   def       UpperCamelCase__  (    self							) ->      int:






       """simple docstring"""
       UpperCamelCase__							:				Any          =      UNetaDModel.from_pretrained('''fusing/unet-ldm-dummy-update''',		output_loading_info=a__							)
       model.to(a__							)
       UpperCamelCase__							:				Union[str, Any]          =      model(**self.dummy_input							).sample

       assert image is not None, "Make sure output is not None"




   @unittest.skipIf(torch_device != '''cuda''',		'''This test is supposed to run on GPU'''							)
   def       UpperCamelCase__  (    self							) ->      str:






       """simple docstring"""
       # by defautl model loading will use accelerate as `low_cpu_mem_usage=True`
       UpperCamelCase__							:				List[Any]          =      UNetaDModel.from_pretrained('''fusing/unet-ldm-dummy-update''',		output_loading_info=a__							)
       model_accelerate.to(a__							)
       model_accelerate.eval()

       UpperCamelCase__							:				int          =      torch.randn(
           1,		model_accelerate.config.in_channels,		model_accelerate.config.sample_size,		model_accelerate.config.sample_size,		generator=torch.manual_seed(0							),		)
       UpperCamelCase__							:				Optional[int]          =      noise.to(a__							)
       UpperCamelCase__							:				Dict          =      torch.tensor([10] * noise.shape[0]							).to(a__							)

       UpperCamelCase__							:				Dict          =      model_accelerate(a__,		a__							)["""sample"""]

       # two models don't need to stay in the device at the same time
       del model_accelerate
       torch.cuda.empty_cache()
       gc.collect()

       UpperCamelCase__							:				Union[str, Any]          =      UNetaDModel.from_pretrained(
           '''fusing/unet-ldm-dummy-update''',		output_loading_info=a__,		low_cpu_mem_usage=a__							)
       model_normal_load.to(a__							)
       model_normal_load.eval()
       UpperCamelCase__							:				Dict          =      model_normal_load(a__,		a__							)["""sample"""]

       assert torch_all_close(a__,		a__,		rtol=1E-3							)




   def       UpperCamelCase__  (    self							) ->      List[Any]:






       """simple docstring"""
       UpperCamelCase__							:				Optional[Any]          =      UNetaDModel.from_pretrained('''fusing/unet-ldm-dummy-update'''							)
       model.eval()
       model.to(a__							)

       UpperCamelCase__							:				List[Any]          =      torch.randn(
           1,		model.config.in_channels,		model.config.sample_size,		model.config.sample_size,		generator=torch.manual_seed(0							),		)
       UpperCamelCase__							:				List[str]          =      noise.to(a__							)
       UpperCamelCase__							:				Any          =      torch.tensor([10] * noise.shape[0]							).to(a__							)

       with torch.no_grad():
           UpperCamelCase__							:				Union[str, Any]          =      model(a__,		a__							).sample

       UpperCamelCase__							:				int          =      output[0, -1, -3:, -3:].flatten().cpu()
       # fmt: off
       UpperCamelCase__							:				Optional[int]          =      torch.tensor([-13.3258, -20.1100, -15.9873, -17.6617, -23.0596, -17.9419, -13.3675, -16.1889, -12.3800]							)
       # fmt: on

       self.assertTrue(torch_all_close(a__,		a__,		rtol=1E-3							)							)






class     lowercase__       (	SCREAMING_SNAKE_CASE_			,				SCREAMING_SNAKE_CASE_			,				unittest.TestCase				):

   '''simple docstring'''


   a						:							List[str]   		=		UNetaDModel
   a						:							Any   		=		"sample"




   @property
   def       UpperCamelCase__  (    self,		__magic_name__=(32, 32)							) ->      Optional[int]:






       """simple docstring"""
       UpperCamelCase__							:				Optional[int]          =      4
       UpperCamelCase__							:				Dict          =      3

       UpperCamelCase__							:				List[Any]          =      floats_tensor((batch_size, num_channels) + sizes							).to(a__							)
       UpperCamelCase__							:				Any          =      torch.tensor(batch_size * [10]							).to(dtype=torch.intaa,		device=a__							)

       return {"sample": noise, "timestep": time_step}




   @property
   def       UpperCamelCase__  (    self							) ->      Tuple:






       """simple docstring"""
       return (3, 32, 32)




   @property
   def       UpperCamelCase__  (    self							) ->      str:






       """simple docstring"""
       return (3, 32, 32)




   def       UpperCamelCase__  (    self							) ->      List[str]:






       """simple docstring"""
       UpperCamelCase__							:				List[Any]          =      {
           """block_out_channels""": [32, 64, 64, 64],
           """in_channels""": 3,
           """layers_per_block""": 1,
           """out_channels""": 3,
           """time_embedding_type""": """fourier""",
           """norm_eps""": 1E-6,
           """mid_block_scale_factor""": math.sqrt(2.0							),
           """norm_num_groups""": None,
           """down_block_types""": [
               """SkipDownBlock2D""",
               """AttnSkipDownBlock2D""",
               """SkipDownBlock2D""",
               """SkipDownBlock2D""",
           ],
           """up_block_types""": [
               """SkipUpBlock2D""",
               """SkipUpBlock2D""",
               """AttnSkipUpBlock2D""",
               """SkipUpBlock2D""",
           ],
       }
       UpperCamelCase__							:				Optional[int]          =      self.dummy_input
       return init_dict, inputs_dict




   @slow
   def       UpperCamelCase__  (    self							) ->      Dict:






       """simple docstring"""
       UpperCamelCase__							:				Union[str, Any]          =      UNetaDModel.from_pretrained('''google/ncsnpp-celebahq-256''',		output_loading_info=a__							)
       self.assertIsNotNone(a__							)
       self.assertEqual(len(loading_info['''missing_keys''']							),		0							)

       model.to(a__							)
       UpperCamelCase__							:				str          =      self.dummy_input
       UpperCamelCase__							:				Optional[Any]          =      floats_tensor((4, 3) + (256, 256)							).to(a__							)
       UpperCamelCase__							:				Any          =      noise
       UpperCamelCase__							:				str          =      model(**a__							)

       assert image is not None, "Make sure output is not None"




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






       """simple docstring"""
       UpperCamelCase__							:				Optional[Any]          =      UNetaDModel.from_pretrained('''google/ncsnpp-celebahq-256'''							)
       model.to(a__							)

       UpperCamelCase__							:				str          =      4
       UpperCamelCase__							:				List[str]          =      3
       UpperCamelCase__							:				Any          =      (256, 256)

       UpperCamelCase__							:				List[Any]          =      torch.ones((batch_size, num_channels) + sizes							).to(a__							)
       UpperCamelCase__							:				str          =      torch.tensor(batch_size * [1E-4]							).to(a__							)

       with torch.no_grad():
           UpperCamelCase__							:				Optional[Any]          =      model(a__,		a__							).sample

       UpperCamelCase__							:				Optional[Any]          =      output[0, -3:, -3:, -1].flatten().cpu()
       # fmt: off
       UpperCamelCase__							:				int          =      torch.tensor([-4842.8691, -6499.6631, -3800.1953, -7978.2686, -10980.7129, -20028.8535, 8148.2822, 2342.2905, 567.7608]							)
       # fmt: on

       self.assertTrue(torch_all_close(a__,		a__,		rtol=1E-2							)							)




   def       UpperCamelCase__  (    self							) ->      Optional[int]:






       """simple docstring"""
       UpperCamelCase__							:				int          =      UNetaDModel.from_pretrained('''fusing/ncsnpp-ffhq-ve-dummy-update'''							)
       model.to(a__							)

       UpperCamelCase__							:				Union[str, Any]          =      4
       UpperCamelCase__							:				Tuple          =      3
       UpperCamelCase__							:				int          =      (32, 32)

       UpperCamelCase__							:				List[str]          =      torch.ones((batch_size, num_channels) + sizes							).to(a__							)
       UpperCamelCase__							:				List[Any]          =      torch.tensor(batch_size * [1E-4]							).to(a__							)

       with torch.no_grad():
           UpperCamelCase__							:				int          =      model(a__,		a__							).sample

       UpperCamelCase__							:				Tuple          =      output[0, -3:, -3:, -1].flatten().cpu()
       # fmt: off
       UpperCamelCase__							:				Optional[Any]          =      torch.tensor([-0.0325, -0.0900, -0.0869, -0.0332, -0.0725, -0.0270, -0.0101, 0.0227, 0.0256]							)
       # fmt: on

       self.assertTrue(torch_all_close(a__,		a__,		rtol=1E-2							)							)




   def       UpperCamelCase__  (    self							) ->      Optional[int]:






       """simple docstring"""
       # not required for this model
       pass


"""simple docstring"""




import unittest

from transformers import DebertaVaConfig, 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 (
         DebertaVaForMaskedLM,
         DebertaVaForMultipleChoice,
         DebertaVaForQuestionAnswering,
         DebertaVaForSequenceClassification,
         DebertaVaForTokenClassification,
         DebertaVaModel,
     )
     from transformers.models.deberta_va.modeling_deberta_va import DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST
class 						__A							( SCREAMING_SNAKE_CASE_		):






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






     def     __A  (		self  ):
       _lowerCAmelCase						:       int  			=     ids_tensor([self.batch_size, self.seq_length]				,     self.vocab_size  )

       _lowerCAmelCase						:       Optional[Any]  			=     None
       if self.use_input_mask:
         _lowerCAmelCase						:       str  			=     ids_tensor([self.batch_size, self.seq_length]				,     vocab_size=2  )

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

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

       _lowerCAmelCase						:       List[str]  			=     self.get_config()

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






     def     __A  (		self  ):
       return DebertaVaConfig(
           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     __A  (		self				,     a__  ):
       self.parent.assertListEqual(list(result.loss.size()  )				,     []  )






     def     __A  (		self				,     a__				,     a__				,     a__				,     a__				,     a__				,     a__				,     a__  ):
       _lowerCAmelCase						:       Union[str, Any]  			=     DebertaVaModel(config=a__  )
       model.to(a__  )
       model.eval()
       _lowerCAmelCase						:       List[Any]  			=     model(a__				,     attention_mask=a__				,     token_type_ids=a__  )[0]
       _lowerCAmelCase						:       List[Any]  			=     model(a__				,     token_type_ids=a__  )[0]
       _lowerCAmelCase						:       Any  			=     model(a__  )[0]

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






     def     __A  (		self				,     a__				,     a__				,     a__				,     a__				,     a__				,     a__				,     a__  ):
       _lowerCAmelCase						:       List[str]  			=     DebertaVaForMaskedLM(config=a__  )
       model.to(a__  )
       model.eval()
       _lowerCAmelCase						:       Optional[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				,     a__				,     a__				,     a__				,     a__				,     a__				,     a__				,     a__  ):
       _lowerCAmelCase						:       int  			=     self.num_labels
       _lowerCAmelCase						:       int  			=     DebertaVaForSequenceClassification(a__  )
       model.to(a__  )
       model.eval()
       _lowerCAmelCase						:       Optional[Any]  			=     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     __A  (		self				,     a__				,     a__				,     a__				,     a__				,     a__				,     a__				,     a__  ):
       _lowerCAmelCase						:       List[Any]  			=     self.num_labels
       _lowerCAmelCase						:       str  			=     DebertaVaForTokenClassification(config=a__  )
       model.to(a__  )
       model.eval()
       _lowerCAmelCase						:       Optional[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				,     a__				,     a__				,     a__				,     a__				,     a__				,     a__				,     a__  ):
       _lowerCAmelCase						:       Any  			=     DebertaVaForQuestionAnswering(config=a__  )
       model.to(a__  )
       model.eval()
       _lowerCAmelCase						:       Dict  			=     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				,     a__				,     a__				,     a__				,     a__				,     a__				,     a__				,     a__  ):
       _lowerCAmelCase						:       Union[str, Any]  			=     DebertaVaForMultipleChoice(config=a__  )
       model.to(a__  )
       model.eval()
       _lowerCAmelCase						:       Optional[int]  			=     input_ids.unsqueeze(1  ).expand(-1				,     self.num_choices				,     -1  ).contiguous()
       _lowerCAmelCase						:       Optional[Any]  			=     token_type_ids.unsqueeze(1  ).expand(-1				,     self.num_choices				,     -1  ).contiguous()
       _lowerCAmelCase						:       str  			=     input_mask.unsqueeze(1  ).expand(-1				,     self.num_choices				,     -1  ).contiguous()
       _lowerCAmelCase						:       List[str]  			=     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  ):
       _lowerCAmelCase						:       Tuple  			=     self.prepare_config_and_inputs()
       (
           (
           _lowerCAmelCase
       )			,	(
           _lowerCAmelCase
       )			,	(
           _lowerCAmelCase
       )			,	(
           _lowerCAmelCase
       )			,	(
           _lowerCAmelCase
       )			,	(
           _lowerCAmelCase
       )			,	(
           _lowerCAmelCase
       )			,	
       )						:       Union[str, Any]  			=     config_and_inputs
       _lowerCAmelCase						:       Union[str, Any]  			=     {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
       return config, inputs_dict







@require_torch
class 						__A							( SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_    ,	unittest.TestCase		):
     _UpperCamelCase							:			Union[str, Any]							=		(
         (
             DebertaVaModel,
             DebertaVaForMaskedLM,
             DebertaVaForSequenceClassification,
             DebertaVaForTokenClassification,
             DebertaVaForQuestionAnswering,
             DebertaVaForMultipleChoice,
         )
         if is_torch_available()
         else ()
     )
     _UpperCamelCase							:			str							=		(
         {
             "feature-extraction": DebertaVaModel,
             "fill-mask": DebertaVaForMaskedLM,
             "question-answering": DebertaVaForQuestionAnswering,
             "text-classification": DebertaVaForSequenceClassification,
             "token-classification": DebertaVaForTokenClassification,
             "zero-shot": DebertaVaForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )

     _UpperCamelCase							:			Optional[Any]							=		True
     _UpperCamelCase							:			List[Any]							=		False
     _UpperCamelCase							:			List[Any]							=		False
     _UpperCamelCase							:			Dict							=		False
     _UpperCamelCase							:			Tuple							=		False






     def     __A  (		self  ):
       _lowerCAmelCase						:       Optional[Any]  			=     DebertaVaModelTester(self  )
       _lowerCAmelCase						:       Any  			=     ConfigTester(self				,     config_class=a__				,     hidden_size=37  )






     def     __A  (		self  ):
       self.config_tester.run_common_tests()






     def     __A  (		self  ):
       _lowerCAmelCase						:       Optional[int]  			=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_deberta_model(*a__  )






     def     __A  (		self  ):
       _lowerCAmelCase						:       List[str]  			=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_deberta_for_sequence_classification(*a__  )






     def     __A  (		self  ):
       _lowerCAmelCase						:       Any  			=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_deberta_for_masked_lm(*a__  )






     def     __A  (		self  ):
       _lowerCAmelCase						:       List[Any]  			=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_deberta_for_question_answering(*a__  )






     def     __A  (		self  ):
       _lowerCAmelCase						:       List[Any]  			=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_deberta_for_token_classification(*a__  )






     def     __A  (		self  ):
       _lowerCAmelCase						:       Union[str, Any]  			=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_deberta_for_multiple_choice(*a__  )






     @slow
     def     __A  (		self  ):
       for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         _lowerCAmelCase						:       Tuple  			=     DebertaVaModel.from_pretrained(a__  )
         self.assertIsNotNone(a__  )







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






     @unittest.skip(reason="""Model not available yet"""  )
     def     __A  (		self  ):
       pass






     @slow
     def     __A  (		self  ):
       _lowerCAmelCase						:       Union[str, Any]  			=     DebertaVaModel.from_pretrained("""microsoft/deberta-v2-xlarge"""  )

       _lowerCAmelCase						:       Dict  			=     torch.tensor([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]  )
       _lowerCAmelCase						:       Any  			=     torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]  )
       with torch.no_grad():
         _lowerCAmelCase						:       Optional[Any]  			=     model(a__				,     attention_mask=a__  )[0]
       # compare the actual values for a slice.
       _lowerCAmelCase						:       str  			=     torch.tensor(
           [[[0.2_3_5_6, 0.1_9_4_8, 0.0_3_6_9], [-0.1_0_6_3, 0.3_5_8_6, -0.5_1_5_2], [-0.6_3_9_9, -0.0_2_5_9, -0.2_5_2_5]]]  )
       self.assertTrue(torch.allclose(output[:, 1:4, 1:4]				,     a__				,     atol=1e-4  )				,     F"{output[:, 1:4, 1:4]}"  )




