class_docstr: A callback that performs periodic synchronous garbage collection.
  
  In fully-synchronous distributed training, the same program is run
  across multiple processes. These processes need to communicate with each
  other, especially to communicate gradients to update model parameters.
  The overall program execution is therefore gated by the slowest running
  process. As a result, it's important that each process takes roughly the
  same amount of time to execute its code: otherwise we run into straggler
  processes. By default, Python's automatic garbage collection can be triggered at
  different points in each of these processes, creating the possibility of
  straggler processes. This callback makes it convenient to configure
  all processes performing garbage collection at the same time in the loop.
  
  Synchronizing the garbage collection can lead to a performance improvement.
  The frequency of garbage collection must be tuned based on the application at hand.
  
  By default, this callback does **generation 1** collection every step. This can free up
  some objects to be reaped with minimal overhead compared to the full garbage collection.
  
  Args:
      step_interval: number of steps to run before executing a full garbage cleanup
class_docstr_tok: ["A","callback","that","performs","periodic","synchronous","garbage","collection",".","In","fully-synchronous","distributed","training",",","the","same","program","is","run","across","multiple","processes",".","These","processes","need","to","communicate","with","each","other",",","especially","to","communicate","gradients","to","update","model","parameters",".","The","overall","program","execution","is","therefore","gated","by","the","slowest","running","process",".","As","a","result",",","it","'s","important","that","each","process","takes","roughly","the","same","amount","of","time","to","execute","its","code",":","otherwise","we","run","into","straggler","processes",".","By","default",",","Python","'s","automatic","garbage","collection","can","be","triggered","at","different","points","in","each","of","these","processes",",","creating","the","possibility","of","straggler","processes",".","This","callback","makes","it","convenient","to","configure","all","processes","performing","garbage","collection","at","the","same","time","in","the","loop",".","Synchronizing","the","garbage","collection","can","lead","to","a","performance","improvement",".","The","frequency","of","garbage","collection","must","be","tuned","based","on","the","application","at","hand",".","By","default",",","this","callback","does","*","*","generation","1","*","*","collection","every","step",".","This","can","free","up","some","objects","to","be","reaped","with","minimal","overhead","compared","to","the","full","garbage","collection",".","Args",":","step_interval",":","number","of","steps","to","run","before","executing","a","full","garbage","cleanup"]
code: def on_train_step_end(self, state: State, unit: TTrainUnit) -> None:
      gc.collect(generation=1)
  
      total_num_steps_completed = (
          unit.train_progress.num_steps_completed
      )
      if state.entry_point == EntryPoint.FIT:
          # if fitting, include the num eval steps completed in the total steps completed
          none_throws(state.eval_state)
          # if fitting, unit should also subclass EvalUnit
          unit_as_eval_unit = cast(TEvalUnit, unit)
          total_num_steps_completed += (
              unit_as_eval_unit.eval_progress.num_steps_completed
          )
  
      if total_num_steps_completed % self._step_interval == 0:
          gc.collect()
  
      # Ensure that GC is disabled, in case GC was reenabled elsewhere
      gc.disable()
  
file_path: tnt/torchtnt/framework/callbacks/garbage_collector.py
imports: import gc
  from typing import cast
  from pyre_extensions import none_throws
  from torchtnt.framework.callback import Callback
  from torchtnt.framework.state import EntryPoint, State
  from torchtnt.framework.unit import TEvalUnit, TPredictUnit, TTrainUnit
  from torchtnt.utils.progress import Progress
label_desc: Use image node_id 3 for calling the GarbageCollector obj's underlying member method code with example usage: obj.on_train_step_end(state, unit) without return types