






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





    def __init__(							self     : Tuple    ,		A     : Union[str, Any]    ,		A     : str=1_3    ,		A     : Dict=7    ,		A     : Tuple=True    ,		A     : int=True    ,		A     : Dict=True    ,		A     : List[str]=True    ,		A     : str=9_9    ,		A     : Optional[int]=3_2    ,		A     : Optional[Any]=2    ,		A     : Optional[Any]=4    ,		A     : List[str]=3_7    ,		A     : int="gelu"    ,		A     : str=0.1    ,		A     : Union[str, Any]=0.1    ,		A     : str=5_1_2    ,		A     : str=1_6    ,		A     : List[str]=2    ,		A     : Tuple=0.02    ,		A     : Any=False    ,		A     : List[Any]=True    ,		A     : int="None"    ,		A     : str=3    ,		A     : Tuple=4    ,		A     : str=None    ,		):


      '''simple docstring'''




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





    def     lowerCamelCase__				(							self     : Union[str, Any]      ):


      '''simple docstring'''




      a					:      int    =       ids_tensor([self.batch_size, self.seq_length]    ,		self.vocab_size      )

      a					:      Tuple    =       None
      if self.use_input_mask:
        a					:      str    =       random_attention_mask([self.batch_size, self.seq_length]      )

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

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

      a					:      str    =       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     lowerCamelCase__				(							self     : Optional[Any]    ,		A     : Any    ,		A     : str    ,		A     : Union[str, Any]    ,		A     : Dict    ,		A     : Optional[Any]    ,		A     : str    ,		A     : int      ):


      '''simple docstring'''




      a					:      Dict    =       TFDebertaVaModel(config=A      )
      a					:      Optional[int]    =       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

      a					:      int    =       [input_ids, input_mask]
      a					:      Union[str, Any]    =       model(A      )

      a					:      Any    =       model(A      )

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





    def     lowerCamelCase__				(							self     : List[Any]    ,		A     : Optional[int]    ,		A     : Optional[Any]    ,		A     : str    ,		A     : List[str]    ,		A     : str    ,		A     : str    ,		A     : Tuple      ):


      '''simple docstring'''




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





    def     lowerCamelCase__				(							self     : Any    ,		A     : int    ,		A     : Optional[Any]    ,		A     : Tuple    ,		A     : Optional[int]    ,		A     : Union[str, Any]    ,		A     : Tuple    ,		A     : int      ):


      '''simple docstring'''




      a					:      str    =       self.num_labels
      a					:      List[Any]    =       TFDebertaVaForSequenceClassification(config=A      )
      a					:      List[Any]    =       {
          'input_ids': input_ids,
          'attention_mask': input_mask,
          'token_type_ids': token_type_ids,
      }

      a					:      str    =       model(A      )
      self.parent.assertEqual(result.logits.shape    ,		(self.batch_size, self.num_labels)      )





    def     lowerCamelCase__				(							self     : Dict    ,		A     : List[Any]    ,		A     : Optional[int]    ,		A     : List[Any]    ,		A     : Any    ,		A     : Tuple    ,		A     : Any    ,		A     : Union[str, Any]      ):


      '''simple docstring'''




      a					:      List[Any]    =       self.num_labels
      a					:      List[str]    =       TFDebertaVaForTokenClassification(config=A      )
      a					:      Optional[Any]    =       {
          'input_ids': input_ids,
          'attention_mask': input_mask,
          'token_type_ids': token_type_ids,
      }
      a					:      Optional[Any]    =       model(A      )
      self.parent.assertEqual(result.logits.shape    ,		(self.batch_size, self.seq_length, self.num_labels)      )





    def     lowerCamelCase__				(							self     : Any    ,		A     : Dict    ,		A     : str    ,		A     : Tuple    ,		A     : int    ,		A     : Optional[int]    ,		A     : Any    ,		A     : List[str]      ):


      '''simple docstring'''




      a					:      str    =       TFDebertaVaForQuestionAnswering(config=A      )
      a					:      str    =       {
          'input_ids': input_ids,
          'attention_mask': input_mask,
          'token_type_ids': token_type_ids,
      }

      a					:      str    =       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     lowerCamelCase__				(							self     : List[Any]      ):


      '''simple docstring'''




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






@require_tf
class 						snake_case  (  UpperCAmelCase       ,			UpperCAmelCase       ,			unittest.TestCase	):
    __magic_name__   					=					(
        (
            TFDebertaVaModel,
            TFDebertaVaForMaskedLM,
            TFDebertaVaForQuestionAnswering,
            TFDebertaVaForSequenceClassification,
            TFDebertaVaForTokenClassification,
        )
        if is_tf_available()
        else ()
    )
    __magic_name__   					=					(
        {
            '''feature-extraction''': TFDebertaVaModel,
            '''fill-mask''': TFDebertaVaForMaskedLM,
            '''question-answering''': TFDebertaVaForQuestionAnswering,
            '''text-classification''': TFDebertaVaForSequenceClassification,
            '''token-classification''': TFDebertaVaForTokenClassification,
            '''zero-shot''': TFDebertaVaForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )

    __magic_name__   					=					False
    __magic_name__   					=					False





    def     lowerCamelCase__				(							self     : Dict      ):


      '''simple docstring'''




      a					:      Tuple    =       TFDebertaVaModelTester(self      )
      a					:      Union[str, Any]    =       ConfigTester(self    ,		config_class=A    ,		hidden_size=3_7      )





    def     lowerCamelCase__				(							self     : int      ):


      '''simple docstring'''




      self.config_tester.run_common_tests()





    def     lowerCamelCase__				(							self     : Tuple      ):


      '''simple docstring'''




      a					:      Union[str, Any]    =       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*A      )





    def     lowerCamelCase__				(							self     : str      ):


      '''simple docstring'''




      a					:      Union[str, Any]    =       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_lm(*A      )





    def     lowerCamelCase__				(							self     : Any      ):


      '''simple docstring'''




      a					:      Any    =       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*A      )





    def     lowerCamelCase__				(							self     : Any      ):


      '''simple docstring'''




      a					:      Tuple    =       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*A      )





    def     lowerCamelCase__				(							self     : Optional[int]      ):


      '''simple docstring'''




      a					:      Dict    =       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*A      )





    @slow
    def     lowerCamelCase__				(							self     : Dict      ):


      '''simple docstring'''




      a					:      Any    =       TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'      )
      self.assertIsNotNone(A      )






@require_tf
class 						snake_case  (  unittest.TestCase	):





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


      '''simple docstring'''




      pass





    @slow
    def     lowerCamelCase__				(							self     : List[str]      ):


      '''simple docstring'''




      a					:      Any    =       TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'      )
      a					:      Union[str, Any]    =       tf.constant([[0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 4_6_0_7_8, 1_5_8_8, 2]]      )
      a					:      List[Any]    =       tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
      a					:      Union[str, Any]    =       model(A    ,		attention_mask=A      )[0]

      a					:      List[Any]    =       tf.constant(
          [[[0.23_56, 0.19_48, 0.03_69], [-0.10_63, 0.35_86, -0.51_52], [-0.63_99, -0.02_59, -0.25_25]]]      )
      tf.debugging.assert_near(output[:, 1:4, 1:4]    ,		A    ,		atol=1E-4      )












"""simple docstring"""


import logging
from dataclasses import dataclass, field
from pathlib import Path
from typing import Optional, Union

from .generation.configuration_utils import GenerationConfig
from .training_args import TrainingArguments
from .utils import add_start_docstrings


_UpperCamelCase    :   Dict   			=						logging.getLogger(__name__)






@dataclass
@add_start_docstrings(TrainingArguments.__doc__	)
class 						snake_case  (  UpperCAmelCase	):
    __magic_name__   					=					field(default=UpperCAmelCase       ,			metadata={'''help''': '''Whether to use SortishSampler or not.'''}	)
    __magic_name__   					=					field(
        default=UpperCAmelCase       ,			metadata={'''help''': '''Whether to use generate to calculate generative metrics (ROUGE, BLEU).'''}	)
    __magic_name__   					=					field(
        default=UpperCAmelCase       ,			metadata={
            '''help''': (
                '''The `max_length` to use on each evaluation loop when `predict_with_generate=True`. Will default '''
                '''to the `max_length` value of the model configuration.'''
            )
        }       ,			)
    __magic_name__   					=					field(
        default=UpperCAmelCase       ,			metadata={
            '''help''': (
                '''The `num_beams` to use on each evaluation loop when `predict_with_generate=True`. Will default '''
                '''to the `num_beams` value of the model configuration.'''
            )
        }       ,			)
    __magic_name__   					=					field(
        default=UpperCAmelCase       ,			metadata={
            '''help''': '''Model id, file path or url pointing to a GenerationConfig json file, to use during prediction.'''
        }       ,			)





    def     lowerCamelCase__				(							self     : Optional[int]      ):


      '''simple docstring'''




      a					:      List[Any]    =       super().to_dict()
      for k, v in d.items():
        if isinstance(A    ,		A      ):
          a					:      str    =       v.to_dict()
      return d




