
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        _SCREAMING_SNAKE_CASE	(   __UpperCamelCase			):
      def __init__(      self		,						*lowerCamelCase		,						lowerCamelCase=None		,						lowerCamelCase=None		,						**lowerCamelCase			):
          super().__init__(*lowerCamelCase		,						**lowerCamelCase			)
          snake_case__    =					eval_examples
          snake_case__    =					post_process_function
      def A_      (      self		,						lowerCamelCase = None		,						lowerCamelCase=None		,						lowerCamelCase = None		,						lowerCamelCase = "eval"		,						**lowerCamelCase		,						):
          snake_case__    =					gen_kwargs.copy()
          snake_case__    =					(
              gen_kwargs["max_length"] if gen_kwargs.get("max_length"			) is not None else self.args.generation_max_length
          )
          snake_case__    =					(
              gen_kwargs["num_beams"] if gen_kwargs.get("num_beams"			) is not None else self.args.generation_num_beams
          )
          snake_case__    =					gen_kwargs

          snake_case__    =					self.eval_dataset if eval_dataset is None else eval_dataset
          snake_case__    =					self.get_eval_dataloader(lowerCamelCase			)
          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.
          snake_case__    =					self.compute_metrics
          snake_case__    =					None
          snake_case__    =					time.time()
          snake_case__    =					self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
          try:
              snake_case__    =					eval_loop(
                  lowerCamelCase		,						description="Evaluation"		,						prediction_loss_only=True if compute_metrics is None else None		,						ignore_keys=lowerCamelCase		,						metric_key_prefix=lowerCamelCase		,						)
          finally:
              snake_case__    =					compute_metrics
          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(
                  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
              snake_case__    =					self.post_process_function(lowerCamelCase		,						lowerCamelCase		,						lowerCamelCase			)
              snake_case__    =					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}_"""			):
                      snake_case__    =					metrics.pop(lowerCamelCase			)

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

          snake_case__    =					self.callback_handler.on_evaluate(self.args		,						self.state		,						self.control		,						lowerCamelCase			)
          return metrics



      def A_      (      self		,						lowerCamelCase		,						lowerCamelCase		,						lowerCamelCase=None		,						lowerCamelCase = "test"		,						**lowerCamelCase			):
          snake_case__    =					gen_kwargs.copy()

          snake_case__    =					self.get_test_dataloader(lowerCamelCase			)

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

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

          snake_case__    =					self.post_process_function(lowerCamelCase		,						lowerCamelCase		,						lowerCamelCase		,						"predict"			)
          snake_case__    =					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}_"""			):
                  snake_case__    =					metrics.pop(lowerCamelCase			)
          metrics.update(output.metrics			)
          return PredictionOutput(predictions=predictions.predictions		,						label_ids=predictions.label_ids		,						metrics=lowerCamelCase			)





import os
from datetime import datetime as dt

from github import Github


__magic_name__  							=	[
    '''good first issue''',
    '''feature request''',
    '''wip''',
]





def 						SCREAMING_SNAKE_CASE__     (   ):
    snake_case__    =					Github(os.environ["GITHUB_TOKEN"]				)
    snake_case__    =					g.get_repo("huggingface/accelerate"				)
    snake_case__    =					repo.get_issues(state="open"				)

    for issue in open_issues:
        snake_case__    =					sorted([comment for comment in issue.get_comments()]     ,		key=lambda __lowerCAmelCase				: i.created_at     ,		reverse=__lowerCAmelCase				)
        snake_case__    =					comments[0] if len(__lowerCAmelCase				) > 0 else None
        snake_case__    =					dt.utcnow()
        snake_case__    =					(current_time - issue.updated_at).days
        snake_case__    =					(current_time - issue.created_at).days
        if (
            last_comment is not None
            and last_comment.user.login == "github-actions[bot]"
            and days_since_updated > 7
            and days_since_creation >= 30
            and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels()				)
        ):
            # Close issue since it has been 7 days of inactivity since bot mention.
            issue.edit(state="closed"				)
        elif (
            days_since_updated > 23
            and days_since_creation >= 30
            and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels()				)
        ):
            # Add stale comment
            issue.create_comment(
                "This issue has been automatically marked as stale because it has not had "
                "recent activity. If you think this still needs to be addressed "
                "please comment on this thread.\n\nPlease note that issues that do not follow the "
                "[contributing guidelines](https://github.com/huggingface/accelerate/blob/main/CONTRIBUTING.md) "
                "are likely to be ignored."				)


if __name__ == "__main__":
     main()



