


'''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 						_snake_case   (       a_		):




							def __init__( self							,							*_lowerCamelCase							,							_lowerCamelCase=None							,							_lowerCamelCase=None							,							**_lowerCamelCase):
										super().__init__(*lowercase_							,							**lowercase_)
										UpperCAmelCase__					:   Optional[int]       				=       eval_examples
										UpperCAmelCase__					:   str       				=       post_process_function




							def 			snake_case__  ( self							,							_lowerCamelCase = None							,							_lowerCamelCase=None							,							_lowerCamelCase = None							,							_lowerCamelCase = "eval"							,							**_lowerCamelCase							,							):
										UpperCAmelCase__					:   Optional[Any]       				=       gen_kwargs.copy()
										UpperCAmelCase__					:   Any       				=       (
										    gen_kwargs["""max_length"""] if gen_kwargs.get("""max_length""") is not None else self.args.generation_max_length
										)
										UpperCAmelCase__					:   List[Any]       				=       (
										    gen_kwargs["""num_beams"""] if gen_kwargs.get("""num_beams""") is not None else self.args.generation_num_beams
										)
										UpperCAmelCase__					:   List[Any]       				=       gen_kwargs

										UpperCAmelCase__					:   Tuple       				=       self.eval_dataset if eval_dataset is None else eval_dataset
										UpperCAmelCase__					:   Any       				=       self.get_eval_dataloader(lowercase_)
										UpperCAmelCase__					:   List[str]       				=       self.eval_examples if eval_examples is None else eval_examples

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

													# Prefix all keys with metric_key_prefix + '_'
													for key in list(metrics.keys()):
																if not key.startswith(f'''{metric_key_prefix}_'''):
																			UpperCAmelCase__					:   List[str]       				=       metrics.pop(lowercase_)

													metrics.update(output.metrics)
										else:
													UpperCAmelCase__					:   int       				=       output.metrics

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

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

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




							def 			snake_case__  ( self							,							_lowerCamelCase							,							_lowerCamelCase							,							_lowerCamelCase=None							,							_lowerCamelCase = "test"							,							**_lowerCamelCase):
										UpperCAmelCase__					:   Tuple       				=       gen_kwargs.copy()

										UpperCAmelCase__					:   Tuple       				=       self.get_test_dataloader(lowercase_)

										# Temporarily disable metric computation, we will do it in the loop here.
										UpperCAmelCase__					:   Optional[Any]       				=       self.compute_metrics
										UpperCAmelCase__					:   List[Any]       				=       None
										UpperCAmelCase__					:   Tuple       				=       time.time()
										UpperCAmelCase__					:   Dict       				=       self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
										try:
													UpperCAmelCase__					:   Dict       				=       eval_loop(
													    lowercase_							,							description="""Prediction"""							,							prediction_loss_only=True if compute_metrics is None else None							,							ignore_keys=lowercase_							,							metric_key_prefix=lowercase_							,							)
										finally:
													UpperCAmelCase__					:   List[str]       				=       compute_metrics

										UpperCAmelCase__					:   int       				=       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(
										        lowercase_							,							lowercase_							,							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

										UpperCAmelCase__					:   str       				=       self.post_process_function(lowercase_							,							lowercase_							,							lowercase_							,							"""predict""")
										UpperCAmelCase__					:   Optional[int]       				=       self.compute_metrics(lowercase_)

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



'''simple docstring'''



import os
from datetime import datetime as dt

from github import Github


__A		=[
    'good first issue',
    'good second issue',
    'good difficult issue',
    'enhancement',
    'new pipeline/model',
    'new scheduler',
    'wip',
]







def       _UpperCamelCase (						):
			UpperCAmelCase__					:   Union[str, Any]       				=       Github(os.environ["""GITHUB_TOKEN"""]   )
			UpperCAmelCase__					:   Any       				=       g.get_repo("""huggingface/diffusers"""   )
			UpperCAmelCase__					:   Optional[int]       				=       repo.get_issues(state="""open"""   )

			for issue in open_issues:
						UpperCAmelCase__					:   Any       				=       sorted(issue.get_comments()	, key=lambda UpperCamelCase__   : i.created_at	, reverse=UpperCamelCase__   )
						UpperCAmelCase__					:   List[Any]       				=       comments[0] if len(UpperCamelCase__   ) > 0 else None
						if (
						    last_comment is not None
						    and last_comment.user.login == "github-actions[bot]"
						    and (dt.utcnow() - issue.updated_at).days > 7
						    and (dt.utcnow() - issue.created_at).days >= 3_0
						    and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels()   )
						):
									# Closes the issue after 7 days of inactivity since the Stalebot notification.
									issue.edit(state="""closed"""   )
						elif (
						    "stale" in issue.get_labels()
						    and last_comment is not None
						    and last_comment.user.login != "github-actions[bot]"
						):
									# Opens the issue if someone other than Stalebot commented.
									issue.edit(state="""open"""   )
									issue.remove_from_labels("""stale"""   )
						elif (
						    (dt.utcnow() - issue.updated_at).days > 2_3
						    and (dt.utcnow() - issue.created_at).days >= 3_0
						    and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels()   )
						):
									# Post a Stalebot notification after 23 days of inactivity.
									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/diffusers/blob/main/CONTRIBUTING.md) """
									    """are likely to be ignored."""   )
									issue.add_to_labels("""stale"""   )


if __name__ == "__main__":
		main()