'''simple docstring'''






from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

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


if is_tf_available():
   import tensorflow as tf

   from transformers import (
       TFDebertaVaForMaskedLM,
       TFDebertaVaForQuestionAnswering,
       TFDebertaVaForSequenceClassification,
       TFDebertaVaForTokenClassification,
       TFDebertaVaModel,
   )







class lowercase_       :







   """simple docstring"""

   def __init__(      self      :			str, UpperCamelCase__      :			Optional[int], UpperCamelCase__      :			int=13, UpperCamelCase__      :			int=7, UpperCamelCase__      :			List[str]=True, UpperCamelCase__      :			Union[str, Any]=True, UpperCamelCase__      :			str=True, UpperCamelCase__      :			Optional[Any]=True, UpperCamelCase__      :			Dict=99, UpperCamelCase__      :			Any=32, UpperCamelCase__      :			str=2, UpperCamelCase__      :			Union[str, Any]=4, UpperCamelCase__      :			Any=37, UpperCamelCase__      :			List[str]="gelu", UpperCamelCase__      :			Any=0.1, UpperCamelCase__      :			int=0.1, UpperCamelCase__      :			List[Any]=5_12, UpperCamelCase__      :			List[str]=16, UpperCamelCase__      :			int=2, UpperCamelCase__      :			Union[str, Any]=0.02, UpperCamelCase__      :			Optional[int]=False, UpperCamelCase__      :			List[Any]=True, UpperCamelCase__      :			List[str]="None", UpperCamelCase__      :			List[Any]=3, UpperCamelCase__      :			Tuple=4, UpperCamelCase__      :			Dict=None, )  ->			Tuple:
        _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 	__UpperCAmelCase   (      self      :			int     )  ->			int:
        _A    		=  ids_tensor([self.batch_size, self.seq_length], self.vocab_size     )

        _A    		=  None
        if self.use_input_mask:
             _A    		=  random_attention_mask([self.batch_size, self.seq_length]     )

        _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    		=  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, relative_attention=self.relative_attention, position_biased_input=self.position_biased_input, initializer_range=self.initializer_range, return_dict=UpperCamelCase__, )

        return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
   def 	__UpperCAmelCase   (      self      :			Tuple, UpperCamelCase__      :			Any, UpperCamelCase__      :			Dict, UpperCamelCase__      :			Tuple, UpperCamelCase__      :			Any, UpperCamelCase__      :			Optional[int], UpperCamelCase__      :			int, UpperCamelCase__      :			Optional[int]     )  ->			str:
        _A    		=  TFDebertaVaModel(config=UpperCamelCase__     )
        _A    		=  {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

        _A    		=  [input_ids, input_mask]
        _A    		=  model(UpperCamelCase__     )

        _A    		=  model(UpperCamelCase__     )

        self.parent.assertEqual(result.last_hidden_state.shape, (self.batch_size, self.seq_length, self.hidden_size)     )
   def 	__UpperCAmelCase   (      self      :			Any, UpperCamelCase__      :			Union[str, Any], UpperCamelCase__      :			List[Any], UpperCamelCase__      :			Any, UpperCamelCase__      :			List[Any], UpperCamelCase__      :			Optional[int], UpperCamelCase__      :			int, UpperCamelCase__      :			List[str]     )  ->			Union[str, Any]:
        _A    		=  TFDebertaVaForMaskedLM(config=UpperCamelCase__     )
        _A    		=  {
            'input_ids': input_ids,
            'attention_mask': input_mask,
            'token_type_ids': token_type_ids,
        }
        _A    		=  model(UpperCamelCase__     )
        self.parent.assertEqual(result.logits.shape, (self.batch_size, self.seq_length, self.vocab_size)     )
   def 	__UpperCAmelCase   (      self      :			Optional[Any], UpperCamelCase__      :			int, UpperCamelCase__      :			str, UpperCamelCase__      :			Any, UpperCamelCase__      :			Dict, UpperCamelCase__      :			List[str], UpperCamelCase__      :			Tuple, UpperCamelCase__      :			str     )  ->			List[Any]:
        _A    		=  self.num_labels
        _A    		=  TFDebertaVaForSequenceClassification(config=UpperCamelCase__     )
        _A    		=  {
            'input_ids': input_ids,
            'attention_mask': input_mask,
            'token_type_ids': token_type_ids,
        }

        _A    		=  model(UpperCamelCase__     )
        self.parent.assertEqual(result.logits.shape, (self.batch_size, self.num_labels)     )
   def 	__UpperCAmelCase   (      self      :			Tuple, UpperCamelCase__      :			Tuple, UpperCamelCase__      :			List[str], UpperCamelCase__      :			int, UpperCamelCase__      :			Optional[Any], UpperCamelCase__      :			List[Any], UpperCamelCase__      :			int, UpperCamelCase__      :			List[str]     )  ->			Optional[Any]:
        _A    		=  self.num_labels
        _A    		=  TFDebertaVaForTokenClassification(config=UpperCamelCase__     )
        _A    		=  {
            'input_ids': input_ids,
            'attention_mask': input_mask,
            'token_type_ids': token_type_ids,
        }
        _A    		=  model(UpperCamelCase__     )
        self.parent.assertEqual(result.logits.shape, (self.batch_size, self.seq_length, self.num_labels)     )
   def 	__UpperCAmelCase   (      self      :			Union[str, Any], UpperCamelCase__      :			Tuple, UpperCamelCase__      :			Union[str, Any], UpperCamelCase__      :			int, UpperCamelCase__      :			Tuple, UpperCamelCase__      :			str, UpperCamelCase__      :			Any, UpperCamelCase__      :			Union[str, Any]     )  ->			Any:
        _A    		=  TFDebertaVaForQuestionAnswering(config=UpperCamelCase__     )
        _A    		=  {
            'input_ids': input_ids,
            'attention_mask': input_mask,
            'token_type_ids': token_type_ids,
        }

        _A    		=  model(UpperCamelCase__     )
        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 	__UpperCAmelCase   (      self      :			Tuple     )  ->			str:
        _A    		=  self.prepare_config_and_inputs()
        (
            (
            _A
        )		,       (
            _A
        )		,       (
            _A
        )		,       (
            _A
        )		,       (
            _A
        )		,       (
            _A
        )		,       (
            _A
        )		,       
        )    		=  config_and_inputs
        _A    		=  {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
        return config, inputs_dict







@require_tf
class lowercase_       (		_UpperCamelCase    ,    _UpperCamelCase    ,    unittest.TestCase			):







   """simple docstring"""

   __lowerCAmelCase         =   (
       (
           TFDebertaVaModel,
           TFDebertaVaForMaskedLM,
           TFDebertaVaForQuestionAnswering,
           TFDebertaVaForSequenceClassification,
           TFDebertaVaForTokenClassification,
       )
       if is_tf_available()
       else ()
   )
   __lowerCAmelCase         =   (
       {
           "feature-extraction": TFDebertaVaModel,
           "fill-mask": TFDebertaVaForMaskedLM,
           "question-answering": TFDebertaVaForQuestionAnswering,
           "text-classification": TFDebertaVaForSequenceClassification,
           "token-classification": TFDebertaVaForTokenClassification,
           "zero-shot": TFDebertaVaForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )

   __lowerCAmelCase         =   False
   __lowerCAmelCase         =   False
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			Dict:
        _A    		=  TFDebertaVaModelTester(self     )
        _A    		=  ConfigTester(self, config_class=UpperCamelCase__, hidden_size=37     )
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			Optional[Any]:
        self.config_tester.run_common_tests()
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			List[Any]:
        _A    		=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*UpperCamelCase__     )
   def 	__UpperCAmelCase   (      self      :			Optional[Any]     )  ->			Any:
        _A    		=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase__     )
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			List[Any]:
        _A    		=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*UpperCamelCase__     )
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			Optional[int]:
        _A    		=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase__     )
   def 	__UpperCAmelCase   (      self      :			Any     )  ->			Optional[int]:
        _A    		=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*UpperCamelCase__     )

   @slow
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			Union[str, Any]:
        _A    		=  TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'     )
        self.assertIsNotNone(UpperCamelCase__     )







@require_tf
class lowercase_       (		unittest.TestCase			):







   """simple docstring"""

   @unittest.skip(reason='Model not available yet'     )
   def 	__UpperCAmelCase   (      self      :			int     )  ->			str:
        pass

   @slow
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			int:
        _A    		=  TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'     )
        _A    		=  tf.constant([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]     )
        _A    		=  tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]     )
        _A    		=  model(UpperCamelCase__, attention_mask=UpperCamelCase__     )[0]

        _A    		=  tf.constant(
            [[[0.2_356, 0.1_948, 0.0_369], [-0.1_063, 0.3_586, -0.5_152], [-0.6_399, -0.0_259, -0.2_525]]]     )
        tf.debugging.assert_near(output[:, 1:4, 1:4], UpperCamelCase__, atol=1e-4     )




'''simple docstring'''






import pytest
import requests

from datasets.utils.file_utils import http_head

from .utils import OfflineSimulationMode, RequestWouldHangIndefinitelyError, offline





@pytest.mark.integration
def  _SCREAMING_SNAKE_CASE		(      ):
     with offline(OfflineSimulationMode.CONNECTION_TIMES_OUT				):
          with pytest.raises(__snake_case				):
               requests.request('GET'   ,		'https://huggingface.co'				)
          with pytest.raises(requests.exceptions.ConnectTimeout				):
               requests.request('GET'   ,		'https://huggingface.co'   ,		timeout=1.0				)





@pytest.mark.integration
def  _SCREAMING_SNAKE_CASE		(      ):
     with offline(OfflineSimulationMode.CONNECTION_FAILS				):
          with pytest.raises(requests.exceptions.ConnectionError				):
               requests.request('GET'   ,		'https://huggingface.co'				)





def  _SCREAMING_SNAKE_CASE		(      ):
     with offline(OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1				):
          with pytest.raises(__snake_case				):
               http_head('https://huggingface.co'				)



