



import itertools
import json
import os
import unittest

from transformers import AddedToken, LongformerTokenizer, LongformerTokenizerFast
from transformers.models.longformer.tokenization_longformer import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin






@require_tokenizers
class 		lowercase						(			snake_case__			,   unittest.TestCase):






	"""simple docstring"""


	a__				: Any		       =							LongformerTokenizer
	a__				: Tuple		       =							True
	a__				: Optional[int]		       =							LongformerTokenizerFast
	a__				: str		       =							True




	def   _SCREAMING_SNAKE_CASE		(     self     :						Optional[int]					)      ->			Optional[Any]:
							super().setUp()

							# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
							UpperCAmelCase_=       [
							    """l""",
							    """o""",
							    """w""",
							    """e""",
							    """r""",
							    """s""",
							    """t""",
							    """i""",
							    """d""",
							    """n""",
							    """\u0120""",
							    """\u0120l""",
							    """\u0120n""",
							    """\u0120lo""",
							    """\u0120low""",
							    """er""",
							    """\u0120lowest""",
							    """\u0120newer""",
							    """\u0120wider""",
							    """<unk>""",
							]
							UpperCAmelCase_=       dict(zip(__UpperCAmelCase						,  range(len(__UpperCAmelCase					)					)					)					)
							UpperCAmelCase_=       ["""#version: 0.2""", """\u0120 l""", """\u0120l o""", """\u0120lo w""", """e r""", """"""]
							UpperCAmelCase_=       {"""unk_token""": """<unk>"""}

							UpperCAmelCase_=       os.path.join(self.tmpdirname						,  VOCAB_FILES_NAMES["""vocab_file"""]					)
							UpperCAmelCase_=       os.path.join(self.tmpdirname						,  VOCAB_FILES_NAMES["""merges_file"""]					)
							with open(self.vocab_file						,  """w"""						,  encoding="""utf-8"""					) as fp:
													fp.write(json.dumps(__UpperCAmelCase					) + """\n"""					)
							with open(self.merges_file						,  """w"""						,  encoding="""utf-8"""					) as fp:
													fp.write("""\n""".join(__UpperCAmelCase					)					)




	def   _SCREAMING_SNAKE_CASE		(     self     :						Union[str, Any]						,  **__UpperCAmelCase     :						int					)      ->			Union[str, Any]:
							kwargs.update(self.special_tokens_map					)
							return self.tokenizer_class.from_pretrained(self.tmpdirname						,  **__UpperCAmelCase					)




	def   _SCREAMING_SNAKE_CASE		(     self     :						List[Any]						,  **__UpperCAmelCase     :						Union[str, Any]					)      ->			List[str]:
							kwargs.update(self.special_tokens_map					)
							return self.rust_tokenizer_class.from_pretrained(self.tmpdirname						,  **__UpperCAmelCase					)




	def   _SCREAMING_SNAKE_CASE		(     self     :						Dict						,  __UpperCAmelCase     :						Any					)      ->			int:
							UpperCAmelCase_=       """lower newer"""
							UpperCAmelCase_=       """lower newer"""
							return input_text, output_text




	def   _SCREAMING_SNAKE_CASE		(     self     :						Optional[Any]					)      ->			Optional[Any]:
							UpperCAmelCase_=       self.tokenizer_class(self.vocab_file						,  self.merges_file						,  **self.special_tokens_map					)
							UpperCAmelCase_=       """lower newer"""
							UpperCAmelCase_=       ["""l""", """o""", """w""", """er""", """\u0120""", """n""", """e""", """w""", """er"""]
							UpperCAmelCase_=       tokenizer.tokenize(__UpperCAmelCase					)  # , add_prefix_space=True)
							self.assertListEqual(__UpperCAmelCase						,  __UpperCAmelCase					)

							UpperCAmelCase_=       tokens + [tokenizer.unk_token]
							UpperCAmelCase_=       [0, 1, 2, 15, 10, 9, 3, 2, 15, 19]
							self.assertListEqual(tokenizer.convert_tokens_to_ids(__UpperCAmelCase					)						,  __UpperCAmelCase					)




	def   _SCREAMING_SNAKE_CASE		(     self     :						str					)      ->			Tuple:
							UpperCAmelCase_=       self.get_tokenizer()

							self.assertListEqual(tokenizer.encode("""Hello world!"""						,  add_special_tokens=__UpperCAmelCase					)						,  [0, 31_414, 232, 328, 2]					)
							self.assertListEqual(
							    tokenizer.encode("""Hello world! cécé herlolip 418"""						,  add_special_tokens=__UpperCAmelCase					)						,  [0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]						,  )




	@slow
	def   _SCREAMING_SNAKE_CASE		(     self     :						List[Any]					)      ->			Union[str, Any]:
							UpperCAmelCase_=       self.tokenizer_class.from_pretrained("""allenai/longformer-base-4096"""					)

							UpperCAmelCase_=       tokenizer.encode("""sequence builders"""						,  add_special_tokens=__UpperCAmelCase					)
							UpperCAmelCase_=       tokenizer.encode("""multi-sequence build"""						,  add_special_tokens=__UpperCAmelCase					)

							UpperCAmelCase_=       tokenizer.encode(
							    """sequence builders"""						,  add_special_tokens=__UpperCAmelCase						,  add_prefix_space=__UpperCAmelCase					)
							UpperCAmelCase_=       tokenizer.encode(
							    """sequence builders"""						,  """multi-sequence build"""						,  add_special_tokens=__UpperCAmelCase						,  add_prefix_space=__UpperCAmelCase					)

							UpperCAmelCase_=       tokenizer.build_inputs_with_special_tokens(__UpperCAmelCase					)
							UpperCAmelCase_=       tokenizer.build_inputs_with_special_tokens(__UpperCAmelCase						,  __UpperCAmelCase					)

							assert encoded_sentence == encoded_text_from_decode
							assert encoded_pair == encoded_pair_from_decode




	def   _SCREAMING_SNAKE_CASE		(     self     :						Dict					)      ->			str:
							UpperCAmelCase_=       self.get_tokenizer()

							UpperCAmelCase_=       """Encode this sequence."""
							UpperCAmelCase_=       tokenizer.byte_encoder[""" """.encode("""utf-8"""					)[0]]

							# Testing encoder arguments
							UpperCAmelCase_=       tokenizer.encode(__UpperCAmelCase						,  add_special_tokens=__UpperCAmelCase						,  add_prefix_space=__UpperCAmelCase					)
							UpperCAmelCase_=       tokenizer.convert_ids_to_tokens(encoded[0]					)[0]
							self.assertNotEqual(__UpperCAmelCase						,  __UpperCAmelCase					)

							UpperCAmelCase_=       tokenizer.encode(__UpperCAmelCase						,  add_special_tokens=__UpperCAmelCase						,  add_prefix_space=__UpperCAmelCase					)
							UpperCAmelCase_=       tokenizer.convert_ids_to_tokens(encoded[0]					)[0]
							self.assertEqual(__UpperCAmelCase						,  __UpperCAmelCase					)

							tokenizer.add_special_tokens({"""bos_token""": """<s>"""}					)
							UpperCAmelCase_=       tokenizer.encode(__UpperCAmelCase						,  add_special_tokens=__UpperCAmelCase					)
							UpperCAmelCase_=       tokenizer.convert_ids_to_tokens(encoded[1]					)[0]
							self.assertNotEqual(__UpperCAmelCase						,  __UpperCAmelCase					)

							# Testing spaces after special tokens
							UpperCAmelCase_=       """<mask>"""
							tokenizer.add_special_tokens(
							    {"""mask_token""": AddedToken(__UpperCAmelCase						,  lstrip=__UpperCAmelCase						,  rstrip=__UpperCAmelCase					)}					)  # mask token has a left space
							UpperCAmelCase_=       tokenizer.convert_tokens_to_ids(__UpperCAmelCase					)

							UpperCAmelCase_=       """Encode <mask> sequence"""
							UpperCAmelCase_=       """Encode <mask>sequence"""

							UpperCAmelCase_=       tokenizer.encode(__UpperCAmelCase					)
							UpperCAmelCase_=       encoded.index(__UpperCAmelCase					)
							UpperCAmelCase_=       tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]					)[0]
							self.assertEqual(__UpperCAmelCase						,  __UpperCAmelCase					)

							UpperCAmelCase_=       tokenizer.encode(__UpperCAmelCase					)
							UpperCAmelCase_=       encoded.index(__UpperCAmelCase					)
							UpperCAmelCase_=       tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]					)[0]
							self.assertNotEqual(__UpperCAmelCase						,  __UpperCAmelCase					)




	def   _SCREAMING_SNAKE_CASE		(     self     :						Any					)      ->			str:
							pass




	def   _SCREAMING_SNAKE_CASE		(     self     :						Dict					)      ->			List[str]:
							for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
													with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""					):
																			UpperCAmelCase_=       self.rust_tokenizer_class.from_pretrained(__UpperCAmelCase						,  **__UpperCAmelCase					)
																			UpperCAmelCase_=       self.tokenizer_class.from_pretrained(__UpperCAmelCase						,  **__UpperCAmelCase					)
																			UpperCAmelCase_=       """A, <mask> AllenNLP sentence."""
																			UpperCAmelCase_=       tokenizer_r.encode_plus(__UpperCAmelCase						,  add_special_tokens=__UpperCAmelCase						,  return_token_type_ids=__UpperCAmelCase					)
																			UpperCAmelCase_=       tokenizer_p.encode_plus(__UpperCAmelCase						,  add_special_tokens=__UpperCAmelCase						,  return_token_type_ids=__UpperCAmelCase					)

																			# token_type_ids should put 0 everywhere
																			self.assertEqual(sum(tokens_r["""token_type_ids"""]					)						,  sum(tokens_p["""token_type_ids"""]					)					)

																			# attention_mask should put 1 everywhere, so sum over length should be 1
																			self.assertEqual(
																			    sum(tokens_r["""attention_mask"""]					) / len(tokens_r["""attention_mask"""]					)						,  sum(tokens_p["""attention_mask"""]					) / len(tokens_p["""attention_mask"""]					)						,  )

																			UpperCAmelCase_=       tokenizer_r.convert_ids_to_tokens(tokens_r["""input_ids"""]					)
																			UpperCAmelCase_=       tokenizer_p.convert_ids_to_tokens(tokens_p["""input_ids"""]					)

																			# Rust correctly handles the space before the mask while python doesnt
																			self.assertSequenceEqual(tokens_p["""input_ids"""]						,  [0, 250, 6, 50_264, 3_823, 487, 21_992, 3_645, 4, 2]					)
																			self.assertSequenceEqual(tokens_r["""input_ids"""]						,  [0, 250, 6, 50_264, 3_823, 487, 21_992, 3_645, 4, 2]					)

																			self.assertSequenceEqual(
																			    __UpperCAmelCase						,  ["""<s>""", """A""", """,""", """<mask>""", """ĠAllen""", """N""", """LP""", """Ġsentence""", """.""", """</s>"""]					)
																			self.assertSequenceEqual(
																			    __UpperCAmelCase						,  ["""<s>""", """A""", """,""", """<mask>""", """ĠAllen""", """N""", """LP""", """Ġsentence""", """.""", """</s>"""]					)




	def   _SCREAMING_SNAKE_CASE		(     self     :						Tuple					)      ->			Tuple:
							for trim_offsets, add_prefix_space in itertools.product([True, False]						,  repeat=2					):
													UpperCAmelCase_=       self.rust_tokenizer_class.from_pretrained(
													    self.tmpdirname						,  use_fast=__UpperCAmelCase						,  add_prefix_space=__UpperCAmelCase						,  trim_offsets=__UpperCAmelCase					)

													UpperCAmelCase_=       json.loads(tokenizer_r.backend_tokenizer.pre_tokenizer.__getstate__()					)
													UpperCAmelCase_=       json.loads(tokenizer_r.backend_tokenizer.post_processor.__getstate__()					)

													self.assertEqual(pre_tokenizer_state["""add_prefix_space"""]						,  __UpperCAmelCase					)

													self.assertEqual(post_processor_state["""add_prefix_space"""]						,  __UpperCAmelCase					)
													self.assertEqual(post_processor_state["""trim_offsets"""]						,  __UpperCAmelCase					)




	def   _SCREAMING_SNAKE_CASE		(     self     :						List[Any]					)      ->			List[Any]:
							# Test which aims to verify that the offsets are well adapted to the argument `add_prefix_space` and
							# `trim_offsets`
							for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
													with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""					):
																			UpperCAmelCase_=       """hello"""  # `hello` is a token in the vocabulary of `pretrained_name`
																			UpperCAmelCase_=       F"""{text_of_1_token} {text_of_1_token}"""

																			UpperCAmelCase_=       self.rust_tokenizer_class.from_pretrained(
																			    __UpperCAmelCase						,  use_fast=__UpperCAmelCase						,  add_prefix_space=__UpperCAmelCase						,  trim_offsets=__UpperCAmelCase					)
																			UpperCAmelCase_=       tokenizer_r(__UpperCAmelCase						,  return_offsets_mapping=__UpperCAmelCase						,  add_special_tokens=__UpperCAmelCase					)
																			self.assertEqual(encoding.offset_mapping[0]						,  (0, len(__UpperCAmelCase					))					)
																			self.assertEqual(
																			    encoding.offset_mapping[1]						,  (len(__UpperCAmelCase					) + 1, len(__UpperCAmelCase					) + 1 + len(__UpperCAmelCase					))						,  )

																			UpperCAmelCase_=       self.rust_tokenizer_class.from_pretrained(
																			    __UpperCAmelCase						,  use_fast=__UpperCAmelCase						,  add_prefix_space=__UpperCAmelCase						,  trim_offsets=__UpperCAmelCase					)
																			UpperCAmelCase_=       tokenizer_r(__UpperCAmelCase						,  return_offsets_mapping=__UpperCAmelCase						,  add_special_tokens=__UpperCAmelCase					)
																			self.assertEqual(encoding.offset_mapping[0]						,  (0, len(__UpperCAmelCase					))					)
																			self.assertEqual(
																			    encoding.offset_mapping[1]						,  (len(__UpperCAmelCase					) + 1, len(__UpperCAmelCase					) + 1 + len(__UpperCAmelCase					))						,  )

																			UpperCAmelCase_=       self.rust_tokenizer_class.from_pretrained(
																			    __UpperCAmelCase						,  use_fast=__UpperCAmelCase						,  add_prefix_space=__UpperCAmelCase						,  trim_offsets=__UpperCAmelCase					)
																			UpperCAmelCase_=       tokenizer_r(__UpperCAmelCase						,  return_offsets_mapping=__UpperCAmelCase						,  add_special_tokens=__UpperCAmelCase					)
																			self.assertEqual(encoding.offset_mapping[0]						,  (0, len(__UpperCAmelCase					))					)
																			self.assertEqual(
																			    encoding.offset_mapping[1]						,  (len(__UpperCAmelCase					), len(__UpperCAmelCase					) + 1 + len(__UpperCAmelCase					))						,  )

																			UpperCAmelCase_=       self.rust_tokenizer_class.from_pretrained(
																			    __UpperCAmelCase						,  use_fast=__UpperCAmelCase						,  add_prefix_space=__UpperCAmelCase						,  trim_offsets=__UpperCAmelCase					)
																			UpperCAmelCase_=       tokenizer_r(__UpperCAmelCase						,  return_offsets_mapping=__UpperCAmelCase						,  add_special_tokens=__UpperCAmelCase					)
																			self.assertEqual(encoding.offset_mapping[0]						,  (0, len(__UpperCAmelCase					))					)
																			self.assertEqual(
																			    encoding.offset_mapping[1]						,  (len(__UpperCAmelCase					), len(__UpperCAmelCase					) + 1 + len(__UpperCAmelCase					))						,  )

																			UpperCAmelCase_=       F""" {text}"""

																			# tokenizer_r = self.rust_tokenizer_class.from_pretrained(
																			#     pretrained_name, use_fast=True, add_prefix_space=True, trim_offsets=True
																			# )
																			# encoding = tokenizer_r(text, return_offsets_mapping=True, add_special_tokens=False)
																			# self.assertEqual(encoding.offset_mapping[0], (1, 1 + len(text_of_1_token)))
																			# self.assertEqual(
																			#     encoding.offset_mapping[1],
																			#     (1 + len(text_of_1_token) + 1, 1 + len(text_of_1_token) + 1 + len(text_of_1_token)),
																			# )

																			UpperCAmelCase_=       self.rust_tokenizer_class.from_pretrained(
																			    __UpperCAmelCase						,  use_fast=__UpperCAmelCase						,  add_prefix_space=__UpperCAmelCase						,  trim_offsets=__UpperCAmelCase					)
																			UpperCAmelCase_=       tokenizer_r(__UpperCAmelCase						,  return_offsets_mapping=__UpperCAmelCase						,  add_special_tokens=__UpperCAmelCase					)
																			self.assertEqual(encoding.offset_mapping[0]						,  (1, 1 + len(__UpperCAmelCase					))					)
																			self.assertEqual(
																			    encoding.offset_mapping[1]						,  (1 + len(__UpperCAmelCase					) + 1, 1 + len(__UpperCAmelCase					) + 1 + len(__UpperCAmelCase					))						,  )

																			UpperCAmelCase_=       self.rust_tokenizer_class.from_pretrained(
																			    __UpperCAmelCase						,  use_fast=__UpperCAmelCase						,  add_prefix_space=__UpperCAmelCase						,  trim_offsets=__UpperCAmelCase					)
																			UpperCAmelCase_=       tokenizer_r(__UpperCAmelCase						,  return_offsets_mapping=__UpperCAmelCase						,  add_special_tokens=__UpperCAmelCase					)
																			self.assertEqual(encoding.offset_mapping[0]						,  (0, 1 + len(__UpperCAmelCase					))					)
																			self.assertEqual(
																			    encoding.offset_mapping[1]						,  (1 + len(__UpperCAmelCase					), 1 + len(__UpperCAmelCase					) + 1 + len(__UpperCAmelCase					))						,  )

																			UpperCAmelCase_=       self.rust_tokenizer_class.from_pretrained(
																			    __UpperCAmelCase						,  use_fast=__UpperCAmelCase						,  add_prefix_space=__UpperCAmelCase						,  trim_offsets=__UpperCAmelCase					)
																			UpperCAmelCase_=       tokenizer_r(__UpperCAmelCase						,  return_offsets_mapping=__UpperCAmelCase						,  add_special_tokens=__UpperCAmelCase					)
																			self.assertEqual(encoding.offset_mapping[0]						,  (0, 1 + len(__UpperCAmelCase					))					)
																			self.assertEqual(
																			    encoding.offset_mapping[1]						,  (1 + len(__UpperCAmelCase					), 1 + len(__UpperCAmelCase					) + 1 + len(__UpperCAmelCase					))						,  )









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 		lowercase						(			snake_case__):






	"""simple docstring"""


	def __init__(     self     :						Any						,  *__UpperCAmelCase     :						Union[str, Any]						,  __UpperCAmelCase     :						List[str]=None						,  __UpperCAmelCase     :						Optional[int]=None						,  **__UpperCAmelCase     :						Dict					)      ->			Optional[int]:
							super().__init__(*__UpperCAmelCase						,  **__UpperCAmelCase					)
							UpperCAmelCase_=       eval_examples
							UpperCAmelCase_=       post_process_function




	def   _SCREAMING_SNAKE_CASE		(     self     :						Tuple						,  __UpperCAmelCase     :						Optional[Dataset] = None						,  __UpperCAmelCase     :						Optional[Any]=None						,  __UpperCAmelCase     :						Optional[List[str]] = None						,  __UpperCAmelCase     :						str = "eval"						,  **__UpperCAmelCase     :						Any						,  )      ->			Dict[str, float]:
							UpperCAmelCase_=       gen_kwargs.copy()
							UpperCAmelCase_=       (
							    gen_kwargs["""max_length"""] if gen_kwargs.get("""max_length"""					) is not None else self.args.generation_max_length
							)
							UpperCAmelCase_=       (
							    gen_kwargs["""num_beams"""] if gen_kwargs.get("""num_beams"""					) is not None else self.args.generation_num_beams
							)
							UpperCAmelCase_=       gen_kwargs

							UpperCAmelCase_=       self.eval_dataset if eval_dataset is None else eval_dataset
							UpperCAmelCase_=       self.get_eval_dataloader(__UpperCAmelCase					)
							UpperCAmelCase_=       self.eval_examples if eval_examples is None else eval_examples

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

													# Prefix all keys with metric_key_prefix + '_'
													for key in list(metrics.keys()					):
																			if not key.startswith(F"""{metric_key_prefix}_"""					):
																									UpperCAmelCase_=       metrics.pop(__UpperCAmelCase					)

													metrics.update(output.metrics					)
							else:
													UpperCAmelCase_=       output.metrics

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

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




	def   _SCREAMING_SNAKE_CASE		(     self     :						int						,  __UpperCAmelCase     :						Dict						,  __UpperCAmelCase     :						int						,  __UpperCAmelCase     :						Optional[int]=None						,  __UpperCAmelCase     :						str = "test"						,  **__UpperCAmelCase     :						List[str]					)      ->			Tuple:
							UpperCAmelCase_=       gen_kwargs.copy()

							UpperCAmelCase_=       self.get_test_dataloader(__UpperCAmelCase					)

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

							UpperCAmelCase_=       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(
							        __UpperCAmelCase						,  __UpperCAmelCase						,  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_=       self.post_process_function(__UpperCAmelCase						,  __UpperCAmelCase						,  __UpperCAmelCase						,  """predict"""					)
							UpperCAmelCase_=       self.compute_metrics(__UpperCAmelCase					)

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




