


'''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 							__magic_name__	(       lowerCAmelCase ):

     """simple docstring"""






     def __init__(   self			,     *lowerCamelCase			,     lowerCamelCase=None			,     lowerCamelCase=None			,     **lowerCamelCase		):


          '''simple docstring'''





          super().__init__(*lowerCamelCase			,     **lowerCamelCase		)
          __A	:       Tuple      =							eval_examples
          __A	:       List[str]      =							post_process_function


     def lowerCAmelCase__  (   self			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase = "eval"		):


          '''simple docstring'''





          __A	:       Any      =							self.eval_dataset if eval_dataset is None else eval_dataset
          __A	:       Dict      =							self.get_eval_dataloader(lowerCamelCase		)
          __A	:       str      =							self.eval_examples if eval_examples is None else eval_examples

          # Temporarily disable metric computation, we will do it in the loop here.
          __A	:       Any      =							self.compute_metrics
          __A	:       Optional[int]      =							None
          __A	:       Tuple      =							self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
          __A	:       Dict      =							time.time()
          try:
               __A	:       List[str]      =							eval_loop(
                   lowerCamelCase			,     description="Evaluation"			,     prediction_loss_only=True if compute_metrics is None else None			,     ignore_keys=lowerCamelCase			,     metric_key_prefix=lowerCamelCase			,     )
          finally:
               __A	:       List[str]      =							compute_metrics
          __A	:       List[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(
                  lowerCamelCase			,     lowerCamelCase			,     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	:       List[Any]      =							self.post_process_function(lowerCamelCase			,     lowerCamelCase			,     output.predictions		)
               __A	:       List[str]      =							self.compute_metrics(lowerCamelCase		)

               # Prefix all keys with metric_key_prefix + '_'
               for key in list(metrics.keys()		):
                    if not key.startswith(f"{metric_key_prefix}_"		):
                         __A	:       Union[str, Any]      =							metrics.pop(lowerCamelCase		)
               metrics.update(output.metrics		)
          else:
               __A	:       Any      =							output.metrics

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

          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	:       str      =							self.callback_handler.on_evaluate(self.args			,     self.state			,     self.control			,     lowerCamelCase		)
          return metrics


     def lowerCAmelCase__  (   self			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase=None			,     lowerCamelCase = "test"		):


          '''simple docstring'''





          __A	:       Tuple      =							self.get_test_dataloader(lowerCamelCase		)

          # Temporarily disable metric computation, we will do it in the loop here.
          __A	:       Union[str, Any]      =							self.compute_metrics
          __A	:       Union[str, Any]      =							None
          __A	:       Optional[Any]      =							self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
          __A	:       Tuple      =							time.time()
          try:
               __A	:       List[str]      =							eval_loop(
                   lowerCamelCase			,     description="Prediction"			,     prediction_loss_only=True if compute_metrics is None else None			,     ignore_keys=lowerCamelCase			,     metric_key_prefix=lowerCamelCase			,     )
          finally:
               __A	:       int      =							compute_metrics
          __A	:       List[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(
                  lowerCamelCase			,     lowerCamelCase			,     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	:       Dict      =							self.post_process_function(lowerCamelCase			,     lowerCamelCase			,     output.predictions			,     "predict"		)
          __A	:       Tuple      =							self.compute_metrics(lowerCamelCase		)

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





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


_UpperCamelCase 							=  logging.get_logger(__name__)

_UpperCamelCase 							=  {
    """microsoft/beit-base-patch16-224-pt22k""": (
        """https://huggingface.co/microsoft/beit-base-patch16-224-pt22k/resolve/main/config.json"""
    ),
    # See all BEiT models at https://huggingface.co/models?filter=beit
}







class 							__magic_name__	(       lowerCAmelCase ):

     """simple docstring"""






     lowerCamelCase__       						=				'beit'


     def __init__(   self			,     lowerCamelCase=8192			,     lowerCamelCase=768			,     lowerCamelCase=12			,     lowerCamelCase=12			,     lowerCamelCase=3072			,     lowerCamelCase="gelu"			,     lowerCamelCase=0.0			,     lowerCamelCase=0.0			,     lowerCamelCase=0.02			,     lowerCamelCase=1E-12			,     lowerCamelCase=224			,     lowerCamelCase=16			,     lowerCamelCase=3			,     lowerCamelCase=False			,     lowerCamelCase=False			,     lowerCamelCase=False			,     lowerCamelCase=False			,     lowerCamelCase=0.1			,     lowerCamelCase=0.1			,     lowerCamelCase=True			,     lowerCamelCase=[3, 5, 7, 11]			,     lowerCamelCase=[1, 2, 3, 6]			,     lowerCamelCase=True			,     lowerCamelCase=0.4			,     lowerCamelCase=256			,     lowerCamelCase=1			,     lowerCamelCase=False			,     lowerCamelCase=255			,     **lowerCamelCase			,     ):


          '''simple docstring'''





          super().__init__(**lowerCamelCase		)

          __A	:       int      =							vocab_size
          __A	:       Tuple      =							hidden_size
          __A	:       List[str]      =							num_hidden_layers
          __A	:       Optional[int]      =							num_attention_heads
          __A	:       Dict      =							intermediate_size
          __A	:       Optional[int]      =							hidden_act
          __A	:       str      =							hidden_dropout_prob
          __A	:       Dict      =							attention_probs_dropout_prob
          __A	:       int      =							initializer_range
          __A	:       List[str]      =							layer_norm_eps

          __A	:       str      =							image_size
          __A	:       Optional[int]      =							patch_size
          __A	:       List[Any]      =							num_channels
          __A	:       List[str]      =							use_mask_token
          __A	:       Union[str, Any]      =							use_absolute_position_embeddings
          __A	:       Optional[int]      =							use_relative_position_bias
          __A	:       int      =							use_shared_relative_position_bias
          __A	:       int      =							layer_scale_init_value
          __A	:       Union[str, Any]      =							drop_path_rate
          __A	:       Dict      =							use_mean_pooling
          # decode head attributes (semantic segmentation)
          __A	:       List[str]      =							out_indices
          __A	:       str      =							pool_scales
          # auxiliary head attributes (semantic segmentation)
          __A	:       List[str]      =							use_auxiliary_head
          __A	:       Tuple      =							auxiliary_loss_weight
          __A	:       Dict      =							auxiliary_channels
          __A	:       Tuple      =							auxiliary_num_convs
          __A	:       List[str]      =							auxiliary_concat_input
          __A	:       int      =							semantic_loss_ignore_index







class 							__magic_name__	(       lowerCAmelCase ):

     """simple docstring"""






     lowerCamelCase__       						=				version.parse('1.11' )


     @property
     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





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


     @property
     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          return 1E-4

