




'''simple docstring'''
import math
import time
from typing import Dict, List, Optional

from torch.utils.data import Dataset

from transformers import SeqaSeqTrainer, 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 							A__   (	lowercase_  ):





  def __init__(		self				:     Union[str, Any]							, *_a				:     Optional[int]							, _a				:     Dict=None							, _a				:     Optional[int]=None							, **_a				:     Any			)     ->   Any:





       '''simple docstring'''






       super().__init__(*a__							, **a__			)
       _SCREAMING_SNAKE_CASE							   =eval_examples
       _SCREAMING_SNAKE_CASE							   =post_process_function





  def 						A  (		self				:     Union[str, Any]							, _a				:     Tuple = None							, _a				:     Union[str, Any]=None							, _a				:     Any = None							, _a				:     List[Any] = "eval"							, **_a				:     Any							, )     ->   Dict[str, float]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =gen_kwargs.copy()
       _SCREAMING_SNAKE_CASE							   =(
           gen_kwargs['max_length'] if gen_kwargs.get('max_length'			) is not None else self.args.generation_max_length
       )
       _SCREAMING_SNAKE_CASE							   =(
           gen_kwargs['num_beams'] if gen_kwargs.get('num_beams'			) is not None else self.args.generation_num_beams
       )
       _SCREAMING_SNAKE_CASE							   =gen_kwargs

       _SCREAMING_SNAKE_CASE							   =self.eval_dataset if eval_dataset is None else eval_dataset
       _SCREAMING_SNAKE_CASE							   =self.get_eval_dataloader(a__			)
       _SCREAMING_SNAKE_CASE							   =self.eval_examples if eval_examples is None else eval_examples

       # Temporarily disable metric computation, we will do it in the loop here.
       _SCREAMING_SNAKE_CASE							   =self.compute_metrics
       _SCREAMING_SNAKE_CASE							   =None
       _SCREAMING_SNAKE_CASE							   =time.time()
       _SCREAMING_SNAKE_CASE							   =self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
       try:
            _SCREAMING_SNAKE_CASE							   =eval_loop(
                a__							, description='Evaluation'							, prediction_loss_only=True if compute_metrics is None else None							, ignore_keys=a__							, metric_key_prefix=a__							, )
       finally:
            _SCREAMING_SNAKE_CASE							   =compute_metrics
       _SCREAMING_SNAKE_CASE							   =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
            _SCREAMING_SNAKE_CASE							   =self.post_process_function(a__							, a__							, a__			)
            _SCREAMING_SNAKE_CASE							   =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}_"			):
                      _SCREAMING_SNAKE_CASE							   =metrics.pop(a__			)

            metrics.update(output.metrics			)
       else:
            _SCREAMING_SNAKE_CASE							   =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()			)

       _SCREAMING_SNAKE_CASE							   =self.callback_handler.on_evaluate(self.args							, self.state							, self.control							, a__			)
       return metrics





  def 						A  (		self				:     Tuple							, _a				:     Dict							, _a				:     Union[str, Any]							, _a				:     List[Any]=None							, _a				:     Any = "test"							, **_a				:     Optional[int]			)     ->   List[str]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =gen_kwargs.copy()

       _SCREAMING_SNAKE_CASE							   =self.get_test_dataloader(a__			)

       # Temporarily disable metric computation, we will do it in the loop here.
       _SCREAMING_SNAKE_CASE							   =self.compute_metrics
       _SCREAMING_SNAKE_CASE							   =None
       _SCREAMING_SNAKE_CASE							   =time.time()
       _SCREAMING_SNAKE_CASE							   =self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
       try:
            _SCREAMING_SNAKE_CASE							   =eval_loop(
                a__							, description='Prediction'							, prediction_loss_only=True if compute_metrics is None else None							, ignore_keys=a__							, metric_key_prefix=a__							, )
       finally:
            _SCREAMING_SNAKE_CASE							   =compute_metrics

       _SCREAMING_SNAKE_CASE							   =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

       _SCREAMING_SNAKE_CASE							   =self.post_process_function(a__							, a__							, a__							, 'predict'			)
       _SCREAMING_SNAKE_CASE							   =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}_"			):
                 _SCREAMING_SNAKE_CASE							   =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 Mapping

from packaging import version

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


lowerCamelCase			:				Any 			=					logging.get_logger(__name__)

lowerCamelCase			:				int 			=					{
    "facebook/data2vec-vision-base-ft": (
        "https://huggingface.co/facebook/data2vec-vision-base-ft/resolve/main/config.json"
    ),
}







class 							A__   (	A__  ):
  A__					=    'data2vec-vision'





  def __init__(		self				:     str							, _a				:     Optional[int]=768							, _a				:     List[str]=12							, _a				:     Any=12							, _a				:     Tuple=3072							, _a				:     Optional[Any]="gelu"							, _a				:     Tuple=0.0							, _a				:     str=0.0							, _a				:     Dict=0.02							, _a				:     int=1e-12							, _a				:     List[str]=224							, _a				:     str=16							, _a				:     Dict=3							, _a				:     int=False							, _a				:     List[str]=False							, _a				:     str=False							, _a				:     str=False							, _a				:     Optional[int]=0.1							, _a				:     List[str]=0.1							, _a				:     Dict=True							, _a				:     str=[3, 5, 7, 11]							, _a				:     List[Any]=[1, 2, 3, 6]							, _a				:     Any=True							, _a				:     Optional[Any]=0.4							, _a				:     str=256							, _a				:     Dict=1							, _a				:     List[str]=False							, _a				:     List[Any]=255							, **_a				:     Any							, )     ->   Optional[Any]:





       '''simple docstring'''






       super().__init__(**_a			)

       _SCREAMING_SNAKE_CASE							   =hidden_size
       _SCREAMING_SNAKE_CASE							   =num_hidden_layers
       _SCREAMING_SNAKE_CASE							   =num_attention_heads
       _SCREAMING_SNAKE_CASE							   =intermediate_size
       _SCREAMING_SNAKE_CASE							   =hidden_act
       _SCREAMING_SNAKE_CASE							   =hidden_dropout_prob
       _SCREAMING_SNAKE_CASE							   =attention_probs_dropout_prob
       _SCREAMING_SNAKE_CASE							   =initializer_range
       _SCREAMING_SNAKE_CASE							   =layer_norm_eps

       _SCREAMING_SNAKE_CASE							   =image_size
       _SCREAMING_SNAKE_CASE							   =patch_size
       _SCREAMING_SNAKE_CASE							   =num_channels
       _SCREAMING_SNAKE_CASE							   =use_mask_token
       _SCREAMING_SNAKE_CASE							   =use_absolute_position_embeddings
       _SCREAMING_SNAKE_CASE							   =use_relative_position_bias
       _SCREAMING_SNAKE_CASE							   =use_shared_relative_position_bias
       _SCREAMING_SNAKE_CASE							   =layer_scale_init_value
       _SCREAMING_SNAKE_CASE							   =drop_path_rate
       _SCREAMING_SNAKE_CASE							   =use_mean_pooling
       # decode head attributes (semantic segmentation)
       _SCREAMING_SNAKE_CASE							   =out_indices
       _SCREAMING_SNAKE_CASE							   =pool_scales
       # auxiliary head attributes (semantic segmentation)
       _SCREAMING_SNAKE_CASE							   =use_auxiliary_head
       _SCREAMING_SNAKE_CASE							   =auxiliary_loss_weight
       _SCREAMING_SNAKE_CASE							   =auxiliary_channels
       _SCREAMING_SNAKE_CASE							   =auxiliary_num_convs
       _SCREAMING_SNAKE_CASE							   =auxiliary_concat_input
       _SCREAMING_SNAKE_CASE							   =semantic_loss_ignore_index







class 							A__   (	A__  ):
  A__					=    version.parse('1.11'  )





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





       '''simple docstring'''






       return OrderedDict(
           [
               ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
           ]			)





  @property
  def 						A  (		self				:     List[Any]			)     ->   float:





       '''simple docstring'''






       return 1e-4
