






"""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      a						:






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






    def    UpperCamelCase       (       self     :							Optional[Any]					)     ->		Any:
      lowerCamelCase_         =						ids_tensor([self.batch_size, self.seq_length]       ,						self.vocab_size					)

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

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

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

      lowerCamelCase_         =						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=__SCREAMING_SNAKE_CASE       ,						)

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






    def    UpperCamelCase       (       self     :							Optional[Any]       ,						__SCREAMING_SNAKE_CASE     :							str       ,						__SCREAMING_SNAKE_CASE     :							List[str]       ,						__SCREAMING_SNAKE_CASE     :							Dict       ,						__SCREAMING_SNAKE_CASE     :							Tuple       ,						__SCREAMING_SNAKE_CASE     :							List[str]       ,						__SCREAMING_SNAKE_CASE     :							Any       ,						__SCREAMING_SNAKE_CASE     :							List[Any]					)     ->		Optional[Any]:
      lowerCamelCase_         =						TFDebertaVaModel(config=__SCREAMING_SNAKE_CASE					)
      lowerCamelCase_         =						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

      lowerCamelCase_         =						[input_ids, input_mask]
      lowerCamelCase_         =						model(__SCREAMING_SNAKE_CASE					)

      lowerCamelCase_         =						model(__SCREAMING_SNAKE_CASE					)

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






    def    UpperCamelCase       (       self     :							Any       ,						__SCREAMING_SNAKE_CASE     :							Optional[int]       ,						__SCREAMING_SNAKE_CASE     :							Optional[int]       ,						__SCREAMING_SNAKE_CASE     :							Optional[int]       ,						__SCREAMING_SNAKE_CASE     :							Union[str, Any]       ,						__SCREAMING_SNAKE_CASE     :							int       ,						__SCREAMING_SNAKE_CASE     :							str       ,						__SCREAMING_SNAKE_CASE     :							Dict					)     ->		Optional[Any]:
      lowerCamelCase_         =						TFDebertaVaForMaskedLM(config=__SCREAMING_SNAKE_CASE					)
      lowerCamelCase_         =						{
          'input_ids': input_ids,
          'attention_mask': input_mask,
          'token_type_ids': token_type_ids,
      }
      lowerCamelCase_         =						model(__SCREAMING_SNAKE_CASE					)
      self.parent.assertEqual(result.logits.shape       ,						(self.batch_size, self.seq_length, self.vocab_size)					)






    def    UpperCamelCase       (       self     :							List[str]       ,						__SCREAMING_SNAKE_CASE     :							List[Any]       ,						__SCREAMING_SNAKE_CASE     :							str       ,						__SCREAMING_SNAKE_CASE     :							str       ,						__SCREAMING_SNAKE_CASE     :							str       ,						__SCREAMING_SNAKE_CASE     :							Dict       ,						__SCREAMING_SNAKE_CASE     :							int       ,						__SCREAMING_SNAKE_CASE     :							Union[str, Any]					)     ->		str:
      lowerCamelCase_         =						self.num_labels
      lowerCamelCase_         =						TFDebertaVaForSequenceClassification(config=__SCREAMING_SNAKE_CASE					)
      lowerCamelCase_         =						{
          'input_ids': input_ids,
          'attention_mask': input_mask,
          'token_type_ids': token_type_ids,
      }

      lowerCamelCase_         =						model(__SCREAMING_SNAKE_CASE					)
      self.parent.assertEqual(result.logits.shape       ,						(self.batch_size, self.num_labels)					)






    def    UpperCamelCase       (       self     :							str       ,						__SCREAMING_SNAKE_CASE     :							int       ,						__SCREAMING_SNAKE_CASE     :							Dict       ,						__SCREAMING_SNAKE_CASE     :							Optional[Any]       ,						__SCREAMING_SNAKE_CASE     :							Union[str, Any]       ,						__SCREAMING_SNAKE_CASE     :							Any       ,						__SCREAMING_SNAKE_CASE     :							int       ,						__SCREAMING_SNAKE_CASE     :							Any					)     ->		Union[str, Any]:
      lowerCamelCase_         =						self.num_labels
      lowerCamelCase_         =						TFDebertaVaForTokenClassification(config=__SCREAMING_SNAKE_CASE					)
      lowerCamelCase_         =						{
          'input_ids': input_ids,
          'attention_mask': input_mask,
          'token_type_ids': token_type_ids,
      }
      lowerCamelCase_         =						model(__SCREAMING_SNAKE_CASE					)
      self.parent.assertEqual(result.logits.shape       ,						(self.batch_size, self.seq_length, self.num_labels)					)






    def    UpperCamelCase       (       self     :							Any       ,						__SCREAMING_SNAKE_CASE     :							List[Any]       ,						__SCREAMING_SNAKE_CASE     :							Optional[int]       ,						__SCREAMING_SNAKE_CASE     :							str       ,						__SCREAMING_SNAKE_CASE     :							Union[str, Any]       ,						__SCREAMING_SNAKE_CASE     :							int       ,						__SCREAMING_SNAKE_CASE     :							List[Any]       ,						__SCREAMING_SNAKE_CASE     :							int					)     ->		int:
      lowerCamelCase_         =						TFDebertaVaForQuestionAnswering(config=__SCREAMING_SNAKE_CASE					)
      lowerCamelCase_         =						{
          'input_ids': input_ids,
          'attention_mask': input_mask,
          'token_type_ids': token_type_ids,
      }

      lowerCamelCase_         =						model(__SCREAMING_SNAKE_CASE					)
      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     :							List[str]					)     ->		Dict:
      lowerCamelCase_         =						self.prepare_config_and_inputs()
      (
          (
          lowerCamelCase_
      )     ,	(
          lowerCamelCase_
      )     ,	(
          lowerCamelCase_
      )     ,	(
          lowerCamelCase_
      )     ,	(
          lowerCamelCase_
      )     ,	(
          lowerCamelCase_
      )     ,	(
          lowerCamelCase_
      )     ,	
      )         =						config_and_inputs
      lowerCamelCase_         =						{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
      return config, inputs_dict






@require_tf
class      a						(					__snake_case  ,      __snake_case  ,      unittest.TestCase		):
    SCREAMING_SNAKE_CASE						:     str						= (
        (
            TFDebertaVaModel,
            TFDebertaVaForMaskedLM,
            TFDebertaVaForQuestionAnswering,
            TFDebertaVaForSequenceClassification,
            TFDebertaVaForTokenClassification,
        )
        if is_tf_available()
        else ()
    )
    SCREAMING_SNAKE_CASE						:     Optional[int]						= (
        {
            """feature-extraction""": TFDebertaVaModel,
            """fill-mask""": TFDebertaVaForMaskedLM,
            """question-answering""": TFDebertaVaForQuestionAnswering,
            """text-classification""": TFDebertaVaForSequenceClassification,
            """token-classification""": TFDebertaVaForTokenClassification,
            """zero-shot""": TFDebertaVaForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )

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






    def    UpperCamelCase       (       self     :							Optional[int]					)     ->		Tuple:
      lowerCamelCase_         =						TFDebertaVaModelTester(self					)
      lowerCamelCase_         =						ConfigTester(self       ,						config_class=__SCREAMING_SNAKE_CASE       ,						hidden_size=37					)






    def    UpperCamelCase       (       self     :							List[str]					)     ->		int:
      self.config_tester.run_common_tests()






    def    UpperCamelCase       (       self     :							int					)     ->		Tuple:
      lowerCamelCase_         =						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE					)






    def    UpperCamelCase       (       self     :							List[Any]					)     ->		str:
      lowerCamelCase_         =						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_lm(*__SCREAMING_SNAKE_CASE					)






    def    UpperCamelCase       (       self     :							Optional[Any]					)     ->		Any:
      lowerCamelCase_         =						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*__SCREAMING_SNAKE_CASE					)






    def    UpperCamelCase       (       self     :							int					)     ->		Tuple:
      lowerCamelCase_         =						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*__SCREAMING_SNAKE_CASE					)






    def    UpperCamelCase       (       self     :							Any					)     ->		List[Any]:
      lowerCamelCase_         =						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*__SCREAMING_SNAKE_CASE					)






    @slow
    def    UpperCamelCase       (       self     :							List[str]					)     ->		Optional[int]:
      lowerCamelCase_         =						TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'					)
      self.assertIsNotNone(__SCREAMING_SNAKE_CASE					)






@require_tf
class      a						(					unittest.TestCase		):






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






    @slow
    def    UpperCamelCase       (       self     :							List[Any]					)     ->		str:
      lowerCamelCase_         =						TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'					)
      lowerCamelCase_         =						tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]					)
      lowerCamelCase_         =						tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]					)
      lowerCamelCase_         =						model(__SCREAMING_SNAKE_CASE       ,						attention_mask=__SCREAMING_SNAKE_CASE					)[0]

      lowerCamelCase_         =						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]       ,						__SCREAMING_SNAKE_CASE       ,						atol=1e-4					)












"""simple docstring"""





import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_lxmert import LxmertTokenizer


_SCREAMING_SNAKE_CASE					:				Union[str, Any]					    =						{'''vocab_file''': '''vocab.txt''', '''tokenizer_file''': '''tokenizer.json'''}

_SCREAMING_SNAKE_CASE					:				Union[str, Any]					    =						{
    '''vocab_file''': {
        '''unc-nlp/lxmert-base-uncased''': '''https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/vocab.txt''',
    },
    '''tokenizer_file''': {
        '''unc-nlp/lxmert-base-uncased''': (
            '''https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/tokenizer.json'''
        ),
    },
}

_SCREAMING_SNAKE_CASE					:				Any					    =						{
    '''unc-nlp/lxmert-base-uncased''': 512,
}

_SCREAMING_SNAKE_CASE					:				int					    =						{
    '''unc-nlp/lxmert-base-uncased''': {'''do_lower_case''': True},
}






class      a						(					__snake_case		):
    SCREAMING_SNAKE_CASE						:     int						= VOCAB_FILES_NAMES
    SCREAMING_SNAKE_CASE						:     Optional[Any]						= PRETRAINED_VOCAB_FILES_MAP
    SCREAMING_SNAKE_CASE						:     Any						= PRETRAINED_INIT_CONFIGURATION
    SCREAMING_SNAKE_CASE						:     Any						= PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    SCREAMING_SNAKE_CASE						:     Optional[Any]						= LxmertTokenizer






    def __init__(       self     :							str       ,						__SCREAMING_SNAKE_CASE     :							Optional[Any]=None       ,						__SCREAMING_SNAKE_CASE     :							Optional[Any]=None       ,						__SCREAMING_SNAKE_CASE     :							str=True       ,						__SCREAMING_SNAKE_CASE     :							List[Any]="[UNK]"       ,						__SCREAMING_SNAKE_CASE     :							int="[SEP]"       ,						__SCREAMING_SNAKE_CASE     :							int="[PAD]"       ,						__SCREAMING_SNAKE_CASE     :							List[Any]="[CLS]"       ,						__SCREAMING_SNAKE_CASE     :							Any="[MASK]"       ,						__SCREAMING_SNAKE_CASE     :							List[str]=True       ,						__SCREAMING_SNAKE_CASE     :							List[str]=None       ,						**__SCREAMING_SNAKE_CASE     :							Any       ,						)     ->		Any:
      super().__init__(
          __SCREAMING_SNAKE_CASE       ,						tokenizer_file=__SCREAMING_SNAKE_CASE       ,						do_lower_case=__SCREAMING_SNAKE_CASE       ,						unk_token=__SCREAMING_SNAKE_CASE       ,						sep_token=__SCREAMING_SNAKE_CASE       ,						pad_token=__SCREAMING_SNAKE_CASE       ,						cls_token=__SCREAMING_SNAKE_CASE       ,						mask_token=__SCREAMING_SNAKE_CASE       ,						tokenize_chinese_chars=__SCREAMING_SNAKE_CASE       ,						strip_accents=__SCREAMING_SNAKE_CASE       ,						**__SCREAMING_SNAKE_CASE       ,						)

      lowerCamelCase_         =						json.loads(self.backend_tokenizer.normalizer.__getstate__()					)
      if (
          normalizer_state.get('lowercase'       ,						__SCREAMING_SNAKE_CASE					) != do_lower_case
          or normalizer_state.get('strip_accents'       ,						__SCREAMING_SNAKE_CASE					) != strip_accents
          or normalizer_state.get('handle_chinese_chars'       ,						__SCREAMING_SNAKE_CASE					) != tokenize_chinese_chars
      ):
        lowerCamelCase_         =						getattr(__SCREAMING_SNAKE_CASE       ,						normalizer_state.pop('type'					)					)
        lowerCamelCase_         =						do_lower_case
        lowerCamelCase_         =						strip_accents
        lowerCamelCase_         =						tokenize_chinese_chars
        lowerCamelCase_         =						normalizer_class(**__SCREAMING_SNAKE_CASE					)

      lowerCamelCase_         =						do_lower_case






    def    UpperCamelCase       (       self     :							Tuple       ,						__SCREAMING_SNAKE_CASE     :							Union[str, Any]       ,						__SCREAMING_SNAKE_CASE     :							Tuple=None					)     ->		Dict:
      lowerCamelCase_         =						[self.cls_token_id] + token_ids_a + [self.sep_token_id]

      if token_ids_a:
        output += token_ids_a + [self.sep_token_id]

      return output






    def    UpperCamelCase       (       self     :							str       ,						__SCREAMING_SNAKE_CASE     :							List[int]       ,						__SCREAMING_SNAKE_CASE     :							Optional[List[int]] = None					)     ->		List[int]:
      lowerCamelCase_         =						[self.sep_token_id]
      lowerCamelCase_         =						[self.cls_token_id]
      if token_ids_a is None:
        return len(cls + token_ids_a + sep					) * [0]
      return len(cls + token_ids_a + sep					) * [0] + len(token_ids_a + sep					) * [1]






    def    UpperCamelCase       (       self     :							List[str]       ,						__SCREAMING_SNAKE_CASE     :							str       ,						__SCREAMING_SNAKE_CASE     :							Optional[str] = None					)     ->		Tuple[str]:
      lowerCamelCase_         =						self._tokenizer.model.save(__SCREAMING_SNAKE_CASE       ,						name=__SCREAMING_SNAKE_CASE					)
      return tuple(__SCREAMING_SNAKE_CASE					)




