






"""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__       (    UpperCAmelCase__				):






      '''simple docstring'''

      def __init__(		self  :						Union[str, Any]		,			lowercase_  :						int		,			lowercase_  :						Any=13		,			lowercase_  :						Any=7		,			lowercase_  :						Optional[int]=True		,			lowercase_  :						Optional[int]=True		,			lowercase_  :						List[Any]=True		,			lowercase_  :						str=True		,			lowercase_  :						Optional[Any]=99		,			lowercase_  :						Any=32		,			lowercase_  :						Optional[Any]=5		,			lowercase_  :						List[Any]=4		,			lowercase_  :						Tuple=37		,			lowercase_  :						int="gelu"		,			lowercase_  :						Tuple=0.1		,			lowercase_  :						Any=0.1		,			lowercase_  :						str=512		,			lowercase_  :						Optional[int]=16		,			lowercase_  :						Dict=2		,			lowercase_  :						List[Any]=0.02		,			lowercase_  :						Union[str, Any]=False		,			lowercase_  :						int=True		,			lowercase_  :						int="None"		,			lowercase_  :						Any=3		,			lowercase_  :						Optional[Any]=4		,			lowercase_  :						Optional[Any]=None		,			):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						str							=	parent
          SCREAMING_SNAKE_CASE_   :						int							=	batch_size
          SCREAMING_SNAKE_CASE_   :						int							=	seq_length
          SCREAMING_SNAKE_CASE_   :						str							=	is_training
          SCREAMING_SNAKE_CASE_   :						Tuple							=	use_input_mask
          SCREAMING_SNAKE_CASE_   :						List[str]							=	use_token_type_ids
          SCREAMING_SNAKE_CASE_   :						Optional[int]							=	use_labels
          SCREAMING_SNAKE_CASE_   :						str							=	vocab_size
          SCREAMING_SNAKE_CASE_   :						Dict							=	hidden_size
          SCREAMING_SNAKE_CASE_   :						Tuple							=	num_hidden_layers
          SCREAMING_SNAKE_CASE_   :						Optional[int]							=	num_attention_heads
          SCREAMING_SNAKE_CASE_   :						Dict							=	intermediate_size
          SCREAMING_SNAKE_CASE_   :						Optional[int]							=	hidden_act
          SCREAMING_SNAKE_CASE_   :						Dict							=	hidden_dropout_prob
          SCREAMING_SNAKE_CASE_   :						List[Any]							=	attention_probs_dropout_prob
          SCREAMING_SNAKE_CASE_   :						List[str]							=	max_position_embeddings
          SCREAMING_SNAKE_CASE_   :						List[Any]							=	type_vocab_size
          SCREAMING_SNAKE_CASE_   :						str							=	type_sequence_label_size
          SCREAMING_SNAKE_CASE_   :						Tuple							=	initializer_range
          SCREAMING_SNAKE_CASE_   :						int							=	num_labels
          SCREAMING_SNAKE_CASE_   :						Dict							=	num_choices
          SCREAMING_SNAKE_CASE_   :						Tuple							=	relative_attention
          SCREAMING_SNAKE_CASE_   :						str							=	position_biased_input
          SCREAMING_SNAKE_CASE_   :						List[Any]							=	pos_att_type
          SCREAMING_SNAKE_CASE_   :						Optional[int]							=	scope
      def _SCREAMING_SNAKE_CASE				(		self  :						List[str]):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						Tuple							=	ids_tensor([self.batch_size, self.seq_length]		,			self.vocab_size)

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

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

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

          SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	self.get_config()

          return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
      def _SCREAMING_SNAKE_CASE				(		self  :						Dict):




          '''simple docstring'''


          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]):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	self.get_config()
          SCREAMING_SNAKE_CASE_   :						Tuple							=	300
          return config
      def _SCREAMING_SNAKE_CASE				(		self  :						Union[str, Any]		,			lowercase_  :						Union[str, Any]):




          '''simple docstring'''


          self.parent.assertListEqual(list(result.loss.size())		,			[])
      def _SCREAMING_SNAKE_CASE				(		self  :						Tuple		,			lowercase_  :						Optional[int]		,			lowercase_  :						List[str]		,			lowercase_  :						List[str]		,			lowercase_  :						str		,			lowercase_  :						Any		,			lowercase_  :						int		,			lowercase_  :						Dict):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						int							=	DebertaModel(config=lowercase_)
          model.to(lowercase_)
          model.eval()
          SCREAMING_SNAKE_CASE_   :						int							=	model(lowercase_		,			attention_mask=lowercase_		,			token_type_ids=lowercase_)[0]
          SCREAMING_SNAKE_CASE_   :						Optional[int]							=	model(lowercase_		,			token_type_ids=lowercase_)[0]
          SCREAMING_SNAKE_CASE_   :						List[str]							=	model(lowercase_)[0]

          self.parent.assertListEqual(list(sequence_output.size())		,			[self.batch_size, self.seq_length, self.hidden_size])
      def _SCREAMING_SNAKE_CASE				(		self  :						str		,			lowercase_  :						List[Any]		,			lowercase_  :						int		,			lowercase_  :						List[Any]		,			lowercase_  :						int		,			lowercase_  :						Dict		,			lowercase_  :						List[str]		,			lowercase_  :						Tuple):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						Tuple							=	DebertaForMaskedLM(config=lowercase_)
          model.to(lowercase_)
          model.eval()
          SCREAMING_SNAKE_CASE_   :						Dict							=	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  :						Tuple		,			lowercase_  :						Optional[Any]		,			lowercase_  :						List[Any]		,			lowercase_  :						str		,			lowercase_  :						Any		,			lowercase_  :						Any		,			lowercase_  :						List[Any]		,			lowercase_  :						List[str]):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						Union[str, Any]							=	self.num_labels
          SCREAMING_SNAKE_CASE_   :						Dict							=	DebertaForSequenceClassification(lowercase_)
          model.to(lowercase_)
          model.eval()
          SCREAMING_SNAKE_CASE_   :						Tuple							=	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  :						Dict		,			lowercase_  :						Optional[int]		,			lowercase_  :						Union[str, Any]		,			lowercase_  :						str		,			lowercase_  :						Optional[int]		,			lowercase_  :						List[Any]		,			lowercase_  :						Optional[int]		,			lowercase_  :						List[Any]):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						Dict							=	self.num_labels
          SCREAMING_SNAKE_CASE_   :						str							=	DebertaForTokenClassification(config=lowercase_)
          model.to(lowercase_)
          model.eval()
          SCREAMING_SNAKE_CASE_   :						List[Any]							=	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  :						List[str]		,			lowercase_  :						List[Any]		,			lowercase_  :						int		,			lowercase_  :						Optional[Any]		,			lowercase_  :						Tuple		,			lowercase_  :						Optional[Any]		,			lowercase_  :						int		,			lowercase_  :						Optional[Any]):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						Dict							=	DebertaForQuestionAnswering(config=lowercase_)
          model.to(lowercase_)
          model.eval()
          SCREAMING_SNAKE_CASE_   :						Union[str, Any]							=	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  :						List[Any]):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						List[Any]							=	self.prepare_config_and_inputs()
          (
              (
              SCREAMING_SNAKE_CASE_
          )		,    (
              SCREAMING_SNAKE_CASE_
          )		,    (
              SCREAMING_SNAKE_CASE_
          )		,    (
              SCREAMING_SNAKE_CASE_
          )		,    (
              SCREAMING_SNAKE_CASE_
          )		,    (
              SCREAMING_SNAKE_CASE_
          )		,    (
              SCREAMING_SNAKE_CASE_
          )		,    
          )   :						List[str]							=	config_and_inputs
          SCREAMING_SNAKE_CASE_   :						Tuple							=	{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
          return config, inputs_dict




@require_torch
class 							lowerCAmelCase__       (    UpperCAmelCase__       ,	UpperCAmelCase__       ,	unittest.TestCase				):






      '''simple docstring'''

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

      __UpperCamelCase							=						True
      __UpperCamelCase							=						False
      __UpperCamelCase							=						False
      __UpperCamelCase							=						False
      __UpperCamelCase							=						False
      def _SCREAMING_SNAKE_CASE				(		self  :						Optional[int]):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						Union[str, Any]							=	DebertaModelTester(self)
          SCREAMING_SNAKE_CASE_   :						Tuple							=	ConfigTester(self		,			config_class=lowercase_		,			hidden_size=37)
      def _SCREAMING_SNAKE_CASE				(		self  :						Optional[int]):




          '''simple docstring'''


          self.config_tester.run_common_tests()
      def _SCREAMING_SNAKE_CASE				(		self  :						Any):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						str							=	self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_deberta_model(*lowercase_)
      def _SCREAMING_SNAKE_CASE				(		self  :						Tuple):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						str							=	self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_deberta_for_sequence_classification(*lowercase_)
      def _SCREAMING_SNAKE_CASE				(		self  :						Tuple):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						Tuple							=	self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_deberta_for_masked_lm(*lowercase_)
      def _SCREAMING_SNAKE_CASE				(		self  :						Any):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						Any							=	self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_deberta_for_question_answering(*lowercase_)
      def _SCREAMING_SNAKE_CASE				(		self  :						Dict):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						Union[str, Any]							=	self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_deberta_for_token_classification(*lowercase_)



      @slow
      def _SCREAMING_SNAKE_CASE				(		self  :						Union[str, Any]):




          '''simple docstring'''


          for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              SCREAMING_SNAKE_CASE_   :						Dict							=	DebertaModel.from_pretrained(lowercase_)
              self.assertIsNotNone(lowercase_)




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






      '''simple docstring'''

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




          '''simple docstring'''


          pass



      @slow
      def _SCREAMING_SNAKE_CASE				(		self  :						Any):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						List[Any]							=	DebertaModel.from_pretrained('''microsoft/deberta-base''')

          SCREAMING_SNAKE_CASE_   :						List[Any]							=	torch.tensor([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]])
          SCREAMING_SNAKE_CASE_   :						Any							=	torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
          with torch.no_grad():
              SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	model(lowercase_		,			attention_mask=lowercase_)[0]
          # compare the actual values for a slice.
          SCREAMING_SNAKE_CASE_   :						int							=	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]		,			lowercase_		,			atol=1e-4)		,			F'{output[:, 1:4, 1:4]}')










"""simple docstring"""






from collections import defaultdict

from graphs.minimum_spanning_tree_prims import prisms_algorithm as mst



def       _A    ()				-> Union[str, Any]:
    """simple docstring"""






    SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_   :						Tuple							=	9, 14  # noqa: F841
    SCREAMING_SNAKE_CASE_   :						Tuple							=	[
        [0, 1, 4],
        [0, 7, 8],
        [1, 2, 8],
        [7, 8, 7],
        [7, 6, 1],
        [2, 8, 2],
        [8, 6, 6],
        [2, 3, 7],
        [2, 5, 4],
        [6, 5, 2],
        [3, 5, 14],
        [3, 4, 9],
        [5, 4, 10],
        [1, 7, 11],
    ]

    SCREAMING_SNAKE_CASE_   :						Dict							=	defaultdict(__a							)
    for nodea, nodea, cost in edges:
        adjancency[nodea].append([nodea, cost]							)
        adjancency[nodea].append([nodea, cost]							)

    SCREAMING_SNAKE_CASE_   :						Any							=	mst(__a							)

    SCREAMING_SNAKE_CASE_   :						Optional[int]							=	[
        [7, 6, 1],
        [2, 8, 2],
        [6, 5, 2],
        [0, 1, 4],
        [2, 5, 4],
        [2, 3, 7],
        [0, 7, 8],
        [3, 4, 9],
    ]

    for answer in expected:
        SCREAMING_SNAKE_CASE_   :						Dict							=	tuple(answer[:2]							)
        SCREAMING_SNAKE_CASE_   :						Optional[int]							=	tuple(edge[::-1]							)
        assert edge in result or reverse in result


