

from abc import ABC, abstractmethod
from typing import List, Optional



class   __lowercase				( UpperCAmelCase_	):




			"""simple docstring"""







			def __init__( self  :     List[Any]):
									# test for the above condition
									self.test()



			def        _SCREAMING_SNAKE_CASE			( self  :     str):
									SCREAMING_SNAKE_CASE_: List[str]  		=       0
									SCREAMING_SNAKE_CASE_: List[str]  		=       False
									while not completed:
															if counter == 1:
																					self.reset()
															SCREAMING_SNAKE_CASE_: Optional[Any]  		=       self.advance()
															if not self.does_advance(A__):
																					raise Exception(
																					    "Custom Constraint is not defined correctly. self.does_advance(self.advance()) must be true.")

															SCREAMING_SNAKE_CASE_: List[Any]  		=       self.update(A__)
															counter += 1

															if counter > 1_0000:
																					raise Exception("update() does not fulfill the constraint.")

									if self.remaining() != 0:
															raise Exception("Custom Constraint is not defined correctly.")



			@abstractmethod
			def        _SCREAMING_SNAKE_CASE			( self  :     Union[str, Any]):
									raise NotImplementedError(
									    F"{self.__class__} is an abstract class. Only classes inheriting this class can be called.")



			@abstractmethod
			def        _SCREAMING_SNAKE_CASE			( self  :     Tuple   ,						lowerCAmelCase__  :     Union[str, Any]):
									raise NotImplementedError(
									    F"{self.__class__} is an abstract class. Only classes inheriting this class can be called.")



			@abstractmethod
			def        _SCREAMING_SNAKE_CASE			( self  :     int   ,						lowerCAmelCase__  :     Optional[int]):
									raise NotImplementedError(
									    F"{self.__class__} is an abstract class. Only classes inheriting this class can be called.")



			@abstractmethod
			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[Any]):
									raise NotImplementedError(
									    F"{self.__class__} is an abstract class. Only classes inheriting this class can be called.")



			@abstractmethod
			def        _SCREAMING_SNAKE_CASE			( self  :     List[str]):
									raise NotImplementedError(
									    F"{self.__class__} is an abstract class. Only classes inheriting this class can be called.")




			@abstractmethod
			def        _SCREAMING_SNAKE_CASE			( self  :     int   ,						lowerCAmelCase__  :     Optional[Any]=False):
									raise NotImplementedError(
									    F"{self.__class__} is an abstract class. Only classes inheriting this class can be called.")







class   __lowercase				( UpperCAmelCase_	):




			"""simple docstring"""







			def __init__( self  :     Dict   ,						lowerCAmelCase__  :     str):
									super(A__   ,						self).__init__()

									if not isinstance(A__   ,						A__) or len(A__) == 0:
															raise ValueError(F"`token_ids` has to be a non-empty list, but is {token_ids}.")
									if any((not isinstance(A__   ,						A__) or token_id < 0) for token_id in token_ids):
															raise ValueError(F"Each list in `token_ids` has to be a list of positive integers, but is {token_ids}.")

									SCREAMING_SNAKE_CASE_: List[Any]  		=       token_ids

									SCREAMING_SNAKE_CASE_: str  		=       len(self.token_ids)
									SCREAMING_SNAKE_CASE_: Dict  		=       -1  # the index of the currently fulfilled step
									SCREAMING_SNAKE_CASE_: List[str]  		=       False



			def        _SCREAMING_SNAKE_CASE			( self  :     Dict):
									if self.completed:
															return None
									return self.token_ids[self.fulfilled_idx + 1]



			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[int]   ,						lowerCAmelCase__  :     Optional[int]):
									if not isinstance(A__   ,						A__):
															raise ValueError(F"`token_id` has to be an `int`, but is {token_id} of type {type(A__)}")

									if self.completed:
															return False

									return token_id == self.token_ids[self.fulfilled_idx + 1]



			def        _SCREAMING_SNAKE_CASE			( self  :     str   ,						lowerCAmelCase__  :     Union[str, Any]):
									if not isinstance(A__   ,						A__):
															raise ValueError(F"`token_id` has to be an `int`, but is {token_id} of type {type(A__)}")

									SCREAMING_SNAKE_CASE_: Any  		=       False
									SCREAMING_SNAKE_CASE_: Optional[int]  		=       False
									SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       False

									if self.does_advance(A__):
															self.fulfilled_idx += 1
															SCREAMING_SNAKE_CASE_: List[Any]  		=       True
															if self.fulfilled_idx == (self.seqlen - 1):
																					SCREAMING_SNAKE_CASE_: Optional[int]  		=       True
															SCREAMING_SNAKE_CASE_: List[Any]  		=       completed
									else:
															# failed to make progress.
															SCREAMING_SNAKE_CASE_: List[str]  		=       True
															self.reset()
									return stepped, completed, reset



			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[int]):
									SCREAMING_SNAKE_CASE_: List[str]  		=       False
									SCREAMING_SNAKE_CASE_: Any  		=       0



			def        _SCREAMING_SNAKE_CASE			( self  :     List[str]):
									return self.seqlen - (self.fulfilled_idx + 1)




			def        _SCREAMING_SNAKE_CASE			( self  :     Dict   ,						lowerCAmelCase__  :     Tuple=False):
									SCREAMING_SNAKE_CASE_: Any  		=       PhrasalConstraint(self.token_ids)

									if stateful:
															SCREAMING_SNAKE_CASE_: List[str]  		=       self.seqlen
															SCREAMING_SNAKE_CASE_: str  		=       self.fulfilled_idx
															SCREAMING_SNAKE_CASE_: Optional[Any]  		=       self.completed

									return new_constraint







class   __lowercase				:




			"""simple docstring"""







			def __init__( self  :     Union[str, Any]   ,						lowerCAmelCase__  :     List[Any]   ,						lowerCAmelCase__  :     Dict=True):
									SCREAMING_SNAKE_CASE_: List[str]  		=       max([len(A__) for one in nested_token_ids])

									SCREAMING_SNAKE_CASE_: str  		=       {}
									for token_ids in nested_token_ids:
															SCREAMING_SNAKE_CASE_: List[Any]  		=       root
															for tidx, token_id in enumerate(A__):
																					if token_id not in level:
																											SCREAMING_SNAKE_CASE_: Tuple  		=       {}

																					SCREAMING_SNAKE_CASE_: int  		=       level[token_id]

									if no_subsets and self.has_subsets(A__   ,						A__):
															raise ValueError(
															    "Each list in `nested_token_ids` can't be a complete subset of another list, but is"
															    F" {nested_token_ids}.")

									SCREAMING_SNAKE_CASE_: int  		=       root



			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[Any]   ,						lowerCAmelCase__  :     List[str]):
									SCREAMING_SNAKE_CASE_: Tuple  		=       self.trie

									for current_token in current_seq:
															SCREAMING_SNAKE_CASE_: Tuple  		=       start[current_token]

									SCREAMING_SNAKE_CASE_: Optional[int]  		=       list(start.keys())

									return next_tokens



			def        _SCREAMING_SNAKE_CASE			( self  :     int   ,						lowerCAmelCase__  :     List[str]):
									SCREAMING_SNAKE_CASE_: List[str]  		=       self.next_tokens(A__)

									return len(A__) == 0



			def        _SCREAMING_SNAKE_CASE			( self  :     Any   ,						lowerCAmelCase__  :     Optional[Any]):
									SCREAMING_SNAKE_CASE_: Tuple  		=       list(root.values())
									if len(A__) == 0:
															return 1
									else:
															return sum([self.count_leaves(A__) for nn in next_nodes])




			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[int]   ,						lowerCAmelCase__  :     List[str]   ,						lowerCAmelCase__  :     List[str]):
									SCREAMING_SNAKE_CASE_: List[Any]  		=       self.count_leaves(A__)
									return len(A__) != leaf_count







class   __lowercase				( UpperCAmelCase_	):




			"""simple docstring"""







			def __init__( self  :     Optional[int]   ,						lowerCAmelCase__  :     Any):
									super(A__   ,						self).__init__()

									if not isinstance(A__   ,						A__) or len(A__) == 0:
															raise ValueError(F"`nested_token_ids` has to be a non-empty list, but is {nested_token_ids}.")
									if any(not isinstance(A__   ,						A__) for token_ids in nested_token_ids):
															raise ValueError(F"`nested_token_ids` has to be a list of lists, but is {nested_token_ids}.")
									if any(
									    any((not isinstance(A__   ,						A__) or token_id < 0) for token_id in token_ids)
									    for token_ids in nested_token_ids):
															raise ValueError(
															    F"Each list in `nested_token_ids` has to be a list of positive integers, but is {nested_token_ids}.")

									SCREAMING_SNAKE_CASE_: Dict  		=       DisjunctiveTrie(A__)
									SCREAMING_SNAKE_CASE_: List[str]  		=       nested_token_ids

									SCREAMING_SNAKE_CASE_: Optional[int]  		=       self.trie.max_height
									SCREAMING_SNAKE_CASE_: Tuple  		=       []
									SCREAMING_SNAKE_CASE_: List[Any]  		=       False



			def        _SCREAMING_SNAKE_CASE			( self  :     Union[str, Any]):
									SCREAMING_SNAKE_CASE_: Optional[int]  		=       self.trie.next_tokens(self.current_seq)

									if len(A__) == 0:
															return None
									else:
															return token_list



			def        _SCREAMING_SNAKE_CASE			( self  :     Tuple   ,						lowerCAmelCase__  :     List[Any]):
									if not isinstance(A__   ,						A__):
															raise ValueError(F"`token_id` is supposed to be type `int`, but is {token_id} of type {type(A__)}")

									SCREAMING_SNAKE_CASE_: Optional[Any]  		=       self.trie.next_tokens(self.current_seq)

									return token_id in next_tokens



			def        _SCREAMING_SNAKE_CASE			( self  :     List[str]   ,						lowerCAmelCase__  :     Any):
									if not isinstance(A__   ,						A__):
															raise ValueError(F"`token_id` is supposed to be type `int`, but is {token_id} of type {type(A__)}")

									SCREAMING_SNAKE_CASE_: List[str]  		=       False
									SCREAMING_SNAKE_CASE_: Any  		=       False
									SCREAMING_SNAKE_CASE_: Optional[int]  		=       False

									if self.does_advance(A__):
															self.current_seq.append(A__)
															SCREAMING_SNAKE_CASE_: str  		=       True
									else:
															SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       True
															self.reset()

									SCREAMING_SNAKE_CASE_: Tuple  		=       self.trie.reached_leaf(self.current_seq)
									SCREAMING_SNAKE_CASE_: Any  		=       completed

									return stepped, completed, reset



			def        _SCREAMING_SNAKE_CASE			( self  :     Union[str, Any]):
									SCREAMING_SNAKE_CASE_: Optional[int]  		=       False
									SCREAMING_SNAKE_CASE_: List[Any]  		=       []



			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[Any]):
									if self.completed:
															# since this can be completed without reaching max height
															return 0
									else:
															return self.seqlen - len(self.current_seq)




			def        _SCREAMING_SNAKE_CASE			( self  :     str   ,						lowerCAmelCase__  :     str=False):
									SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       DisjunctiveConstraint(self.token_ids)

									if stateful:
															SCREAMING_SNAKE_CASE_: str  		=       self.seqlen
															SCREAMING_SNAKE_CASE_: int  		=       self.current_seq
															SCREAMING_SNAKE_CASE_: int  		=       self.completed

									return new_constraint







class   __lowercase				:




			"""simple docstring"""







			def __init__( self  :     Dict   ,						lowerCAmelCase__  :     List[Any]):
									SCREAMING_SNAKE_CASE_: List[str]  		=       constraints

									# max # of steps required to fulfill a given constraint
									SCREAMING_SNAKE_CASE_: List[Any]  		=       max([c.seqlen for c in constraints])
									SCREAMING_SNAKE_CASE_: str  		=       len(A__)
									SCREAMING_SNAKE_CASE_: Optional[Any]  		=       False

									self.init_state()



			def        _SCREAMING_SNAKE_CASE			( self  :     List[str]):
									SCREAMING_SNAKE_CASE_: int  		=       []
									SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       None
									SCREAMING_SNAKE_CASE_: List[Any]  		=       [constraint.copy(stateful=A__) for constraint in self.constraints]



			def        _SCREAMING_SNAKE_CASE			( self  :     List[Any]):
									SCREAMING_SNAKE_CASE_: List[str]  		=       0
									if self.inprogress_constraint:
															# extra points for having a constraint mid-fulfilled
															add += self.max_seqlen - self.inprogress_constraint.remaining()

									return (len(self.complete_constraints) * self.max_seqlen) + add



			def        _SCREAMING_SNAKE_CASE			( self  :     Union[str, Any]):
									SCREAMING_SNAKE_CASE_: Optional[Any]  		=       []
									if self.inprogress_constraint is None:
															for constraint in self.pending_constraints:  # "pending" == "unfulfilled yet"
																					SCREAMING_SNAKE_CASE_: Optional[Any]  		=       constraint.advance()
																					if isinstance(A__   ,						A__):
																											token_list.append(A__)
																					elif isinstance(A__   ,						A__):
																											token_list.extend(A__)
									else:
															SCREAMING_SNAKE_CASE_: Optional[Any]  		=       self.inprogress_constraint.advance()
															if isinstance(A__   ,						A__):
																					token_list.append(A__)
															elif isinstance(A__   ,						A__):
																					token_list.extend(A__)

									if len(A__) == 0:
															return None
									else:
															return token_list



			def        _SCREAMING_SNAKE_CASE			( self  :     List[Any]   ,						lowerCAmelCase__  :     Any):
									self.init_state()

									if token_ids is not None:
															for token in token_ids:
																					# completes or steps **one** constraint
																					SCREAMING_SNAKE_CASE_: Tuple  		=       self.add(A__)

																					# the entire list of constraints are fulfilled
																					if self.completed:
																											break



			def        _SCREAMING_SNAKE_CASE			( self  :     List[Any]   ,						lowerCAmelCase__  :     List[Any]):
									if not isinstance(A__   ,						A__):
															raise ValueError(F"`token_id` should be an `int`, but is `{token_id}`.")

									SCREAMING_SNAKE_CASE_: Optional[Any]  		=       False, False

									if self.completed:
															SCREAMING_SNAKE_CASE_: List[str]  		=       True
															SCREAMING_SNAKE_CASE_: str  		=       False
															return complete, stepped

									if self.inprogress_constraint is not None:
															# In the middle of fulfilling a constraint. If the `token_id` *does* makes an incremental progress to current
															# job, simply update the state

															SCREAMING_SNAKE_CASE_: Dict  		=       self.inprogress_constraint.update(A__)
															if reset:
																					# 1. If the next token breaks the progress, then we must restart.
																					#     e.g. constraint = "I love pies" and sequence so far is "I love" but `token_id` == "books".

																					#     But that doesn't mean we self.init_state(), since we only reset the state for this particular
																					#     constraint, not the full list of constraints.

																					self.pending_constraints.append(self.inprogress_constraint.copy(stateful=A__))
																					SCREAMING_SNAKE_CASE_: Optional[int]  		=       None

															if complete:
																					# 2. If the next token completes the constraint, move it to completed list, set
																					#     inprogress to None. If there are no pending constraints either, then this full list of constraints
																					#     is complete.

																					self.complete_constraints.append(self.inprogress_constraint)
																					SCREAMING_SNAKE_CASE_: Any  		=       None

																					if len(self.pending_constraints) == 0:
																											# we're done!
																											SCREAMING_SNAKE_CASE_: List[Any]  		=       True

									else:
															# Not in the middle of fulfilling a constraint. So does this `token_id` helps us step towards any of our list
															# of constraints?

															for cidx, pending_constraint in enumerate(self.pending_constraints):
																					if pending_constraint.does_advance(A__):
																											SCREAMING_SNAKE_CASE_: List[Any]  		=       pending_constraint.update(A__)

																											if not stepped:
																																	raise Exception(
																																	    "`constraint.update(token_id)` is not yielding incremental progress, "
																																	    "even though `constraint.does_advance(token_id)` is true.")

																											if complete:
																																	self.complete_constraints.append(A__)
																																	SCREAMING_SNAKE_CASE_: Optional[Any]  		=       None

																											if not complete and stepped:
																																	SCREAMING_SNAKE_CASE_: Dict  		=       pending_constraint

																											if complete or stepped:
																																	# If we made any progress at all, then it's at least not a "pending constraint".

																																	SCREAMING_SNAKE_CASE_: Tuple  		=       (
																																	    self.pending_constraints[:cidx] + self.pending_constraints[cidx + 1 :]
																																	)

																																	if len(self.pending_constraints) == 0 and self.inprogress_constraint is None:
																																							# If there's no longer any pending after this and no inprogress either, then we must be
																																							# complete.

																																							SCREAMING_SNAKE_CASE_: Any  		=       True

																																	break  # prevent accidentally stepping through multiple constraints with just one token.

									return complete, stepped




			def        _SCREAMING_SNAKE_CASE			( self  :     Tuple   ,						lowerCAmelCase__  :     str=True):
									SCREAMING_SNAKE_CASE_: int  		=       ConstraintListState(self.constraints)  # we actually never though self.constraints objects
									# throughout this process. So it's at initialization state.

									if stateful:
															SCREAMING_SNAKE_CASE_: Optional[int]  		=       [
															    constraint.copy(stateful=A__) for constraint in self.complete_constraints
															]
															if self.inprogress_constraint is not None:
																					SCREAMING_SNAKE_CASE_: str  		=       self.inprogress_constraint.copy(stateful=A__)
															SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       [constraint.copy() for constraint in self.pending_constraints]

									return new_state









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



