docstr: JSON-serializable holder object that stores information related to training progress.
  
  [train/vali/test]_metrics is a nested dictionary of TrainerMetrics: feature_name -> metric_name ->
  List[TrainerMetrics], with one entry per training checkpoint.
  
  When the model is saved, all of the progress tracker's attributes are serialized to JSON as
  `training_progress.json` under the model output directory.
  
  JSON serialization automatically converts all dictionary top-level keys to strings, and the string typing
  is preserved when the progress tracker is deserialized from JSON when model resumes training from a checkpoint.
  
  For this reason, all of the dictionary attributes of the progress tracker are keyed by strings to ensure a
  consistent interface before or after deserialization. For example, the `tokens` dictionaries are keyed by steps,
  as strings.
  
  When the progress tracker is deserialized from JSON like when a model resumes training from a checkpoint, the
  TrainerMetrics namedtuples are automatically converted into regular (epoch, steps, value) tuples, which is why
  in trainer.py, we often use `[-1]` to index into the last element of the TrainerMetric namedtuple to get the
  actual metric value instead of the named field.
  
  Args:
      epoch: The current epoch number.
      steps: The current step of training.
      batch_size: The current batch size.
      tune_checkpoint_num: The hyperopt checkpoint number (Ray Tune).
      checkpoint_number: The current checkpoint number.
  
      best_eval_metric_steps: The step of training that has the best evaluation so far.
      best_eval_metric_epoch: The epoch of training that has the best evaluation so far.
      best_eval_metric_checkpoint_number: The checkpoint number that has the best evaluation so far.
  
      last_improvement_steps: The number of steps since the last improvement.
      last_learning_rate_reduction_steps: The training step of the last learning rate reduction.
      last_increase_batch_size_steps: The training_step of the the last batch size increase.
  
      best_eval_metric_value: The metric value of the best evaluation so far.
      best_increase_batch_size_eval_metric:
          The metric value of the best evaluation so far, for increasing the batch size.
  
      last_learning_rate_reduction: The number of steps since the last learning rate reduction.
      last_increase_batch_size: The number of steps since the last batch size increase.
  
      last_increase_batch_size_eval_metric_improvement:
          The number of checkpoints since the last batch size increase.
  
      num_reductions_learning_rate: The number of total reductions in learning rate.
      num_increases_batch_size: The number of total increases in batch size.
  
      train_metrics: Training metrics. <output feature name> -> <metric name> -> History of metrics.
      validation_metrics: Validation metrics. <output feature name> -> <metric name> -> History of metrics.
      test_metrics: Test metrics. <output feature name> -> <metric name> -> History of metrics.
  
      best_eval_train_metrics:
          Best eval train metrics: <output feature name> -> <metric name> -> <metric value>.
      best_eval_validation_metrics:
          Best eval validation metrics: <output feature name> -> <metric name> -> <metric value>.
      best_eval_test_metrics:
          Best eval test metrics: <output feature name> -> <metric name> -> <metric value>.
  
      llm_eval_examples:
          Dictionary whose keys are "inputs", "targets", and "outputs" and whose values are dicts.
          The keys of each subdict are the names of the input/target/output features and the values are lists of
          example tensors. This is only set for LLM fine-tuning.
  
      checkpoint_to_step: Map of checkpoint number to step number.
      checkpoint_to_epoch: Map of checkpoint number to epoch number.
  
      incremental_step_token_usage: Map of step number to number of tokens used in that step.
      cumulative_step_token_usage: Map of step number to cumulative number of tokens used up to that step.
      incremental_checkpoint_token_usage: Map of checkpoint number to number of tokens used up to that checkpoint
          since the last checkpoint.
      cumulative_checkpoint_token_usage: Map of checkpoint number to cumulative number of tokens used up to that
          checkpoint.
      total_tokens_used: Total number of tokens used.
docstr_tok: ["JSON-serializable","holder","object","that","stores","information","related","to","training","progress",".","[","train\/vali\/test","]","_metrics","is","a","nested","dictionary","of","TrainerMetrics",":","feature_name","-",">","metric_name","-",">","List","[","TrainerMetrics","]",",","with","one","entry","per","training","checkpoint",".","When","the","model","is","saved",",","all","of","the","progress","tracker","'s","attributes","are","serialized","to","JSON","as","`","training_progress.json","`","under","the","model","output","directory",".","JSON","serialization","automatically","converts","all","dictionary","top-level","keys","to","strings",",","and","the","string","typing","is","preserved","when","the","progress","tracker","is","deserialized","from","JSON","when","model","resumes","training","from","a","checkpoint",".","For","this","reason",",","all","of","the","dictionary","attributes","of","the","progress","tracker","are","keyed","by","strings","to","ensure","a","consistent","interface","before","or","after","deserialization",".","For","example",",","the","`","tokens","`","dictionaries","are","keyed","by","steps",",","as","strings",".","When","the","progress","tracker","is","deserialized","from","JSON","like","when","a","model","resumes","training","from","a","checkpoint",",","the","TrainerMetrics","namedtuples","are","automatically","converted","into","regular","(","epoch",",","steps",",","value",")","tuples",",","which","is","why","in","trainer.py",",","we","often","use","`","[","-1","]","`","to","index","into","the","last","element","of","the","TrainerMetric","namedtuple","to","get","the","actual","metric","value","instead","of","the","named","field",".","Args",":","epoch",":","The","current","epoch","number",".","steps",":","The","current","step","of","training",".","batch_size",":","The","current","batch","size",".","tune_checkpoint_num",":","The","hyperopt","checkpoint","number","(","Ray","Tune",")",".","checkpoint_number",":","The","current","checkpoint","number",".","best_eval_metric_steps",":","The","step","of","training","that","has","the","best","evaluation","so","far",".","best_eval_metric_epoch",":","The","epoch","of","training","that","has","the","best","evaluation","so","far",".","best_eval_metric_checkpoint_number",":","The","checkpoint","number","that","has","the","best","evaluation","so","far",".","last_improvement_steps",":","The","number","of","steps","since","the","last","improvement",".","last_learning_rate_reduction_steps",":","The","training","step","of","the","last","learning","rate","reduction",".","last_increase_batch_size_steps",":","The","training_step","of","the","the","last","batch","size","increase",".","best_eval_metric_value",":","The","metric","value","of","the","best","evaluation","so","far",".","best_increase_batch_size_eval_metric",":","The","metric","value","of","the","best","evaluation","so","far",",","for","increasing","the","batch","size",".","last_learning_rate_reduction",":","The","number","of","steps","since","the","last","learning","rate","reduction",".","last_increase_batch_size",":","The","number","of","steps","since","the","last","batch","size","increase",".","last_increase_batch_size_eval_metric_improvement",":","The","number","of","checkpoints","since","the","last","batch","size","increase",".","num_reductions_learning_rate",":","The","number","of","total","reductions","in","learning","rate",".","num_increases_batch_size",":","The","number","of","total","increases","in","batch","size",".","train_metrics",":","Training","metrics",".","<","output","feature","name",">","-",">","<","metric","name",">","-",">","History","of","metrics",".","validation_metrics",":","Validation","metrics",".","<","output","feature","name",">","-",">","<","metric","name",">","-",">","History","of","metrics",".","test_metrics",":","Test","metrics",".","<","output","feature","name",">","-",">","<","metric","name",">","-",">","History","of","metrics",".","best_eval_train_metrics",":","Best","eval","train","metrics",":","<","output","feature","name",">","-",">","<","metric","name",">","-",">","<","metric","value",">",".","best_eval_validation_metrics",":","Best","eval","validation","metrics",":","<","output","feature","name",">","-",">","<","metric","name",">","-",">","<","metric","value",">",".","best_eval_test_metrics",":","Best","eval","test","metrics",":","<","output","feature","name",">","-",">","<","metric","name",">","-",">","<","metric","value",">",".","llm_eval_examples",":","Dictionary","whose","keys","are","``","inputs","''",",","``","targets","''",",","and","``","outputs","''","and","whose","values","are","dicts",".","The","keys","of","each","subdict","are","the","names","of","the","input\/target\/output","features","and","the","values","are","lists","of","example","tensors",".","This","is","only","set","for","LLM","fine-tuning",".","checkpoint_to_step",":","Map","of","checkpoint","number","to","step","number",".","checkpoint_to_epoch",":","Map","of","checkpoint","number","to","epoch","number",".","incremental_step_token_usage",":","Map","of","step","number","to","number","of","tokens","used","in","that","step",".","cumulative_step_token_usage",":","Map","of","step","number","to","cumulative","number","of","tokens","used","up","to","that","step",".","incremental_checkpoint_token_usage",":","Map","of","checkpoint","number","to","number","of","tokens","used","up","to","that","checkpoint","since","the","last","checkpoint",".","cumulative_checkpoint_token_usage",":","Map","of","checkpoint","number","to","cumulative","number","of","tokens","used","up","to","that","checkpoint",".","total_tokens_used",":","Total","number","of","tokens","used","."]
code: def __init__(
      self,
      epoch: int,
      batch_size: int,
      steps: int,
      tune_checkpoint_num: int,
      checkpoint_number: int,
      best_eval_metric_steps: int,
      best_eval_metric_epoch: int,
      best_eval_metric_checkpoint_number: int,
      last_improvement_steps: int,
      last_learning_rate_reduction_steps: int,
      last_increase_batch_size_steps: int,
      best_eval_metric_value: float,
      best_increase_batch_size_eval_metric: float,
      last_increase_batch_size_eval_metric_improvement: int,
      learning_rate: float,
      num_reductions_learning_rate: int,
      num_increases_batch_size: int,
      train_metrics: Dict[str, Dict[str, List[TrainerMetric]]],
      validation_metrics: Dict[str, Dict[str, List[TrainerMetric]]],
      test_metrics: Dict[str, Dict[str, List[TrainerMetric]]],
      last_learning_rate_reduction: int,
      last_increase_batch_size: int,
      best_eval_train_metrics: Dict[str, Dict[str, float]],
      best_eval_validation_metrics: Dict[str, Dict[str, float]],
      best_eval_test_metrics: Dict[str, Dict[str, float]],
      llm_eval_examples: Dict[str, List[str]] = None,
      checkpoint_to_step: Dict[str, int] = None,
      checkpoint_to_epoch: Dict[str, int] = None,
      incremental_step_token_usage: Dict[str, int] = None,
      cumulative_step_token_usage: Dict[str, int] = None,
      incremental_checkpoint_token_usage: Dict[str, int] = None,
      cumulative_checkpoint_token_usage: Dict[str, int] = None,
      total_tokens_used: int = 0,
  ):
      """JSON-serializable holder object that stores information related to training progress.
  
      [train/vali/test]_metrics is a nested dictionary of TrainerMetrics: feature_name -> metric_name ->
      List[TrainerMetrics], with one entry per training checkpoint.
  
      When the model is saved, all of the progress tracker's attributes are serialized to JSON as
      `training_progress.json` under the model output directory.
  
      JSON serialization automatically converts all dictionary top-level keys to strings, and the string typing
      is preserved when the progress tracker is deserialized from JSON when model resumes training from a checkpoint.
  
      For this reason, all of the dictionary attributes of the progress tracker are keyed by strings to ensure a
      consistent interface before or after deserialization. For example, the `tokens` dictionaries are keyed by steps,
      as strings.
  
      When the progress tracker is deserialized from JSON like when a model resumes training from a checkpoint, the
      TrainerMetrics namedtuples are automatically converted into regular (epoch, steps, value) tuples, which is why
      in trainer.py, we often use `[-1]` to index into the last element of the TrainerMetric namedtuple to get the
      actual metric value instead of the named field.
  
      Args:
          epoch: The current epoch number.
          steps: The current step of training.
          batch_size: The current batch size.
          tune_checkpoint_num: The hyperopt checkpoint number (Ray Tune).
          checkpoint_number: The current checkpoint number.
  
          best_eval_metric_steps: The step of training that has the best evaluation so far.
          best_eval_metric_epoch: The epoch of training that has the best evaluation so far.
          best_eval_metric_checkpoint_number: The checkpoint number that has the best evaluation so far.
  
          last_improvement_steps: The number of steps since the last improvement.
          last_learning_rate_reduction_steps: The training step of the last learning rate reduction.
          last_increase_batch_size_steps: The training_step of the the last batch size increase.
  
          best_eval_metric_value: The metric value of the best evaluation so far.
          best_increase_batch_size_eval_metric:
              The metric value of the best evaluation so far, for increasing the batch size.
  
          last_learning_rate_reduction: The number of steps since the last learning rate reduction.
          last_increase_batch_size: The number of steps since the last batch size increase.
  
          last_increase_batch_size_eval_metric_improvement:
              The number of checkpoints since the last batch size increase.
  
          num_reductions_learning_rate: The number of total reductions in learning rate.
          num_increases_batch_size: The number of total increases in batch size.
  
          train_metrics: Training metrics. <output feature name> -> <metric name> -> History of metrics.
          validation_metrics: Validation metrics. <output feature name> -> <metric name> -> History of metrics.
          test_metrics: Test metrics. <output feature name> -> <metric name> -> History of metrics.
  
          best_eval_train_metrics:
              Best eval train metrics: <output feature name> -> <metric name> -> <metric value>.
          best_eval_validation_metrics:
              Best eval validation metrics: <output feature name> -> <metric name> -> <metric value>.
          best_eval_test_metrics:
              Best eval test metrics: <output feature name> -> <metric name> -> <metric value>.
  
          llm_eval_examples:
              Dictionary whose keys are "inputs", "targets", and "outputs" and whose values are dicts.
              The keys of each subdict are the names of the input/target/output features and the values are lists of
              example tensors. This is only set for LLM fine-tuning.
  
          checkpoint_to_step: Map of checkpoint number to step number.
          checkpoint_to_epoch: Map of checkpoint number to epoch number.
  
          incremental_step_token_usage: Map of step number to number of tokens used in that step.
          cumulative_step_token_usage: Map of step number to cumulative number of tokens used up to that step.
          incremental_checkpoint_token_usage: Map of checkpoint number to number of tokens used up to that checkpoint
              since the last checkpoint.
          cumulative_checkpoint_token_usage: Map of checkpoint number to cumulative number of tokens used up to that
              checkpoint.
          total_tokens_used: Total number of tokens used.
      """
      self.batch_size = batch_size
      self.epoch = epoch
      self.steps = steps
      self.tune_checkpoint_num = tune_checkpoint_num
      self.checkpoint_number = checkpoint_number
      self.best_eval_metric_steps = best_eval_metric_steps
      self.best_eval_metric_epoch = best_eval_metric_epoch
      self.best_eval_metric_checkpoint_number = (
          best_eval_metric_checkpoint_number
      )
      self.last_improvement_steps = last_improvement_steps
      self.last_learning_rate_reduction_steps = (
          last_learning_rate_reduction_steps
      )
      self.last_learning_rate_reduction = last_learning_rate_reduction
      self.last_increase_batch_size_steps = (
          last_increase_batch_size_steps
      )
      self.last_increase_batch_size = last_increase_batch_size
      self.learning_rate = learning_rate
      self.best_eval_metric_value = best_eval_metric_value
      self.best_increase_batch_size_eval_metric = (
          best_increase_batch_size_eval_metric
      )
      self.last_increase_batch_size_eval_metric_improvement = (
          last_increase_batch_size_eval_metric_improvement
      )
      self.num_reductions_learning_rate = num_reductions_learning_rate
      self.num_increases_batch_size = num_increases_batch_size
      self.train_metrics = train_metrics
      self.validation_metrics = validation_metrics
      self.test_metrics = test_metrics
  
      # This should be an dictionary whose keys are "inputs", "targets", and "outputs" and whose values are dicts.
      # The keys of each subdict are the names of the input/target/output features and the values are lists of
      # example tensors. This is only set for LLM fine-tuning.
      self.llm_eval_examples = llm_eval_examples
  
      # Best metrics.
      self.best_eval_train_metrics = best_eval_train_metrics
      self.best_eval_validation_metrics = best_eval_validation_metrics
      self.best_eval_test_metrics = best_eval_test_metrics
  
      # Checkpoint tracking.
      self.checkpoint_to_step = checkpoint_to_step
      self.checkpoint_to_epoch = checkpoint_to_epoch
  
      # Token usage.
      self.incremental_step_token_usage = incremental_step_token_usage
      self.cumulative_step_token_usage = cumulative_step_token_usage
      self.incremental_checkpoint_token_usage = (
          incremental_checkpoint_token_usage
      )
      self.cumulative_checkpoint_token_usage = (
          cumulative_checkpoint_token_usage
      )
      self.total_tokens_used = total_tokens_used
  
imports: import logging
  from collections import defaultdict
  from typing import Dict, List, Tuple, TYPE_CHECKING
  from ludwig.api_annotations import DeveloperAPI
  from ludwig.constants import AUTO, COMBINED, LOSS
  from ludwig.models.base import BaseModel
  from ludwig.modules.metric_modules import get_best_function
  from ludwig.utils.data_utils import save_json
  from ludwig.utils.metric_utils import TrainerMetric
label_desc: Use image node_id 1 to create a new ProgressTracker object  with example: obj = ProgressTracker(epoch, batch_size, steps, tune_checkpoint_num, checkpoint_number, best_eval_metric_steps, best_eval_metric_epoch, best_eval_metric_checkpoint_number, last_improvement_steps, last_learning_rate_reduction_steps, last_increase_batch_size_steps, best_eval_metric_value, best_increase_batch_size_eval_metric, last_increase_batch_size_eval_metric_improvement, learning_rate, num_reductions_learning_rate, num_increases_batch_size, train_metrics, validation_metrics, test_metrics, last_learning_rate_reduction, last_increase_batch_size, best_eval_train_metrics, best_eval_validation_metrics, best_eval_test_metrics, llm_eval_examples, checkpoint_to_step, checkpoint_to_epoch, incremental_step_token_usage, cumulative_step_token_usage, incremental_checkpoint_token_usage, cumulative_checkpoint_token_usage, total_tokens_used)