





'''simple docstring'''

import argparse
import json
import os
import sys
import tempfile
import unittest
from argparse import Namespace
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import List, Literal, Optional

import yaml

from transformers import HfArgumentParser, TrainingArguments
from transformers.hf_argparser import make_choice_type_function, string_to_bool


# Since Python 3.10, we can use the builtin `|` operator for Union types
# See PEP 604: https://peps.python.org/pep-0604
lowercase__						:      List[str]	=    sys.version_info >= (3, 10)







def  a__    (    lowercase :					Dict=None, lowercase :					List[str]=None				)		->		List[Any]:





     """simple docstring"""

     return field(default_factory=lambda: default, metadata=lowercase				)
@dataclass
class     __lowerCAmelCase					:






       """simple docstring"""
       _snake_case     :					int
       _snake_case     :					float
       _snake_case     :					str
       _snake_case     :					bool

@dataclass
class     __lowerCAmelCase					:






       """simple docstring"""
       _snake_case     :					int						    =   4_2
       _snake_case     :					str						    =   field(default='toto'						,						metadata={'help': 'help message'}			)

@dataclass
class     __lowerCAmelCase					:






       """simple docstring"""
       _snake_case     :					bool						    =   False
       _snake_case     :					bool						    =   True
       _snake_case     :					Optional[bool]						    =   None

class     __lowerCAmelCase					(   __magic_name__			):






       """simple docstring"""
       _snake_case     :					str						    =   'titi'
       _snake_case     :					Union[str, Any]						    =   'toto'

class     __lowerCAmelCase					(   __magic_name__			):






       """simple docstring"""
       _snake_case     :					str						    =   'titi'
       _snake_case     :					Union[str, Any]						    =   'toto'
       _snake_case     :					Any						    =   4_2

@dataclass
class     __lowerCAmelCase					:






       """simple docstring"""
       _snake_case     :					BasicEnum						    =   "toto"





       def snake_case__						(							self       :		List[Any]					)   ->					List[Any]:

            '''simple docstring'''




            _UpperCamelCase       =	BasicEnum(self.foo					)

@dataclass
class     __lowerCAmelCase					:






       """simple docstring"""
       _snake_case     :					MixedTypeEnum						    =   "toto"





       def snake_case__						(							self       :		Dict					)   ->					Union[str, Any]:

            '''simple docstring'''




            _UpperCamelCase       =	MixedTypeEnum(self.foo					)

@dataclass
class     __lowerCAmelCase					:






       """simple docstring"""
       _snake_case     :					Optional[int]						    =   None
       _snake_case     :					Optional[float]						    =   field(default=__magic_name__						,						metadata={'help': 'help message'}			)
       _snake_case     :					Optional[str]						    =   None
       _snake_case     :					Optional[List[str]]						    =   list_field(default=[]			)
       _snake_case     :					Optional[List[int]]						    =   list_field(default=[]			)

@dataclass
class     __lowerCAmelCase					:






       """simple docstring"""
       _snake_case     :					List[int]						    =   list_field(default=[]			)
       _snake_case     :					List[int]						    =   list_field(default=[1, 2, 3]			)
       _snake_case     :					List[str]						    =   list_field(default=['Hallo', 'Bonjour', 'Hello']			)
       _snake_case     :					List[float]						    =   list_field(default=[0.1, 0.2, 0.3]			)

@dataclass
class     __lowerCAmelCase					:






       """simple docstring"""
       _snake_case     :					List[int]						    =   field()
       _snake_case     :					str						    =   field()
       _snake_case     :					BasicEnum						    =   field()





       def snake_case__						(							self       :		str					)   ->					Any:

            '''simple docstring'''




            _UpperCamelCase       =	BasicEnum(self.required_enum					)

@dataclass
class     __lowerCAmelCase					:






       """simple docstring"""
       _snake_case     :					int
       _snake_case     :					"BasicEnum"						    =   field()
       _snake_case     :					"Optional[bool]"						    =   None
       _snake_case     :					"str"						    =   field(default='toto'						,						metadata={'help': 'help message'}			)
       _snake_case     :					"List[str]"						    =   list_field(default=['Hallo', 'Bonjour', 'Hello']			)


if is_python_no_less_than_3_10:
  @dataclass
  class     __lowerCAmelCase					:






         """simple docstring"""
         _snake_case     :					bool						    =   False
         _snake_case     :					bool						    =   True
         _snake_case     :					bool | None						    =   None

  @dataclass
  class     __lowerCAmelCase					:






         """simple docstring"""
         _snake_case     :					int | None						    =   None
         _snake_case     :					float | None						    =   field(default=__magic_name__						,						metadata={'help': 'help message'}			)
         _snake_case     :					str | None						    =   None
         _snake_case     :					list[str] | None						    =   list_field(default=[]			)
         _snake_case     :					list[int] | None						    =   list_field(default=[]			)




class     __lowerCAmelCase					(   unittest.TestCase			):






       """simple docstring"""





       def snake_case__						(							self       :		Optional[Any]	,			lowerCAmelCase__       :		argparse.ArgumentParser	,			lowerCAmelCase__       :		argparse.ArgumentParser					)   ->					str:

            '''simple docstring'''




            self.assertEqual(len(a._actions					)	,			len(b._actions					)					)
            for x, y in zip(a._actions	,			b._actions					):
                 _UpperCamelCase       =	{k: v for k, v in vars(lowerCAmelCase__					).items() if k != '''container'''}
                 _UpperCamelCase       =	{k: v for k, v in vars(lowerCAmelCase__					).items() if k != '''container'''}

                 # Choices with mixed type have custom function as "type"
                 # So we need to compare results directly for equality
                 if xx.get('''choices'''	,			lowerCAmelCase__					) and yy.get('''choices'''	,			lowerCAmelCase__					):
                      for expected_choice in yy["choices"] + xx["choices"]:
                           self.assertEqual(xx['''type'''](lowerCAmelCase__					)	,			yy['''type'''](lowerCAmelCase__					)					)
                      del xx["type"], yy["type"]

                 self.assertEqual(lowerCAmelCase__	,			lowerCAmelCase__					)





       def snake_case__						(							self       :		Dict					)   ->					List[Any]:

            '''simple docstring'''




            _UpperCamelCase       =	HfArgumentParser(lowerCAmelCase__					)

            _UpperCamelCase       =	argparse.ArgumentParser()
            expected.add_argument('''--foo'''	,			type=lowerCAmelCase__	,			required=lowerCAmelCase__					)
            expected.add_argument('''--bar'''	,			type=lowerCAmelCase__	,			required=lowerCAmelCase__					)
            expected.add_argument('''--baz'''	,			type=lowerCAmelCase__	,			required=lowerCAmelCase__					)
            expected.add_argument('''--flag'''	,			type=lowerCAmelCase__	,			default=lowerCAmelCase__	,			const=lowerCAmelCase__	,			nargs='''?'''					)
            self.argparsersEqual(lowerCAmelCase__	,			lowerCAmelCase__					)

            _UpperCamelCase       =	['''--foo''', '''1''', '''--baz''', '''quux''', '''--bar''', '''0.5''']
            ((_UpperCamelCase    )   ,        )       =	parser.parse_args_into_dataclasses(lowerCAmelCase__	,			look_for_args_file=lowerCAmelCase__					)
            self.assertFalse(example.flag					)





       def snake_case__						(							self       :		int					)   ->					Any:

            '''simple docstring'''




            _UpperCamelCase       =	HfArgumentParser(lowerCAmelCase__					)

            _UpperCamelCase       =	argparse.ArgumentParser()
            expected.add_argument('''--foo'''	,			default=42	,			type=lowerCAmelCase__					)
            expected.add_argument('''--baz'''	,			default='''toto'''	,			type=lowerCAmelCase__	,			help='''help message'''					)
            self.argparsersEqual(lowerCAmelCase__	,			lowerCAmelCase__					)





       def snake_case__						(							self       :		Tuple					)   ->					Optional[Any]:

            '''simple docstring'''




            _UpperCamelCase       =	argparse.ArgumentParser()
            expected.add_argument('''--foo'''	,			type=lowerCAmelCase__	,			default=lowerCAmelCase__	,			const=lowerCAmelCase__	,			nargs='''?'''					)
            expected.add_argument('''--baz'''	,			type=lowerCAmelCase__	,			default=lowerCAmelCase__	,			const=lowerCAmelCase__	,			nargs='''?'''					)
            # A boolean no_* argument always has to come after its "default: True" regular counter-part
            # and its default must be set to False
            expected.add_argument('''--no_baz'''	,			action='''store_false'''	,			default=lowerCAmelCase__	,			dest='''baz'''					)
            expected.add_argument('''--opt'''	,			type=lowerCAmelCase__	,			default=lowerCAmelCase__					)

            _UpperCamelCase       =	[WithDefaultBoolExample]
            if is_python_no_less_than_3_10:
                 dataclass_types.append(lowerCAmelCase__					)

            for dataclass_type in dataclass_types:
                 _UpperCamelCase       =	HfArgumentParser(lowerCAmelCase__					)
                 self.argparsersEqual(lowerCAmelCase__	,			lowerCAmelCase__					)

                 _UpperCamelCase       =	parser.parse_args([]					)
                 self.assertEqual(lowerCAmelCase__	,			Namespace(foo=lowerCAmelCase__	,			baz=lowerCAmelCase__	,			opt=lowerCAmelCase__					)					)

                 _UpperCamelCase       =	parser.parse_args(['''--foo''', '''--no_baz''']					)
                 self.assertEqual(lowerCAmelCase__	,			Namespace(foo=lowerCAmelCase__	,			baz=lowerCAmelCase__	,			opt=lowerCAmelCase__					)					)

                 _UpperCamelCase       =	parser.parse_args(['''--foo''', '''--baz''']					)
                 self.assertEqual(lowerCAmelCase__	,			Namespace(foo=lowerCAmelCase__	,			baz=lowerCAmelCase__	,			opt=lowerCAmelCase__					)					)

                 _UpperCamelCase       =	parser.parse_args(['''--foo''', '''True''', '''--baz''', '''True''', '''--opt''', '''True''']					)
                 self.assertEqual(lowerCAmelCase__	,			Namespace(foo=lowerCAmelCase__	,			baz=lowerCAmelCase__	,			opt=lowerCAmelCase__					)					)

                 _UpperCamelCase       =	parser.parse_args(['''--foo''', '''False''', '''--baz''', '''False''', '''--opt''', '''False''']					)
                 self.assertEqual(lowerCAmelCase__	,			Namespace(foo=lowerCAmelCase__	,			baz=lowerCAmelCase__	,			opt=lowerCAmelCase__					)					)





       def snake_case__						(							self       :		Union[str, Any]					)   ->					Optional[Any]:

            '''simple docstring'''




            _UpperCamelCase       =	HfArgumentParser(lowerCAmelCase__					)

            _UpperCamelCase       =	argparse.ArgumentParser()
            expected.add_argument(
                '''--foo'''	,			default='''toto'''	,			choices=['''titi''', '''toto''', 42]	,			type=make_choice_type_function(['''titi''', '''toto''', 42]					)	,			)
            self.argparsersEqual(lowerCAmelCase__	,			lowerCAmelCase__					)

            _UpperCamelCase       =	parser.parse_args([]					)
            self.assertEqual(args.foo	,			'''toto'''					)
            _UpperCamelCase       =	parser.parse_args_into_dataclasses([]					)[0]
            self.assertEqual(enum_ex.foo	,			MixedTypeEnum.toto					)

            _UpperCamelCase       =	parser.parse_args(['''--foo''', '''titi''']					)
            self.assertEqual(args.foo	,			'''titi'''					)
            _UpperCamelCase       =	parser.parse_args_into_dataclasses(['''--foo''', '''titi''']					)[0]
            self.assertEqual(enum_ex.foo	,			MixedTypeEnum.titi					)

            _UpperCamelCase       =	parser.parse_args(['''--foo''', '''42''']					)
            self.assertEqual(args.foo	,			42					)
            _UpperCamelCase       =	parser.parse_args_into_dataclasses(['''--foo''', '''42''']					)[0]
            self.assertEqual(enum_ex.foo	,			MixedTypeEnum.fourtytwo					)





       def snake_case__						(							self       :		Any					)   ->					List[Any]:

            '''simple docstring'''




            @dataclass
            class     __lowerCAmelCase					:






                   """simple docstring"""
                   _snake_case     :					Literal["titi", "toto", 4_2]						    =   "toto"

            _UpperCamelCase       =	HfArgumentParser(lowerCAmelCase__					)

            _UpperCamelCase       =	argparse.ArgumentParser()
            expected.add_argument(
                '''--foo'''	,			default='''toto'''	,			choices=('''titi''', '''toto''', 42)	,			type=make_choice_type_function(['''titi''', '''toto''', 42]					)	,			)
            self.argparsersEqual(lowerCAmelCase__	,			lowerCAmelCase__					)

            _UpperCamelCase       =	parser.parse_args([]					)
            self.assertEqual(args.foo	,			'''toto'''					)

            _UpperCamelCase       =	parser.parse_args(['''--foo''', '''titi''']					)
            self.assertEqual(args.foo	,			'''titi'''					)

            _UpperCamelCase       =	parser.parse_args(['''--foo''', '''42''']					)
            self.assertEqual(args.foo	,			42					)





       def snake_case__						(							self       :		int					)   ->					Union[str, Any]:

            '''simple docstring'''




            _UpperCamelCase       =	HfArgumentParser(lowerCAmelCase__					)

            _UpperCamelCase       =	argparse.ArgumentParser()
            expected.add_argument('''--foo_int'''	,			nargs='''+'''	,			default=[]	,			type=lowerCAmelCase__					)
            expected.add_argument('''--bar_int'''	,			nargs='''+'''	,			default=[1, 2, 3]	,			type=lowerCAmelCase__					)
            expected.add_argument('''--foo_str'''	,			nargs='''+'''	,			default=['''Hallo''', '''Bonjour''', '''Hello''']	,			type=lowerCAmelCase__					)
            expected.add_argument('''--foo_float'''	,			nargs='''+'''	,			default=[0.1, 0.2, 0.3]	,			type=lowerCAmelCase__					)

            self.argparsersEqual(lowerCAmelCase__	,			lowerCAmelCase__					)

            _UpperCamelCase       =	parser.parse_args([]					)
            self.assertEqual(
                lowerCAmelCase__	,			Namespace(foo_int=[]	,			bar_int=[1, 2, 3]	,			foo_str=['''Hallo''', '''Bonjour''', '''Hello''']	,			foo_float=[0.1, 0.2, 0.3]					)	,			)

            _UpperCamelCase       =	parser.parse_args('''--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7'''.split()					)
            self.assertEqual(lowerCAmelCase__	,			Namespace(foo_int=[1]	,			bar_int=[2, 3]	,			foo_str=['''a''', '''b''', '''c''']	,			foo_float=[0.1, 0.7]					)					)





       def snake_case__						(							self       :		List[str]					)   ->					Tuple:

            '''simple docstring'''




            _UpperCamelCase       =	argparse.ArgumentParser()
            expected.add_argument('''--foo'''	,			default=lowerCAmelCase__	,			type=lowerCAmelCase__					)
            expected.add_argument('''--bar'''	,			default=lowerCAmelCase__	,			type=lowerCAmelCase__	,			help='''help message'''					)
            expected.add_argument('''--baz'''	,			default=lowerCAmelCase__	,			type=lowerCAmelCase__					)
            expected.add_argument('''--ces'''	,			nargs='''+'''	,			default=[]	,			type=lowerCAmelCase__					)
            expected.add_argument('''--des'''	,			nargs='''+'''	,			default=[]	,			type=lowerCAmelCase__					)

            _UpperCamelCase       =	[OptionalExample]
            if is_python_no_less_than_3_10:
                 dataclass_types.append(lowerCAmelCase__					)

            for dataclass_type in dataclass_types:
                 _UpperCamelCase       =	HfArgumentParser(lowerCAmelCase__					)

                 self.argparsersEqual(lowerCAmelCase__	,			lowerCAmelCase__					)

                 _UpperCamelCase       =	parser.parse_args([]					)
                 self.assertEqual(lowerCAmelCase__	,			Namespace(foo=lowerCAmelCase__	,			bar=lowerCAmelCase__	,			baz=lowerCAmelCase__	,			ces=[]	,			des=[]					)					)

                 _UpperCamelCase       =	parser.parse_args('''--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3'''.split()					)
                 self.assertEqual(lowerCAmelCase__	,			Namespace(foo=12	,			bar=3.14	,			baz='''42'''	,			ces=['''a''', '''b''', '''c''']	,			des=[1, 2, 3]					)					)





       def snake_case__						(							self       :		Any					)   ->					int:

            '''simple docstring'''




            _UpperCamelCase       =	HfArgumentParser(lowerCAmelCase__					)

            _UpperCamelCase       =	argparse.ArgumentParser()
            expected.add_argument('''--required_list'''	,			nargs='''+'''	,			type=lowerCAmelCase__	,			required=lowerCAmelCase__					)
            expected.add_argument('''--required_str'''	,			type=lowerCAmelCase__	,			required=lowerCAmelCase__					)
            expected.add_argument(
                '''--required_enum'''	,			type=make_choice_type_function(['''titi''', '''toto''']					)	,			choices=['''titi''', '''toto''']	,			required=lowerCAmelCase__	,			)
            self.argparsersEqual(lowerCAmelCase__	,			lowerCAmelCase__					)





       def snake_case__						(							self       :		Any					)   ->					int:

            '''simple docstring'''




            _UpperCamelCase       =	HfArgumentParser(lowerCAmelCase__					)

            _UpperCamelCase       =	argparse.ArgumentParser()
            expected.add_argument('''--foo'''	,			type=lowerCAmelCase__	,			required=lowerCAmelCase__					)
            expected.add_argument(
                '''--required_enum'''	,			type=make_choice_type_function(['''titi''', '''toto''']					)	,			choices=['''titi''', '''toto''']	,			required=lowerCAmelCase__	,			)
            expected.add_argument('''--opt'''	,			type=lowerCAmelCase__	,			default=lowerCAmelCase__					)
            expected.add_argument('''--baz'''	,			default='''toto'''	,			type=lowerCAmelCase__	,			help='''help message'''					)
            expected.add_argument('''--foo_str'''	,			nargs='''+'''	,			default=['''Hallo''', '''Bonjour''', '''Hello''']	,			type=lowerCAmelCase__					)
            self.argparsersEqual(lowerCAmelCase__	,			lowerCAmelCase__					)





       def snake_case__						(							self       :		int					)   ->					Optional[Any]:

            '''simple docstring'''




            _UpperCamelCase       =	HfArgumentParser(lowerCAmelCase__					)

            _UpperCamelCase       =	{
                '''foo''': 12,
                '''bar''': 3.14,
                '''baz''': '''42''',
                '''flag''': True,
            }

            _UpperCamelCase       =	parser.parse_dict(lowerCAmelCase__					)[0]
            _UpperCamelCase       =	BasicExample(**lowerCAmelCase__					)
            self.assertEqual(lowerCAmelCase__	,			lowerCAmelCase__					)





       def snake_case__						(							self       :		Any					)   ->					Tuple:

            '''simple docstring'''




            _UpperCamelCase       =	HfArgumentParser(lowerCAmelCase__					)

            _UpperCamelCase       =	{
                '''foo''': 12,
                '''bar''': 3.14,
                '''baz''': '''42''',
                '''flag''': True,
                '''extra''': 42,
            }

            self.assertRaises(lowerCAmelCase__	,			parser.parse_dict	,			lowerCAmelCase__	,			allow_extra_keys=lowerCAmelCase__					)





       def snake_case__						(							self       :		str					)   ->					Tuple:

            '''simple docstring'''




            _UpperCamelCase       =	HfArgumentParser(lowerCAmelCase__					)

            _UpperCamelCase       =	{
                '''foo''': 12,
                '''bar''': 3.14,
                '''baz''': '''42''',
                '''flag''': True,
            }
            with tempfile.TemporaryDirectory() as tmp_dir:
                 _UpperCamelCase       =	os.path.join(lowerCAmelCase__	,			'''temp_json'''					)
                 os.mkdir(lowerCAmelCase__					)
                 with open(temp_local_path + '''.json'''	,			'''w+'''					) as f:
                      json.dump(lowerCAmelCase__	,			lowerCAmelCase__					)
                 _UpperCamelCase       =	parser.parse_yaml_file(Path(temp_local_path + '''.json'''					)					)[0]

            _UpperCamelCase       =	BasicExample(**lowerCAmelCase__					)
            self.assertEqual(lowerCAmelCase__	,			lowerCAmelCase__					)





       def snake_case__						(							self       :		Optional[Any]					)   ->					Optional[int]:

            '''simple docstring'''




            _UpperCamelCase       =	HfArgumentParser(lowerCAmelCase__					)

            _UpperCamelCase       =	{
                '''foo''': 12,
                '''bar''': 3.14,
                '''baz''': '''42''',
                '''flag''': True,
            }
            with tempfile.TemporaryDirectory() as tmp_dir:
                 _UpperCamelCase       =	os.path.join(lowerCAmelCase__	,			'''temp_yaml'''					)
                 os.mkdir(lowerCAmelCase__					)
                 with open(temp_local_path + '''.yaml'''	,			'''w+'''					) as f:
                      yaml.dump(lowerCAmelCase__	,			lowerCAmelCase__					)
                 _UpperCamelCase       =	parser.parse_yaml_file(Path(temp_local_path + '''.yaml'''					)					)[0]
            _UpperCamelCase       =	BasicExample(**lowerCAmelCase__					)
            self.assertEqual(lowerCAmelCase__	,			lowerCAmelCase__					)







       def snake_case__						(							self       :		str					)   ->					str:

            '''simple docstring'''




            _UpperCamelCase       =	HfArgumentParser(lowerCAmelCase__					)
            self.assertIsNotNone(lowerCAmelCase__					)










'''simple docstring'''

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  a__    (    lowercase :					Tuple				)		->		Dict:





     """simple docstring"""

     _UpperCamelCase       =	int(lowercase				)
     _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase       =	t // 3600, (t // 60) % 60, t % 60
     return F"""{h}:{m:02d}:{s:02d}""" if h != 0 else F"""{m:02d}:{s:02d}"""







def  a__    (    lowercase :					List[Any], lowercase :					Dict, lowercase :					Optional[int], lowercase :					Union[str, Any], lowercase :					Any=300				)		->		Any:





     """simple docstring"""

     return F"""
    <div>
      {prefix}
      <progress value='{value}' max='{total}' style='width:{width}px; height:20px; vertical-align: middle;'></progress>
      {label}
    </div>
    """







def  a__    (    lowercase :					Optional[Any]				)		->		Any:





     """simple docstring"""

     _UpperCamelCase       =	'''<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:
               _UpperCamelCase       =	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     __lowerCAmelCase					:






       """simple docstring"""
       _snake_case     :					str						    =   5
       _snake_case     :					Optional[int]						    =   0.2





       def __init__(							self       :		Dict	,			lowerCAmelCase__       :		int	,			lowerCAmelCase__       :		Optional[str] = None	,			lowerCAmelCase__       :		bool = True	,			lowerCAmelCase__       :		Optional["NotebookTrainingTracker"] = None	,			lowerCAmelCase__       :		int = 300	,			)   ->					int:

            '''simple docstring'''




            _UpperCamelCase       =	total
            _UpperCamelCase       =	'''''' if prefix is None else prefix
            _UpperCamelCase       =	leave
            _UpperCamelCase       =	parent
            _UpperCamelCase       =	width
            _UpperCamelCase       =	None
            _UpperCamelCase       =	None
            _UpperCamelCase       =	None





       def snake_case__						(							self       :		str	,			lowerCAmelCase__       :		int	,			lowerCAmelCase__       :		bool = False	,			lowerCAmelCase__       :		str = None					)   ->					Dict:

            '''simple docstring'''




            _UpperCamelCase       =	value
            if comment is not None:
                 _UpperCamelCase       =	comment
            if self.last_value is None:
                 _UpperCamelCase       =	_UpperCamelCase       =	time.time()
                 _UpperCamelCase       =	_UpperCamelCase       =	value
                 _UpperCamelCase       =	_UpperCamelCase       =	None
                 _UpperCamelCase       =	self.warmup
                 _UpperCamelCase       =	1
                 self.update_bar(lowerCAmelCase__					)
            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
                 _UpperCamelCase       =	time.time()
                 _UpperCamelCase       =	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:
                      _UpperCamelCase       =	self.elapsed_time / (value - self.start_value)
                 else:
                      _UpperCamelCase       =	None
                 if value >= self.total:
                      _UpperCamelCase       =	self.total
                      _UpperCamelCase       =	None
                      if not self.leave:
                           self.close()
                 elif self.average_time_per_item is not None:
                      _UpperCamelCase       =	self.average_time_per_item * (self.total - value)
                 self.update_bar(lowerCAmelCase__					)
                 _UpperCamelCase       =	value
                 _UpperCamelCase       =	current_time
                 if self.average_time_per_item is None:
                      _UpperCamelCase       =	1
                 else:
                      _UpperCamelCase       =	max(int(self.update_every / self.average_time_per_item					)	,			1					)





       def snake_case__						(							self       :		str	,			lowerCAmelCase__       :		int	,			lowerCAmelCase__       :		Tuple=None					)   ->					Union[str, Any]:

            '''simple docstring'''




            _UpperCamelCase       =	''' ''' * (len(str(self.total					)					) - len(str(lowerCAmelCase__					)					)) + str(lowerCAmelCase__					)
            if self.elapsed_time is None:
                 _UpperCamelCase       =	f"""[{spaced_value}/{self.total} : < :"""
            elif self.predicted_remaining is None:
                 _UpperCamelCase       =	f"""[{spaced_value}/{self.total} {format_time(self.elapsed_time					)}"""
            else:
                 _UpperCamelCase       =	(
                     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 snake_case__						(							self       :		List[Any]					)   ->					Tuple:

            '''simple docstring'''




            _UpperCamelCase       =	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:
                 _UpperCamelCase       =	disp.display(disp.HTML(self.html_code					)	,			display_id=lowerCAmelCase__					)
            else:
                 self.output.update(disp.HTML(self.html_code					)					)







       def snake_case__						(							self       :		Tuple					)   ->					Any:

            '''simple docstring'''




            if self.parent is None and self.output is not None:
                 self.output.update(disp.HTML(''''''					)					)

class     __lowerCAmelCase					(   __magic_name__			):






       """simple docstring"""





       def __init__(							self       :		Any	,			lowerCAmelCase__       :		int	,			lowerCAmelCase__       :		List[Any]=None					)   ->					Dict:

            '''simple docstring'''




            super().__init__(lowerCAmelCase__					)
            _UpperCamelCase       =	None if column_names is None else [column_names]
            _UpperCamelCase       =	None





       def snake_case__						(							self       :		List[Any]					)   ->					Any:

            '''simple docstring'''




            _UpperCamelCase       =	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:
                 _UpperCamelCase       =	disp.display(disp.HTML(self.html_code					)	,			display_id=lowerCAmelCase__					)
            else:
                 self.output.update(disp.HTML(self.html_code					)					)





       def snake_case__						(							self       :		Optional[int]	,			lowerCAmelCase__       :		int					)   ->					Union[str, Any]:

            '''simple docstring'''




            if self.inner_table is None:
                 _UpperCamelCase       =	[list(values.keys()					), list(values.values()					)]
            else:
                 _UpperCamelCase       =	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(lowerCAmelCase__					)
                      _UpperCamelCase       =	columns
                 self.inner_table.append([values[c] for c in columns]					)





       def snake_case__						(							self       :		Dict	,			lowerCAmelCase__       :		Any	,			lowerCAmelCase__       :		Any=None	,			lowerCAmelCase__       :		List[str]=300					)   ->					int:

            '''simple docstring'''




            _UpperCamelCase       =	NotebookProgressBar(lowerCAmelCase__	,			prefix=lowerCAmelCase__	,			parent=self	,			width=lowerCAmelCase__					)
            return self.child_bar







       def snake_case__						(							self       :		Any					)   ->					str:

            '''simple docstring'''




            _UpperCamelCase       =	None
            self.display()

class     __lowerCAmelCase					(   __magic_name__			):






       """simple docstring"""





       def __init__(							self       :		str					)   ->					Optional[int]:

            '''simple docstring'''




            _UpperCamelCase       =	None
            _UpperCamelCase       =	None
            _UpperCamelCase       =	False





       def snake_case__						(							self       :		List[str]	,			lowerCAmelCase__       :		Optional[int]	,			lowerCAmelCase__       :		int	,			lowerCAmelCase__       :		str	,			**lowerCAmelCase__       :		Any					)   ->					Dict:

            '''simple docstring'''




            _UpperCamelCase       =	'''Epoch''' if args.evaluation_strategy == IntervalStrategy.EPOCH else '''Step'''
            _UpperCamelCase       =	0
            _UpperCamelCase       =	0
            _UpperCamelCase       =	[self.first_column] + ['''Training Loss''']
            if args.evaluation_strategy != IntervalStrategy.NO:
                 column_names.append('''Validation Loss'''					)
            _UpperCamelCase       =	NotebookTrainingTracker(state.max_steps	,			lowerCAmelCase__					)





       def snake_case__						(							self       :		Optional[int]	,			lowerCAmelCase__       :		Optional[int]	,			lowerCAmelCase__       :		List[str]	,			lowerCAmelCase__       :		Dict	,			**lowerCAmelCase__       :		Dict					)   ->					Dict:

            '''simple docstring'''




            _UpperCamelCase       =	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	,			)
            _UpperCamelCase       =	False





       def snake_case__						(							self       :		Dict	,			lowerCAmelCase__       :		Any	,			lowerCAmelCase__       :		Dict	,			lowerCAmelCase__       :		int	,			lowerCAmelCase__       :		List[Any]=None	,			**lowerCAmelCase__       :		Dict					)   ->					Dict:

            '''simple docstring'''




            if not has_length(lowerCAmelCase__					):
                 return
            if self.prediction_bar is None:
                 if self.training_tracker is not None:
                      _UpperCamelCase       =	self.training_tracker.add_child(len(lowerCAmelCase__					)					)
                 else:
                      _UpperCamelCase       =	NotebookProgressBar(len(lowerCAmelCase__					)					)
                 self.prediction_bar.update(1					)
            else:
                 self.prediction_bar.update(self.prediction_bar.value + 1					)





       def snake_case__						(							self       :		Optional[Any]	,			lowerCAmelCase__       :		Optional[int]	,			lowerCAmelCase__       :		Tuple	,			lowerCAmelCase__       :		Dict	,			**lowerCAmelCase__       :		Any					)   ->					Optional[int]:

            '''simple docstring'''




            if self.prediction_bar is not None:
                 self.prediction_bar.close()
            _UpperCamelCase       =	None





       def snake_case__						(							self       :		Optional[int]	,			lowerCAmelCase__       :		Union[str, Any]	,			lowerCAmelCase__       :		Any	,			lowerCAmelCase__       :		Optional[Any]	,			lowerCAmelCase__       :		Optional[int]=None	,			**lowerCAmelCase__       :		Optional[int]					)   ->					Tuple:

            '''simple docstring'''




            if args.evaluation_strategy == IntervalStrategy.NO and "loss" in logs:
                 _UpperCamelCase       =	{'''Training Loss''': logs['''loss''']}
                 # First column is necessarily Step sine we're not in epoch eval strategy
                 _UpperCamelCase       =	state.global_step
                 self.training_tracker.write_line(lowerCAmelCase__					)





       def snake_case__						(							self       :		Optional[Any]	,			lowerCAmelCase__       :		Dict	,			lowerCAmelCase__       :		Any	,			lowerCAmelCase__       :		Optional[int]	,			lowerCAmelCase__       :		List[Any]=None	,			**lowerCAmelCase__       :		List[str]					)   ->					List[str]:

            '''simple docstring'''




            if self.training_tracker is not None:
                 _UpperCamelCase       =	{'''Training Loss''': '''No log''', '''Validation Loss''': '''No log'''}
                 for log in reversed(state.log_history					):
                      if "loss" in log:
                           _UpperCamelCase       =	log['''loss''']
                           break

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







       def snake_case__						(							self       :		int	,			lowerCAmelCase__       :		Dict	,			lowerCAmelCase__       :		Any	,			lowerCAmelCase__       :		Any	,			**lowerCAmelCase__       :		List[str]					)   ->					Optional[Any]:

            '''simple docstring'''




            self.training_tracker.update(
                state.global_step	,			comment=f"""Epoch {int(state.epoch					)}/{state.num_train_epochs}"""	,			force_update=lowerCAmelCase__					)
            _UpperCamelCase       =	None



