

import shutil
import tempfile
import unittest

from transformers import (
    SPIECE_UNDERLINE,
    AddedToken,
    BatchEncoding,
    NllbTokenizer,
    NllbTokenizerFast,
    is_torch_available,
)
from transformers.testing_utils import (
    get_tests_dir,
    nested_simplify,
    require_sentencepiece,
    require_tokenizers,
    require_torch,
)

from ...test_tokenization_common import TokenizerTesterMixin


A_       : str         =			get_tests_dir('fixtures/test_sentencepiece.model')


if is_torch_available():
	from transformers.models.mam_aaa.modeling_mam_aaa import shift_tokens_right

A_       : str         =			25_6047
A_       : Optional[Any]         =			25_6145



@require_sentencepiece
@require_tokenizers
class     _a						(__magic_name__		,   unittest.TestCase				):


					'''simple docstring'''






					UpperCAmelCase__:   Optional[int]  							=       NllbTokenizer
					UpperCAmelCase__:   str  							=       NllbTokenizerFast
					UpperCAmelCase__:   List[str]  							=       True
					UpperCAmelCase__:   str  							=       True
					UpperCAmelCase__:   Union[str, Any]  							=       {}






					def   __A			( self			):
						super().setUp()

						# We have a SentencePiece fixture for testing
						A__							:    Dict        =		NllbTokenizer(A__    ,       keep_accents=A__			)
						tokenizer.save_pretrained(self.tmpdirname			)






					def   __A			( self			):
						A__							:    List[Any]        =		NllbTokenizer(A__    ,       keep_accents=A__			)

						A__							:    Optional[Any]        =		tokenizer.tokenize("""This is a test"""			)
						self.assertListEqual(A__    ,       ["""▁This""", """▁is""", """▁a""", """▁t""", """est"""]			)

						self.assertListEqual(
						    tokenizer.convert_tokens_to_ids(A__			)    ,       [value + tokenizer.fairseq_offset for value in [285, 46, 10, 170, 382]]    ,       )

						A__							:    Any        =		tokenizer.tokenize("""I was born in 92000, and this is falsé."""			)
						self.assertListEqual(
						    A__    ,       [
						        SPIECE_UNDERLINE + """I""",
						        SPIECE_UNDERLINE + """was""",
						        SPIECE_UNDERLINE + """b""",
						        """or""",
						        """n""",
						        SPIECE_UNDERLINE + """in""",
						        SPIECE_UNDERLINE + """""",
						        """9""",
						        """2""",
						        """0""",
						        """0""",
						        """0""",
						        """,""",
						        SPIECE_UNDERLINE + """and""",
						        SPIECE_UNDERLINE + """this""",
						        SPIECE_UNDERLINE + """is""",
						        SPIECE_UNDERLINE + """f""",
						        """al""",
						        """s""",
						        """é""",
						        """.""",
						    ]    ,       )
						A__							:    Optional[Any]        =		tokenizer.convert_tokens_to_ids(A__			)
						self.assertListEqual(
						    A__    ,       [
						        value + tokenizer.fairseq_offset
						        for value in [8, 21, 84, 55, 24, 19, 7, 2, 602, 347, 347, 347, 3, 12, 66, 46, 72, 80, 6, 2, 4]
						    ]    ,       )

						A__							:    Optional[int]        =		tokenizer.convert_ids_to_tokens(A__			)
						self.assertListEqual(
						    A__    ,       [
						        SPIECE_UNDERLINE + """I""",
						        SPIECE_UNDERLINE + """was""",
						        SPIECE_UNDERLINE + """b""",
						        """or""",
						        """n""",
						        SPIECE_UNDERLINE + """in""",
						        SPIECE_UNDERLINE + """""",
						        """<unk>""",
						        """2""",
						        """0""",
						        """0""",
						        """0""",
						        """,""",
						        SPIECE_UNDERLINE + """and""",
						        SPIECE_UNDERLINE + """this""",
						        SPIECE_UNDERLINE + """is""",
						        SPIECE_UNDERLINE + """f""",
						        """al""",
						        """s""",
						        """<unk>""",
						        """.""",
						    ]    ,       )






					def   __A			( self			):
						A__							:    Optional[Any]        =		(self.rust_tokenizer_class, """hf-internal-testing/tiny-random-nllb""", {})
						for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
							with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""			):
								A__							:    List[Any]        =		self.rust_tokenizer_class.from_pretrained(A__    ,       **A__			)
								A__							:    Optional[int]        =		self.tokenizer_class.from_pretrained(A__    ,       **A__			)

								A__							:    str        =		tempfile.mkdtemp()

								A__							:    Any        =		tokenizer_r.save_pretrained(A__			)
								A__							:    List[str]        =		tokenizer_p.save_pretrained(A__			)

								# Checks it save with the same files + the tokenizer.json file for the fast one
								self.assertTrue(any("""tokenizer.json""" in f for f in tokenizer_r_files			)			)
								A__							:    Optional[int]        =		tuple(f for f in tokenizer_r_files if """tokenizer.json""" not in f			)
								self.assertSequenceEqual(A__    ,       A__			)

								# Checks everything loads correctly in the same way
								A__							:    Tuple        =		tokenizer_r.from_pretrained(A__			)
								A__							:    List[Any]        =		tokenizer_p.from_pretrained(A__			)

								# Check special tokens are set accordingly on Rust and Python
								for key in tokenizer_pp.special_tokens_map:
									self.assertTrue(hasattr(A__    ,       A__			)			)

								shutil.rmtree(A__			)

								# Save tokenizer rust, legacy_format=True
								A__							:    Optional[Any]        =		tempfile.mkdtemp()

								A__							:    Dict        =		tokenizer_r.save_pretrained(A__    ,       legacy_format=A__			)
								A__							:    Any        =		tokenizer_p.save_pretrained(A__			)

								# Checks it save with the same files
								self.assertSequenceEqual(A__    ,       A__			)

								# Checks everything loads correctly in the same way
								A__							:    int        =		tokenizer_r.from_pretrained(A__			)
								A__							:    Any        =		tokenizer_p.from_pretrained(A__			)

								# Check special tokens are set accordingly on Rust and Python
								for key in tokenizer_pp.special_tokens_map:
									self.assertTrue(hasattr(A__    ,       A__			)			)

								shutil.rmtree(A__			)

								# Save tokenizer rust, legacy_format=False
								A__							:    Tuple        =		tempfile.mkdtemp()

								A__							:    str        =		tokenizer_r.save_pretrained(A__    ,       legacy_format=A__			)
								A__							:    int        =		tokenizer_p.save_pretrained(A__			)

								# Checks it saved the tokenizer.json file
								self.assertTrue(any("""tokenizer.json""" in f for f in tokenizer_r_files			)			)

								# Checks everything loads correctly in the same way
								A__							:    Optional[int]        =		tokenizer_r.from_pretrained(A__			)
								A__							:    Union[str, Any]        =		tokenizer_p.from_pretrained(A__			)

								# Check special tokens are set accordingly on Rust and Python
								for key in tokenizer_pp.special_tokens_map:
									self.assertTrue(hasattr(A__    ,       A__			)			)

								shutil.rmtree(A__			)






					@require_torch
					def   __A			( self			):
						if not self.test_seqaseq:
							return

						A__							:    List[str]        =		self.get_tokenizers()
						for tokenizer in tokenizers:
							with self.subTest(F"""{tokenizer.__class__.__name__}"""			):
								# Longer text that will definitely require truncation.
								A__							:    str        =		[
								    """ UN Chief Says There Is No Military Solution in Syria""",
								    """ Secretary-General Ban Ki-moon says his response to Russia's stepped up military support for"""
								    """ Syria is that 'there is no military solution' to the nearly five-year conflict and more weapons"""
								    """ will only worsen the violence and misery for millions of people.""",
								]
								A__							:    str        =		[
								    """Şeful ONU declară că nu există o soluţie militară în Siria""",
								    """Secretarul General Ban Ki-moon declară că răspunsul său la intensificarea sprijinului militar al"""
								    """ Rusiei pentru Siria este că \"nu există o soluţie militară\" la conflictul de aproape cinci ani şi"""
								    """ că noi arme nu vor face decât să înrăutăţească violenţele şi mizeria pentru milioane de oameni.""",
								]
								try:
									A__							:    Optional[Any]        =		tokenizer.prepare_seqaseq_batch(
									    src_texts=A__    ,       tgt_texts=A__    ,       max_length=3    ,       max_target_length=10    ,       return_tensors="""pt"""    ,       src_lang="""eng_Latn"""    ,       tgt_lang="""ron_Latn"""    ,       )
								except NotImplementedError:
									return
								self.assertEqual(batch.input_ids.shape[1]    ,       3			)
								self.assertEqual(batch.labels.shape[1]    ,       10			)
								# max_target_length will default to max_length if not specified
								A__							:    List[Any]        =		tokenizer.prepare_seqaseq_batch(
								    A__    ,       tgt_texts=A__    ,       max_length=3    ,       return_tensors="""pt"""			)
								self.assertEqual(batch.input_ids.shape[1]    ,       3			)
								self.assertEqual(batch.labels.shape[1]    ,       3			)

								A__							:    Dict        =		tokenizer.prepare_seqaseq_batch(
								    src_texts=A__    ,       max_length=3    ,       max_target_length=10    ,       return_tensors="""pt"""			)
								self.assertEqual(batch_encoder_only.input_ids.shape[1]    ,       3			)
								self.assertEqual(batch_encoder_only.attention_mask.shape[1]    ,       3			)
								self.assertNotIn("""decoder_input_ids"""    ,       A__			)






					@unittest.skip("""Unfortunately way too slow to build a BPE with SentencePiece."""			)
					def   __A			( self			):
						pass






					def   __A			( self			):
						for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
							with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""			):
								A__							:    Union[str, Any]        =		[AddedToken("""<special>"""    ,       lstrip=A__			)]

								A__							:    Optional[Any]        =		self.rust_tokenizer_class.from_pretrained(
								    A__    ,       additional_special_tokens=A__    ,       **A__			)
								A__							:    str        =		tokenizer_r.encode("""Hey this is a <special> token"""			)

								A__							:    Optional[Any]        =		tokenizer_r.encode("""<special>"""    ,       add_special_tokens=A__			)[0]

								self.assertTrue(special_token_id in r_output			)

								if self.test_slow_tokenizer:
									A__							:    Union[str, Any]        =		self.rust_tokenizer_class.from_pretrained(
									    A__    ,       additional_special_tokens=A__    ,       **A__    ,       )
									A__							:    int        =		self.tokenizer_class.from_pretrained(
									    A__    ,       additional_special_tokens=A__    ,       **A__			)

									A__							:    int        =		tokenizer_p.encode("""Hey this is a <special> token"""			)

									A__							:    int        =		tokenizer_cr.encode("""Hey this is a <special> token"""			)

									self.assertEqual(A__    ,       A__			)
									self.assertEqual(A__    ,       A__			)
									self.assertTrue(special_token_id in p_output			)
									self.assertTrue(special_token_id in cr_output			)



@require_torch
@require_sentencepiece
@require_tokenizers
class     _a						(unittest.TestCase				):


					'''simple docstring'''






					UpperCAmelCase__:   Optional[Any]  							=       '''facebook/nllb-200-distilled-600M'''
					UpperCAmelCase__:   List[Any]  							=       [
					    ''' UN Chief Says There Is No Military Solution in Syria''',
					    ''' Secretary-General Ban Ki-moon says his response to Russia\'s stepped up military support for Syria is that "there is no military solution" to the nearly five-year conflict and more weapons will only worsen the violence and misery for millions of people.''',
					]
					UpperCAmelCase__:   Optional[Any]  							=       [
					    '''Şeful ONU declară că nu există o soluţie militară în Siria''',
					    '''Secretarul General Ban Ki-moon declară că răspunsul său la intensificarea sprijinului militar al Rusiei'''
					    ''' pentru Siria este că "nu există o soluţie militară" la conflictul de aproape cinci ani şi că noi arme nu vor'''
					    ''' face decât să înrăutăţească violenţele şi mizeria pentru milioane de oameni.''',
					]
					UpperCAmelCase__:   Optional[int]  							=       [
					    25_60_47,
					    1_62_97,
					    13_44_08,
					    81_65,
					    24_80_66,
					    1_47_34,
					    9_50,
					    11_35,
					    10_57_21,
					    35_73,
					    83,
					    2_73_52,
					    1_08,
					    4_94_86,
					    2,
					]






					@classmethod
					def   __A			( cls			):
						A__							:    NllbTokenizer        =		NllbTokenizer.from_pretrained(
						    cls.checkpoint_name    ,       src_lang="""eng_Latn"""    ,       tgt_lang="""ron_Latn"""			)
						A__							:    str        =		1
						return cls






					def   __A			( self			):
						self.assertEqual(self.tokenizer.fairseq_tokens_to_ids["""ace_Arab"""]    ,       25_6001			)
						self.assertEqual(self.tokenizer.fairseq_tokens_to_ids["""ace_Latn"""]    ,       25_6002			)
						self.assertEqual(self.tokenizer.fairseq_tokens_to_ids["""fra_Latn"""]    ,       25_6057			)






					def   __A			( self			):
						A__							:    str        =		self.tokenizer.batch_encode_plus(self.src_text			).input_ids[0]
						self.assertListEqual(self.expected_src_tokens    ,       A__			)






					def   __A			( self			):
						self.assertIn(A__    ,       self.tokenizer.all_special_ids			)
						# fmt: off
						A__							:    List[str]        =		[RO_CODE, 4254, 9_8068, 11_2923, 3_9072, 3909, 713, 10_2767, 26, 1_7314, 3_5642, 1_4683, 3_3118, 2022, 6_6987, 2, 25_6047]
						# fmt: on

						A__							:    Tuple        =		self.tokenizer.decode(A__    ,       skip_special_tokens=A__			)
						A__							:    List[str]        =		self.tokenizer.decode(generated_ids[1:]    ,       skip_special_tokens=A__			)
						self.assertEqual(A__    ,       A__			)
						self.assertNotIn(self.tokenizer.eos_token    ,       A__			)






					def   __A			( self			):
						A__							:    Any        =		["""this is gunna be a long sentence """ * 20]
						assert isinstance(src_text[0]    ,       A__			)
						A__							:    int        =		10
						A__							:    Tuple        =		self.tokenizer(A__    ,       max_length=A__    ,       truncation=A__			).input_ids[0]
						self.assertEqual(ids[-1]    ,       2			)
						self.assertEqual(ids[0]    ,       A__			)
						self.assertEqual(len(A__			)    ,       A__			)






					def   __A			( self			):
						self.assertListEqual(self.tokenizer.convert_tokens_to_ids(["""<mask>""", """ar_AR"""]			)    ,       [25_6203, 3]			)






					def   __A			( self			):
						A__							:    Optional[Any]        =		tempfile.mkdtemp()
						A__							:    Dict        =		self.tokenizer.fairseq_tokens_to_ids
						self.tokenizer.save_pretrained(A__			)
						A__							:    List[str]        =		NllbTokenizer.from_pretrained(A__			)
						self.assertDictEqual(new_tok.fairseq_tokens_to_ids    ,       A__			)






					@require_torch
					def   __A			( self			):
						A__							:    Any        =		self.tokenizer(
						    self.src_text    ,       text_target=self.tgt_text    ,       padding=A__    ,       truncation=A__    ,       max_length=len(self.expected_src_tokens			)    ,       return_tensors="""pt"""    ,       )
						A__							:    List[Any]        =		shift_tokens_right(
						    batch["""labels"""]    ,       self.tokenizer.pad_token_id    ,       self.tokenizer.lang_code_to_id["""ron_Latn"""]			)

						self.assertIsInstance(A__    ,       A__			)

						self.assertEqual((2, 15)    ,       batch.input_ids.shape			)
						self.assertEqual((2, 15)    ,       batch.attention_mask.shape			)
						A__							:    List[str]        =		batch.input_ids.tolist()[0]
						self.assertListEqual(self.expected_src_tokens    ,       A__			)
						self.assertEqual(A__    ,       batch.decoder_input_ids[0, 0]			)  # EOS
						# Test that special tokens are reset
						self.assertEqual(self.tokenizer.prefix_tokens    ,       [EN_CODE]			)
						self.assertEqual(self.tokenizer.suffix_tokens    ,       [self.tokenizer.eos_token_id]			)






					def   __A			( self			):
						A__							:    int        =		self.tokenizer(self.src_text    ,       padding=A__    ,       truncation=A__    ,       max_length=3    ,       return_tensors="""pt"""			)
						A__							:    Dict        =		self.tokenizer(
						    text_target=self.tgt_text    ,       padding=A__    ,       truncation=A__    ,       max_length=10    ,       return_tensors="""pt"""			)
						A__							:    Union[str, Any]        =		targets["""input_ids"""]
						A__							:    Union[str, Any]        =		shift_tokens_right(
						    A__    ,       self.tokenizer.pad_token_id    ,       decoder_start_token_id=self.tokenizer.lang_code_to_id[self.tokenizer.tgt_lang]    ,       )

						self.assertEqual(batch.input_ids.shape[1]    ,       3			)
						self.assertEqual(batch.decoder_input_ids.shape[1]    ,       10			)






					@require_torch
					def   __A			( self			):
						A__							:    Any        =		self.tokenizer._build_translation_inputs(
						    """A test"""    ,       return_tensors="""pt"""    ,       src_lang="""eng_Latn"""    ,       tgt_lang="""fra_Latn"""			)

						self.assertEqual(
						    nested_simplify(A__			)    ,       {
						        # A, test, EOS, en_XX
						        """input_ids""": [[25_6047, 70, 7356, 2]],
						        """attention_mask""": [[1, 1, 1, 1]],
						        # ar_AR
						        """forced_bos_token_id""": 25_6057,
						    }    ,       )






					@require_torch
					def   __A			( self			):
						A__							:    str        =		True
						A__							:    str        =		self.tokenizer(
						    """UN Chief says there is no military solution in Syria"""    ,       src_lang="""eng_Latn"""    ,       tgt_lang="""fra_Latn"""			)
						self.assertEqual(
						    inputs.input_ids    ,       [1_6297, 13_4408, 2_5653, 6370, 248, 254, 10_3929, 9_4995, 108, 4_9486, 2, 25_6047]			)

						A__							:    List[str]        =		False
						A__							:    Union[str, Any]        =		self.tokenizer(
						    """UN Chief says there is no military solution in Syria"""    ,       src_lang="""eng_Latn"""    ,       tgt_lang="""fra_Latn"""			)
						self.assertEqual(
						    inputs.input_ids    ,       [25_6047, 1_6297, 13_4408, 2_5653, 6370, 248, 254, 10_3929, 9_4995, 108, 4_9486, 2]			)






import re
import time
from typing import Optional

import IPython.display as disp

from ..trainer_callback import TrainerCallback
from ..trainer_utils import IntervalStrategy, has_length

def 						UpperCamelCase					(lowercase_: str					)     ->      Dict:
	A__							:    int        =		int(lowercase_					)
	A__   ,   A__   ,   A__							:    Tuple        =		t // 3600, (t // 60) % 60, t % 60
	return f"""{h}:{m:02d}:{s:02d}""" if h != 0 else f"""{m:02d}:{s:02d}"""

def 						UpperCamelCase					(lowercase_: str    ,      lowercase_: Optional[Any]    ,      lowercase_: Union[str, Any]    ,      lowercase_: Tuple    ,      lowercase_: Any=300					)     ->      Optional[int]:
	# docstyle-ignore
	return f"""
    <div>
      {prefix}
      <progress value='{value}' max='{total}' style='width:{width}px; height:20px; vertical-align: middle;'></progress>
      {label}
    </div>
    """

def 						UpperCamelCase					(lowercase_: Tuple					)     ->      Optional[int]:
	A__							:    Tuple        =		"""<table border=\"1\" class=\"dataframe\">\n"""
	html_code += """  <thead>\n <tr style="text-align: left;">\n"""
	for i in items[0]:
		html_code += f"""      <th>{i}</th>\n"""
	html_code += "    </tr>\n  </thead>\n  <tbody>\n"
	for line in items[1:]:
		html_code += "    <tr>\n"
		for elt in line:
			A__							:    str        =		f"""{elt:.6f}""" if isinstance(lowercase_    ,      lowercase_					) else str(lowercase_					)
			html_code += f"""      <td>{elt}</td>\n"""
		html_code += "    </tr>\n"
	html_code += "  </tbody>\n</table><p>"
	return html_code



class     _a						:


					'''simple docstring'''






					UpperCAmelCase__:   str  							=       5
					UpperCAmelCase__:   int  							=       0.2






					def __init__( self    ,       A__    ,       A__ = None    ,       A__ = True    ,       A__ = None    ,       A__ = 300    ,       ):
						A__							:    Optional[int]        =		total
						A__							:    Tuple        =		"""""" if prefix is None else prefix
						A__							:    str        =		leave
						A__							:    str        =		parent
						A__							:    int        =		width
						A__							:    Dict        =		None
						A__							:    List[str]        =		None
						A__							:    Optional[int]        =		None






					def   __A			( self    ,       A__    ,       A__ = False    ,       A__ = None			):
						A__							:    Tuple        =		value
						if comment is not None:
							A__							:    Any        =		comment
						if self.last_value is None:
							A__							:    int        =		time.time()
							A__							:    Dict        =		value
							A__							:    int        =		None
							A__							:    int        =		self.warmup
							A__							:    str        =		1
							self.update_bar(A__			)
						elif value <= self.last_value and not force_update:
							return
						elif force_update or self.first_calls > 0 or value >= min(self.last_value + self.wait_for    ,       self.total			):
							if self.first_calls > 0:
								self.first_calls -= 1
							A__							:    Any        =		time.time()
							A__							:    str        =		current_time - self.start_time
							# We could have value = self.start_value if the update is called twixe with the same start value.
							if value > self.start_value:
								A__							:    Dict        =		self.elapsed_time / (value - self.start_value)
							else:
								A__							:    List[str]        =		None
							if value >= self.total:
								A__							:    Optional[Any]        =		self.total
								A__							:    List[Any]        =		None
								if not self.leave:
									self.close()
							elif self.average_time_per_item is not None:
								A__							:    List[Any]        =		self.average_time_per_item * (self.total - value)
							self.update_bar(A__			)
							A__							:    Any        =		value
							A__							:    List[str]        =		current_time
							if self.average_time_per_item is None:
								A__							:    str        =		1
							else:
								A__							:    Optional[Any]        =		max(int(self.update_every / self.average_time_per_item			)    ,       1			)






					def   __A			( self    ,       A__    ,       A__=None			):
						A__							:    Tuple        =		""" """ * (len(str(self.total			)			) - len(str(A__			)			)) + str(A__			)
						if self.elapsed_time is None:
							A__							:    Union[str, Any]        =		F"""[{spaced_value}/{self.total} : < :"""
						elif self.predicted_remaining is None:
							A__							:    Tuple        =		F"""[{spaced_value}/{self.total} {format_time(self.elapsed_time			)}"""
						else:
							A__							:    Optional[int]        =		(
							    F"""[{spaced_value}/{self.total} {format_time(self.elapsed_time			)} <"""
							    F""" {format_time(self.predicted_remaining			)}"""
							)
							self.label += F""", {1/self.average_time_per_item:.2f} it/s"""
						self.label += "]" if self.comment is None or len(self.comment			) == 0 else F""", {self.comment}]"""
						self.display()






					def   __A			( self			):
						A__							:    str        =		html_progress_bar(self.value    ,       self.total    ,       self.prefix    ,       self.label    ,       self.width			)
						if self.parent is not None:
							# If this is a child bar, the parent will take care of the display.
							self.parent.display()
							return
						if self.output is None:
							A__							:    str        =		disp.display(disp.HTML(self.html_code			)    ,       display_id=A__			)
						else:
							self.output.update(disp.HTML(self.html_code			)			)






					def   __A			( self			):
						if self.parent is None and self.output is not None:
							self.output.update(disp.HTML(""""""			)			)



class     _a						(__magic_name__				):


					'''simple docstring'''






					def __init__( self    ,       A__    ,       A__=None			):
						super().__init__(A__			)
						A__							:    Optional[Any]        =		None if column_names is None else [column_names]
						A__							:    Optional[Any]        =		None






					def   __A			( self			):
						A__							:    List[str]        =		html_progress_bar(self.value    ,       self.total    ,       self.prefix    ,       self.label    ,       self.width			)
						if self.inner_table is not None:
							self.html_code += text_to_html_table(self.inner_table			)
						if self.child_bar is not None:
							self.html_code += self.child_bar.html_code
						if self.output is None:
							A__							:    Optional[int]        =		disp.display(disp.HTML(self.html_code			)    ,       display_id=A__			)
						else:
							self.output.update(disp.HTML(self.html_code			)			)






					def   __A			( self    ,       A__			):
						if self.inner_table is None:
							A__							:    List[str]        =		[list(values.keys()			), list(values.values()			)]
						else:
							A__							:    Optional[Any]        =		self.inner_table[0]
							if len(self.inner_table			) == 1:
								# We give a chance to update the column names at the first iteration
								for key in values.keys():
									if key not in columns:
										columns.append(A__			)
								A__							:    Any        =		columns
							self.inner_table.append([values[c] for c in columns]			)






					def   __A			( self    ,       A__    ,       A__=None    ,       A__=300			):
						A__							:    Optional[Any]        =		NotebookProgressBar(A__    ,       prefix=A__    ,       parent=self    ,       width=A__			)
						return self.child_bar






					def   __A			( self			):
						A__							:    List[str]        =		None
						self.display()



class     _a						(__magic_name__				):


					'''simple docstring'''






					def __init__( self			):
						A__							:    int        =		None
						A__							:    List[str]        =		None
						A__							:    Union[str, Any]        =		False






					def   __A			( self    ,       A__    ,       A__    ,       A__    ,       **A__			):
						A__							:    List[str]        =		"""Epoch""" if args.evaluation_strategy == IntervalStrategy.EPOCH else """Step"""
						A__							:    Dict        =		0
						A__							:    Tuple        =		0
						A__							:    Optional[int]        =		[self.first_column] + ["""Training Loss"""]
						if args.evaluation_strategy != IntervalStrategy.NO:
							column_names.append("""Validation Loss"""			)
						A__							:    Union[str, Any]        =		NotebookTrainingTracker(state.max_steps    ,       A__			)






					def   __A			( self    ,       A__    ,       A__    ,       A__    ,       **A__			):
						A__							:    Any        =		int(state.epoch			) if int(state.epoch			) == state.epoch else F"""{state.epoch:.2f}"""
						self.training_tracker.update(
						    state.global_step + 1    ,       comment=F"""Epoch {epoch}/{state.num_train_epochs}"""    ,       force_update=self._force_next_update    ,       )
						A__							:    str        =		False






					def   __A			( self    ,       A__    ,       A__    ,       A__    ,       A__=None    ,       **A__			):
						if not has_length(A__			):
							return
						if self.prediction_bar is None:
							if self.training_tracker is not None:
								A__							:    Union[str, Any]        =		self.training_tracker.add_child(len(A__			)			)
							else:
								A__							:    Tuple        =		NotebookProgressBar(len(A__			)			)
							self.prediction_bar.update(1			)
						else:
							self.prediction_bar.update(self.prediction_bar.value + 1			)






					def   __A			( self    ,       A__    ,       A__    ,       A__    ,       **A__			):
						if self.prediction_bar is not None:
							self.prediction_bar.close()
						A__							:    List[str]        =		None






					def   __A			( self    ,       A__    ,       A__    ,       A__    ,       A__=None    ,       **A__			):
						# Only for when there is no evaluation
						if args.evaluation_strategy == IntervalStrategy.NO and "loss" in logs:
							A__							:    Dict        =		{"""Training Loss""": logs["""loss"""]}
							# First column is necessarily Step sine we're not in epoch eval strategy
							A__							:    List[Any]        =		state.global_step
							self.training_tracker.write_line(A__			)






					def   __A			( self    ,       A__    ,       A__    ,       A__    ,       A__=None    ,       **A__			):
						if self.training_tracker is not None:
							A__							:    Tuple        =		{"""Training Loss""": """No log""", """Validation Loss""": """No log"""}
							for log in reversed(state.log_history			):
								if "loss" in log:
									A__							:    Dict        =		log["""loss"""]
									break

							if self.first_column == "Epoch":
								A__							:    List[Any]        =		int(state.epoch			)
							else:
								A__							:    Optional[Any]        =		state.global_step
							A__							:    Optional[Any]        =		"""eval"""
							for k in metrics:
								if k.endswith("""_loss"""			):
									A__							:    Optional[int]        =		re.sub(r"""\_loss$"""    ,       """"""    ,       A__			)
							A__							:    int        =		metrics.pop("""total_flos"""    ,       A__			)
							A__							:    int        =		metrics.pop("""epoch"""    ,       A__			)
							A__							:    Optional[int]        =		metrics.pop(F"""{metric_key_prefix}_runtime"""    ,       A__			)
							A__							:    Any        =		metrics.pop(F"""{metric_key_prefix}_samples_per_second"""    ,       A__			)
							A__							:    List[Any]        =		metrics.pop(F"""{metric_key_prefix}_steps_per_second"""    ,       A__			)
							A__							:    Optional[Any]        =		metrics.pop(F"""{metric_key_prefix}_jit_compilation_time"""    ,       A__			)
							for k, v in metrics.items():
								if k == F"""{metric_key_prefix}_loss""":
									A__							:    Any        =		v
								else:
									A__							:    Optional[Any]        =		k.split("""_"""			)
									A__							:    Any        =		""" """.join([part.capitalize() for part in splits[1:]]			)
									A__							:    List[str]        =		v
							self.training_tracker.write_line(A__			)
							self.training_tracker.remove_child()
							A__							:    Dict        =		None
							# Evaluation takes a long time so we should force the next update.
							A__							:    Union[str, Any]        =		True






					def   __A			( self    ,       A__    ,       A__    ,       A__    ,       **A__			):
						self.training_tracker.update(
						    state.global_step    ,       comment=F"""Epoch {int(state.epoch			)}/{state.num_train_epochs}"""    ,       force_update=A__			)
						A__							:    Optional[int]        =		None



