




'''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        UpperCamelCase_					:

    '''simple docstring'''






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





           '''simple docstring'''

           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   :			Dict)		->Optional[Any]:





           '''simple docstring'''

           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=_A      ,				)

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


    def  SCREAMING_SNAKE_CASE							(    self   :			Dict      ,				UpperCAmelCase__   :			Tuple      ,				UpperCAmelCase__   :			Tuple      ,				UpperCAmelCase__   :			Union[str, Any]      ,				UpperCAmelCase__   :			List[str]      ,				UpperCAmelCase__   :			Optional[int]      ,				UpperCAmelCase__   :			int      ,				UpperCAmelCase__   :			Optional[Any])		->int:





           '''simple docstring'''

           A__   				=					TFDebertaVaModel(config=_A)
           A__   				=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

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

           A__   				=					model(_A)

           self.parent.assertEqual(result.last_hidden_state.shape      ,				(self.batch_size, self.seq_length, self.hidden_size))


    def  SCREAMING_SNAKE_CASE							(    self   :			Dict      ,				UpperCAmelCase__   :			Optional[int]      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			Dict      ,				UpperCAmelCase__   :			Union[str, Any]      ,				UpperCAmelCase__   :			Union[str, Any]      ,				UpperCAmelCase__   :			List[Any]      ,				UpperCAmelCase__   :			List[str])		->Optional[Any]:





           '''simple docstring'''

           A__   				=					TFDebertaVaForMaskedLM(config=_A)
           A__   				=					{
               '''input_ids''': input_ids,
               '''attention_mask''': input_mask,
               '''token_type_ids''': token_type_ids,
           }
           A__   				=					model(_A)
           self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.seq_length, self.vocab_size))


    def  SCREAMING_SNAKE_CASE							(    self   :			Dict      ,				UpperCAmelCase__   :			Dict      ,				UpperCAmelCase__   :			List[str]      ,				UpperCAmelCase__   :			List[Any]      ,				UpperCAmelCase__   :			List[Any]      ,				UpperCAmelCase__   :			Optional[Any]      ,				UpperCAmelCase__   :			Tuple      ,				UpperCAmelCase__   :			int)		->List[Any]:





           '''simple docstring'''

           A__   				=					self.num_labels
           A__   				=					TFDebertaVaForSequenceClassification(config=_A)
           A__   				=					{
               '''input_ids''': input_ids,
               '''attention_mask''': input_mask,
               '''token_type_ids''': token_type_ids,
           }

           A__   				=					model(_A)
           self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.num_labels))


    def  SCREAMING_SNAKE_CASE							(    self   :			Tuple      ,				UpperCAmelCase__   :			Dict      ,				UpperCAmelCase__   :			Optional[int]      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			List[Any]      ,				UpperCAmelCase__   :			Dict      ,				UpperCAmelCase__   :			Union[str, Any]      ,				UpperCAmelCase__   :			List[str])		->int:





           '''simple docstring'''

           A__   				=					self.num_labels
           A__   				=					TFDebertaVaForTokenClassification(config=_A)
           A__   				=					{
               '''input_ids''': input_ids,
               '''attention_mask''': input_mask,
               '''token_type_ids''': token_type_ids,
           }
           A__   				=					model(_A)
           self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.seq_length, self.num_labels))


    def  SCREAMING_SNAKE_CASE							(    self   :			Dict      ,				UpperCAmelCase__   :			Optional[Any]      ,				UpperCAmelCase__   :			Optional[int]      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			List[str]      ,				UpperCAmelCase__   :			str      ,				UpperCAmelCase__   :			Optional[int]      ,				UpperCAmelCase__   :			str)		->Any:





           '''simple docstring'''

           A__   				=					TFDebertaVaForQuestionAnswering(config=_A)
           A__   				=					{
               '''input_ids''': input_ids,
               '''attention_mask''': input_mask,
               '''token_type_ids''': token_type_ids,
           }

           A__   				=					model(_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   :			Any)		->int:





           '''simple docstring'''

           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        UpperCamelCase_					(				__lowercase	,      __lowercase	,      unittest.TestCase  ):

    '''simple docstring'''






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

    UpperCAmelCase__													=   False
    UpperCAmelCase__													=   False


    def  SCREAMING_SNAKE_CASE							(    self   :			List[Any])		->Optional[Any]:





           '''simple docstring'''

           A__   				=					TFDebertaVaModelTester(self)
           A__   				=					ConfigTester(self      ,				config_class=_A      ,				hidden_size=37)


    def  SCREAMING_SNAKE_CASE							(    self   :			Any)		->int:





           '''simple docstring'''

           self.config_tester.run_common_tests()


    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[int])		->Any:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*_A)


    def  SCREAMING_SNAKE_CASE							(    self   :			int)		->List[Any]:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_lm(*_A)


    def  SCREAMING_SNAKE_CASE							(    self   :			Dict)		->List[str]:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_question_answering(*_A)


    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[int])		->Union[str, Any]:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_sequence_classification(*_A)


    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[int])		->str:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*_A)





    @slow
    def  SCREAMING_SNAKE_CASE							(    self   :			Any)		->str:





           '''simple docstring'''

           A__   				=					TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge''')
           self.assertIsNotNone(_A)


@require_tf
class        UpperCamelCase_					(				unittest.TestCase  ):

    '''simple docstring'''






    @unittest.skip(reason='''Model not available yet''')
    def  SCREAMING_SNAKE_CASE							(    self   :			List[Any])		->int:





           '''simple docstring'''

           pass





    @slow
    def  SCREAMING_SNAKE_CASE							(    self   :			int)		->Optional[Any]:





           '''simple docstring'''

           A__   				=					TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge''')
           A__   				=					tf.constant([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]])
           A__   				=					tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
           A__   				=					model(_A      ,				attention_mask=_A)[0]

           A__   				=					tf.constant(
               [[[0.2356, 0.1948, 0.0369], [-0.1063, 0.3586, -0.5152], [-0.6399, -0.0259, -0.2525]]])
           tf.debugging.assert_near(output[:, 1:4, 1:4]      ,				_A      ,				atol=1e-4)








from collections import OrderedDict
from typing import Mapping

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


_lowerCamelCase			:	List[Any]							 =     logging.get_logger(__name__)

_lowerCamelCase			:	Dict							 =     {
    """xlm-mlm-en-2048""": """https://huggingface.co/xlm-mlm-en-2048/resolve/main/config.json""",
    """xlm-mlm-ende-1024""": """https://huggingface.co/xlm-mlm-ende-1024/resolve/main/config.json""",
    """xlm-mlm-enfr-1024""": """https://huggingface.co/xlm-mlm-enfr-1024/resolve/main/config.json""",
    """xlm-mlm-enro-1024""": """https://huggingface.co/xlm-mlm-enro-1024/resolve/main/config.json""",
    """xlm-mlm-tlm-xnli15-1024""": """https://huggingface.co/xlm-mlm-tlm-xnli15-1024/resolve/main/config.json""",
    """xlm-mlm-xnli15-1024""": """https://huggingface.co/xlm-mlm-xnli15-1024/resolve/main/config.json""",
    """xlm-clm-enfr-1024""": """https://huggingface.co/xlm-clm-enfr-1024/resolve/main/config.json""",
    """xlm-clm-ende-1024""": """https://huggingface.co/xlm-clm-ende-1024/resolve/main/config.json""",
    """xlm-mlm-17-1280""": """https://huggingface.co/xlm-mlm-17-1280/resolve/main/config.json""",
    """xlm-mlm-100-1280""": """https://huggingface.co/xlm-mlm-100-1280/resolve/main/config.json""",
}


class        UpperCamelCase_					(				UpperCAmelCase__  ):

    '''simple docstring'''






    UpperCAmelCase__													=   '''xlm'''
    UpperCAmelCase__													=   {
        '''hidden_size''': '''emb_dim''',
        '''num_attention_heads''': '''n_heads''',
        '''num_hidden_layers''': '''n_layers''',
        '''n_words''': '''vocab_size''',  # For backward compatibility
    }


    def __init__(    self   :			Tuple      ,				UpperCAmelCase__   :			Optional[Any]=30_145      ,				UpperCAmelCase__   :			List[str]=2_048      ,				UpperCAmelCase__   :			str=12      ,				UpperCAmelCase__   :			List[Any]=16      ,				UpperCAmelCase__   :			Dict=0.1      ,				UpperCAmelCase__   :			Tuple=0.1      ,				UpperCAmelCase__   :			str=True      ,				UpperCAmelCase__   :			Union[str, Any]=False      ,				UpperCAmelCase__   :			str=False      ,				UpperCAmelCase__   :			Optional[int]=False      ,				UpperCAmelCase__   :			List[str]=1      ,				UpperCAmelCase__   :			List[Any]=True      ,				UpperCAmelCase__   :			Union[str, Any]=512      ,				UpperCAmelCase__   :			List[str]=2_048**-0.5      ,				UpperCAmelCase__   :			List[Any]=1e-12      ,				UpperCAmelCase__   :			Any=0.02      ,				UpperCAmelCase__   :			str=0      ,				UpperCAmelCase__   :			int=1      ,				UpperCAmelCase__   :			Union[str, Any]=2      ,				UpperCAmelCase__   :			List[Any]=3      ,				UpperCAmelCase__   :			int=5      ,				UpperCAmelCase__   :			Any=True      ,				UpperCAmelCase__   :			Tuple="first"      ,				UpperCAmelCase__   :			Optional[int]=True      ,				UpperCAmelCase__   :			List[str]=None      ,				UpperCAmelCase__   :			Tuple=True      ,				UpperCAmelCase__   :			Dict=0.1      ,				UpperCAmelCase__   :			Any=5      ,				UpperCAmelCase__   :			List[Any]=5      ,				UpperCAmelCase__   :			int=0      ,				UpperCAmelCase__   :			Dict=0      ,				UpperCAmelCase__   :			Dict=2      ,				UpperCAmelCase__   :			str=0      ,				**UpperCAmelCase__   :			List[str]      ,				)		->str:





           '''simple docstring'''

           A__   				=					vocab_size
           A__   				=					emb_dim
           A__   				=					n_layers
           A__   				=					n_heads
           A__   				=					dropout
           A__   				=					attention_dropout
           A__   				=					gelu_activation
           A__   				=					sinusoidal_embeddings
           A__   				=					causal
           A__   				=					asm
           A__   				=					n_langs
           A__   				=					use_lang_emb
           A__   				=					layer_norm_eps
           A__   				=					bos_index
           A__   				=					eos_index
           A__   				=					pad_index
           A__   				=					unk_index
           A__   				=					mask_index
           A__   				=					is_encoder
           A__   				=					max_position_embeddings
           A__   				=					embed_init_std
           A__   				=					init_std
           A__   				=					summary_type
           A__   				=					summary_use_proj
           A__   				=					summary_activation
           A__   				=					summary_proj_to_labels
           A__   				=					summary_first_dropout
           A__   				=					start_n_top
           A__   				=					end_n_top
           A__   				=					mask_token_id
           A__   				=					lang_id

           if "n_words" in kwargs:
                  A__   				=					kwargs['''n_words''']

           super().__init__(pad_token_id=UpperCAmelCase__      ,				bos_token_id=UpperCAmelCase__      ,				**UpperCAmelCase__)


class        UpperCamelCase_					(				UpperCAmelCase__  ):

    '''simple docstring'''






    @property
    def  SCREAMING_SNAKE_CASE							(    self   :			Dict)		->Mapping[str, Mapping[int, str]]:





           '''simple docstring'''

           if self.task == "multiple-choice":
                  A__   				=					{0: '''batch''', 1: '''choice''', 2: '''sequence'''}
           else:
                  A__   				=					{0: '''batch''', 1: '''sequence'''}
           return OrderedDict(
               [
                   ('''input_ids''', dynamic_axis),
                   ('''attention_mask''', dynamic_axis),
                   ('''token_type_ids''', dynamic_axis),
               ])


