


"""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_   (   _lowerCAmelCase     :					Optional[Any]       ):






     """simple docstring"""

     _a    	=				int(_lowerCAmelCase       )
     _a	,      _a	,      _a    	=				t // 36_00, (t // 60) % 60, t % 60
     return f'{h}:{m:02d}:{s:02d}' if h != 0 else f'{m:02d}:{s:02d}'
def       A_   (   _lowerCAmelCase     :					List[Any],     _lowerCAmelCase     :					str,     _lowerCAmelCase     :					Any,     _lowerCAmelCase     :					Union[str, Any],     _lowerCAmelCase     :					List[str]=3_00       ):






     """simple docstring"""

     return f'\n    <div>\n      {prefix}\n      <progress value=\'{value}\' max=\'{total}\' style=\'width:{width}px; height:20px; vertical-align: middle;\'></progress>\n      {label}\n    </div>\n    '
def       A_   (   _lowerCAmelCase     :					Optional[int]       ):






     """simple docstring"""

     _a    	=				'''<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    	=				f'{elt:.6f}' if isinstance(_lowerCAmelCase,     _lowerCAmelCase       ) else str(_lowerCAmelCase       )
               html_code += f'      <td>{elt}</td>\n'
          html_code += "    </tr>\n"
     html_code += "  </tbody>\n</table><p>"
     return html_code


class     __lowerCamelCase  :

     '''simple docstring'''
     A_       :	List[str]    =		5
     A_       :	Any    =		0.2


     def __init__(      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = True    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = 300    ,				)       ->							Dict:
          _a    	=				total
          _a    	=				'''''' if prefix is None else prefix
          _a    	=				leave
          _a    	=				parent
          _a    	=				width
          _a    	=				None
          _a    	=				None
          _a    	=				None


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase = False    ,				__UpperCAmelCase = None							)       ->							List[str]:
          _a    	=				value
          if comment is not None:
               _a    	=				comment
          if self.last_value is None:
               _a    	=				_a    	=				time.time()
               _a    	=				_a    	=				value
               _a    	=				_a    	=				None
               _a    	=				self.warmup
               _a    	=				1
               self.update_bar(__UpperCAmelCase							)
          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    	=				time.time()
               _a    	=				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    	=				self.elapsed_time / (value - self.start_value)
               else:
                    _a    	=				None
               if value >= self.total:
                    _a    	=				self.total
                    _a    	=				None
                    if not self.leave:
                         self.close()
               elif self.average_time_per_item is not None:
                    _a    	=				self.average_time_per_item * (self.total - value)
               self.update_bar(__UpperCAmelCase							)
               _a    	=				value
               _a    	=				current_time
               if self.average_time_per_item is None:
                    _a    	=				1
               else:
                    _a    	=				max(int(self.update_every / self.average_time_per_item							)    ,				1							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase=None							)       ->							Optional[Any]:
          _a    	=				''' ''' * (len(str(self.total							)							) - len(str(__UpperCAmelCase							)							)) + str(__UpperCAmelCase							)
          if self.elapsed_time is None:
               _a    	=				F'[{spaced_value}/{self.total} : < :'
          elif self.predicted_remaining is None:
               _a    	=				F'[{spaced_value}/{self.total} {format_time(self.elapsed_time							)}'
          else:
               _a    	=				(
                   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 							_UpperCAmelCase      (      self							)       ->							Any:
          _a    	=				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    	=				disp.display(disp.HTML(self.html_code							)    ,				display_id=__UpperCAmelCase							)
          else:
               self.output.update(disp.HTML(self.html_code							)							)





     def 							_UpperCAmelCase      (      self							)       ->							str:
          if self.parent is None and self.output is not None:
               self.output.update(disp.HTML(''''''							)							)







class     __lowerCamelCase  (					a__				):

     '''simple docstring'''


     def __init__(      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase=None							)       ->							int:
          super().__init__(__UpperCAmelCase							)
          _a    	=				None if column_names is None else [column_names]
          _a    	=				None


     def 							_UpperCAmelCase      (      self							)       ->							Tuple:
          _a    	=				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    	=				disp.display(disp.HTML(self.html_code							)    ,				display_id=__UpperCAmelCase							)
          else:
               self.output.update(disp.HTML(self.html_code							)							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase							)       ->							Union[str, Any]:
          if self.inner_table is None:
               _a    	=				[list(values.keys()							), list(values.values()							)]
          else:
               _a    	=				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(__UpperCAmelCase							)
                    _a    	=				columns
               self.inner_table.append([values[c] for c in columns]							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase=None    ,				__UpperCAmelCase=300							)       ->							Optional[int]:
          _a    	=				NotebookProgressBar(__UpperCAmelCase    ,				prefix=__UpperCAmelCase    ,				parent=self    ,				width=__UpperCAmelCase							)
          return self.child_bar





     def 							_UpperCAmelCase      (      self							)       ->							List[Any]:
          _a    	=				None
          self.display()







class     __lowerCamelCase  (					a__				):

     '''simple docstring'''


     def __init__(      self							)       ->							Tuple:
          _a    	=				None
          _a    	=				None
          _a    	=				False


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				**__UpperCAmelCase							)       ->							int:
          _a    	=				'''Epoch''' if args.evaluation_strategy == IntervalStrategy.EPOCH else '''Step'''
          _a    	=				0
          _a    	=				0
          _a    	=				[self.first_column] + ['''Training Loss''']
          if args.evaluation_strategy != IntervalStrategy.NO:
               column_names.append('''Validation Loss'''							)
          _a    	=				NotebookTrainingTracker(state.max_steps    ,				__UpperCAmelCase							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				**__UpperCAmelCase							)       ->							int:
          _a    	=				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    	=				False


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase=None    ,				**__UpperCAmelCase							)       ->							List[Any]:
          if not has_length(__UpperCAmelCase							):
               return
          if self.prediction_bar is None:
               if self.training_tracker is not None:
                    _a    	=				self.training_tracker.add_child(len(__UpperCAmelCase							)							)
               else:
                    _a    	=				NotebookProgressBar(len(__UpperCAmelCase							)							)
               self.prediction_bar.update(1							)
          else:
               self.prediction_bar.update(self.prediction_bar.value + 1							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				**__UpperCAmelCase							)       ->							List[Any]:
          if self.prediction_bar is not None:
               self.prediction_bar.close()
          _a    	=				None


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


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase=None    ,				**__UpperCAmelCase							)       ->							int:
          if self.training_tracker is not None:
               _a    	=				{'''Training Loss''': '''No log''', '''Validation Loss''': '''No log'''}
               for log in reversed(state.log_history							):
                    if "loss" in log:
                         _a    	=				log['''loss''']
                         break

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





     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				__UpperCAmelCase    ,				**__UpperCAmelCase							)       ->							List[str]:
          self.training_tracker.update(
              state.global_step    ,				comment=F'Epoch {int(state.epoch							)}/{state.num_train_epochs}'    ,				force_update=__UpperCAmelCase							)
          _a    	=				None



"""simple docstring"""






def       A_   (   _lowerCAmelCase     :					int = 10**12       ):






     """simple docstring"""

     _a    	=				1
     _a    	=				0

     _a    	=				1
     _a    	=				1

     while numerator <= 2 * min_total - 1:
          prev_numerator += 2 * numerator
          numerator += 2 * prev_numerator

          prev_denominator += 2 * denominator
          denominator += 2 * prev_denominator

     return (denominator + 1) // 2


if __name__ == "__main__":
   print(f'{solution() = }')