


'''simple docstring'''


import math
import time

from transformers import Trainer, is_torch_tpu_available
from transformers.trainer_utils import PredictionOutput, speed_metrics


if is_torch_tpu_available(check_device=False):
  import torch_xla.core.xla_model as xm
  import torch_xla.debug.metrics as met



class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  def __init__(							self :       List[Any]	,*_a :       List[Any]	,_a :       Optional[Any]=None	,_a :       int=None	,**_a :       Tuple ):

        '''simple docstring'''




        super().__init__(*_a	,**_a )
        A_						:  Tuple          =				eval_examples
        A_						:  Optional[int]          =				post_process_function






  def        _a							(							self :       Tuple	,_a :       Tuple=None	,_a :       Union[str, Any]=None	,_a :       List[Any]=None	,_a :       str = "eval" ):

        '''simple docstring'''




        A_						:  str          =				self.eval_dataset if eval_dataset is None else eval_dataset
        A_						:  Optional[Any]          =				self.get_eval_dataloader(_a )
        A_						:  Union[str, Any]          =				self.eval_examples if eval_examples is None else eval_examples

        # Temporarily disable metric computation, we will do it in the loop here.
        A_						:  List[str]          =				self.compute_metrics
        A_						:  Tuple          =				None
        A_						:  Optional[Any]          =				self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
        A_						:  List[str]          =				time.time()
        try:
              A_						:  Dict          =				eval_loop(
                  _a	,description="""Evaluation"""	,prediction_loss_only=True if compute_metrics is None else None	,ignore_keys=_a	,metric_key_prefix=_a	,)
        finally:
              A_						:  Optional[Any]          =				compute_metrics
        A_						:  Tuple          =				self.args.eval_batch_size * self.args.world_size
        if f'{metric_key_prefix}_jit_compilation_time' in output.metrics:
              start_time += output.metrics[f'{metric_key_prefix}_jit_compilation_time']
        output.metrics.update(
            speed_metrics(
                _a	,_a	,num_samples=output.num_samples	,num_steps=math.ceil(output.num_samples / total_batch_size )	,) )
        if self.post_process_function is not None and self.compute_metrics is not None and self.args.should_save:
              # Only the main node write the results by default
              A_						:  int          =				self.post_process_function(_a	,_a	,output.predictions )
              A_						:  str          =				self.compute_metrics(_a )

              # Prefix all keys with metric_key_prefix + '_'
              for key in list(metrics.keys() ):
                    if not key.startswith(f'{metric_key_prefix}_' ):
                          A_						:  List[Any]          =				metrics.pop(_a )
              metrics.update(output.metrics )
        else:
              A_						:  List[Any]          =				output.metrics

        if self.args.should_log:
              # Only the main node log the results by default
              self.log(_a )

        if self.args.tpu_metrics_debug or self.args.debug:
              # tpu-comment: Logging debug metrics for PyTorch/XLA (compile, execute times, ops, etc.)
              xm.master_print(met.metrics_report() )

        A_						:  List[Any]          =				self.callback_handler.on_evaluate(self.args	,self.state	,self.control	,_a )
        return metrics






  def        _a							(							self :       Optional[Any]	,_a :       Dict	,_a :       List[Any]	,_a :       List[Any]=None	,_a :       str = "test" ):

        '''simple docstring'''




        A_						:  str          =				self.get_test_dataloader(_a )

        # Temporarily disable metric computation, we will do it in the loop here.
        A_						:  Any          =				self.compute_metrics
        A_						:  List[Any]          =				None
        A_						:  int          =				self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
        A_						:  int          =				time.time()
        try:
              A_						:  str          =				eval_loop(
                  _a	,description="""Prediction"""	,prediction_loss_only=True if compute_metrics is None else None	,ignore_keys=_a	,metric_key_prefix=_a	,)
        finally:
              A_						:  Tuple          =				compute_metrics
        A_						:  Optional[Any]          =				self.args.eval_batch_size * self.args.world_size
        if f'{metric_key_prefix}_jit_compilation_time' in output.metrics:
              start_time += output.metrics[f'{metric_key_prefix}_jit_compilation_time']
        output.metrics.update(
            speed_metrics(
                _a	,_a	,num_samples=output.num_samples	,num_steps=math.ceil(output.num_samples / total_batch_size )	,) )

        if self.post_process_function is None or self.compute_metrics is None:
              return output

        A_						:  Any          =				self.post_process_function(_a	,_a	,output.predictions	,"""predict""" )
        A_						:  Union[str, Any]          =				self.compute_metrics(_a )

        # Prefix all keys with metric_key_prefix + '_'
        for key in list(metrics.keys() ):
              if not key.startswith(f'{metric_key_prefix}_' ):
                    A_						:  str          =				metrics.pop(_a )
        metrics.update(output.metrics )
        return PredictionOutput(predictions=predictions.predictions	,label_ids=predictions.label_ids	,metrics=_a )




'''simple docstring'''


from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union

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


if TYPE_CHECKING:
     from ... import FeatureExtractionMixin, PreTrainedTokenizerBase, TensorType


__magic_name__			=      logging.get_logger(__name__)

__magic_name__			=      {
    'microsoft/deberta-v2-xlarge': 'https://huggingface.co/microsoft/deberta-v2-xlarge/resolve/main/config.json',
    'microsoft/deberta-v2-xxlarge': 'https://huggingface.co/microsoft/deberta-v2-xxlarge/resolve/main/config.json',
    'microsoft/deberta-v2-xlarge-mnli': (
        'https://huggingface.co/microsoft/deberta-v2-xlarge-mnli/resolve/main/config.json'
    ),
    'microsoft/deberta-v2-xxlarge-mnli': (
        'https://huggingface.co/microsoft/deberta-v2-xxlarge-mnli/resolve/main/config.json'
    ),
}



class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  a_  					=							"""deberta-v2"""






  def __init__(							self :       Optional[Any]	,_a :       Union[str, Any]=128100	,_a :       Optional[int]=1536	,_a :       Dict=24	,_a :       int=24	,_a :       Tuple=6144	,_a :       Union[str, Any]="gelu"	,_a :       List[Any]=0.1	,_a :       Dict=0.1	,_a :       int=512	,_a :       int=0	,_a :       int=0.02	,_a :       int=1e-7	,_a :       List[str]=False	,_a :       Union[str, Any]=-1	,_a :       List[Any]=0	,_a :       Optional[Any]=True	,_a :       Tuple=None	,_a :       Any=0	,_a :       int="gelu"	,**_a :       Any	,):

        '''simple docstring'''




        super().__init__(**_a )

        A_						:  Union[str, Any]          =				hidden_size
        A_						:  Dict          =				num_hidden_layers
        A_						:  Union[str, Any]          =				num_attention_heads
        A_						:  List[Any]          =				intermediate_size
        A_						:  List[Any]          =				hidden_act
        A_						:  Optional[int]          =				hidden_dropout_prob
        A_						:  Dict          =				attention_probs_dropout_prob
        A_						:  int          =				max_position_embeddings
        A_						:  Any          =				type_vocab_size
        A_						:  List[Any]          =				initializer_range
        A_						:  int          =				relative_attention
        A_						:  Tuple          =				max_relative_positions
        A_						:  int          =				pad_token_id
        A_						:  Tuple          =				position_biased_input

        # Backwards compatibility
        if type(_a ) == str:
              A_						:  str          =				[x.strip() for x in pos_att_type.lower().split("""|""" )]

        A_						:  Any          =				pos_att_type
        A_						:  Optional[int]          =				vocab_size
        A_						:  Tuple          =				layer_norm_eps

        A_						:  Any          =				kwargs.get("""pooler_hidden_size"""	,_a )
        A_						:  Union[str, Any]          =				pooler_dropout
        A_						:  List[Any]          =				pooler_hidden_act







class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  @property
  def        _a							(							self :       Any ):

        '''simple docstring'''




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






  @property
  def        _a							(							self :       Optional[int] ):

        '''simple docstring'''




        return 12






  def        _a							(							self :       int	,_a :       Union["PreTrainedTokenizerBase", "FeatureExtractionMixin"]	,_a :       int = -1	,_a :       int = -1	,_a :       int = -1	,_a :       bool = False	,_a :       Optional["TensorType"] = None	,_a :       int = 3	,_a :       int = 40	,_a :       int = 40	,_a :       "PreTrainedTokenizerBase" = None	,):

        '''simple docstring'''




        A_						:  Any          =				super().generate_dummy_inputs(preprocessor=_a	,framework=_a )
        if self._config.type_vocab_size == 0 and "token_type_ids" in dummy_inputs:
              del dummy_inputs["token_type_ids"]
        return dummy_inputs
