class_docstr: Members:
      eval_only: If True, only run evaluation using the test dataloader.
      max_epochs: Train for this many epochs. Note that if the model was
          loaded from a checkpoint, we will restart training at the appropriate
          epoch and run for (max_epochs - checkpoint_epoch) epochs.
      store_checkpoints: If True, store model and optimizer state checkpoints.
      store_checkpoints_purge: If >= 0, remove any checkpoints older or equal
          to this many epochs.
      test_interval: Evaluate on a test dataloader each `test_interval` epochs.
      test_when_finished: If True, evaluate on a test dataloader when training
          completes.
      validation_interval: Validate each `validation_interval` epochs.
      clip_grad: Optionally clip the gradient norms.
          If set to a value <=0.0, no clipping
      metric_print_interval: The batch interval at which the stats should be
          logged.
      visualize_interval: The batch interval at which the visualizations
          should be plotted
      visdom_env: The name of the Visdom environment to use for plotting.
      visdom_port: The Visdom port.
      visdom_server: Address of the Visdom server.
docstr: Entry point to run the training and validation loops
  based on the specified config file.
docstr_tok: ["Entry","point","to","run","the","training","and","validation","loops","based","on","the","specified","config","file","."]
code: def run(
      self,
      *,
      train_loader: DataLoader,
      val_loader: Optional[DataLoader],
      test_loader: Optional[DataLoader],
      train_dataset: Dataset,
      model: ImplicitronModelBase,
      optimizer: torch.optim.Optimizer,
      scheduler: Any,
      accelerator: Optional[Accelerator],
      device: torch.device,
      exp_dir: str,
      stats: Stats,
      seed: int,
      **kwargs,
  ):
      """
      Entry point to run the training and validation loops
      based on the specified config file.
      """
      start_epoch = stats.epoch + 1
      assert scheduler.last_epoch == stats.epoch + 1
      assert scheduler.last_epoch == start_epoch
  
      # only run evaluation on the test dataloader
      if self.eval_only:
          if test_loader is not None:
              # pyre-fixme[16]: `Optional` has no attribute `run`.
              self.evaluator.run(
                  dataloader=test_loader,
                  device=device,
                  dump_to_json=True,
                  epoch=stats.epoch,
                  exp_dir=exp_dir,
                  model=model,
              )
              return
          else:
              raise ValueError(
                  "Cannot evaluate and dump results to json, no test data provided."
              )
  
      # loop through epochs
      for epoch in range(start_epoch, self.max_epochs):
          # automatic new_epoch and plotting of stats at every epoch start
          with stats:
              # Make sure to re-seed random generators to ensure reproducibility
              # even after restart.
              seed_all_random_engines(seed + epoch)
  
              cur_lr = float(scheduler.get_last_lr()[-1])
              logger.debug(f"scheduler lr = {cur_lr:1.2e}")
  
              # train loop
              self._training_or_validation_epoch(
                  accelerator=accelerator,
                  device=device,
                  epoch=epoch,
                  loader=train_loader,
                  model=model,
                  optimizer=optimizer,
                  stats=stats,
                  validation=False,
              )
  
              # val loop (optional)
              if (
                  val_loader is not None
                  and epoch % self.validation_interval == 0
              ):
                  self._training_or_validation_epoch(
                      accelerator=accelerator,
                      device=device,
                      epoch=epoch,
                      loader=val_loader,
                      model=model,
                      optimizer=optimizer,
                      stats=stats,
                      validation=True,
                  )
  
              # eval loop (optional)
              if (
                  test_loader is not None
                  and self.test_interval > 0
                  and epoch % self.test_interval == 0
              ):
                  self.evaluator.run(
                      device=device,
                      dataloader=test_loader,
                      model=model,
                  )
  
              assert stats.epoch == epoch, "inconsistent stats!"
              self._checkpoint(
                  accelerator, epoch, exp_dir, model, optimizer, stats
              )
  
              scheduler.step()
              new_lr = float(scheduler.get_last_lr()[-1])
              if new_lr != cur_lr:
                  logger.info(f"LR change! {cur_lr} -> {new_lr}")
  
      if self.test_when_finished:
          if test_loader is not None:
              self.evaluator.run(
                  device=device,
                  dump_to_json=True,
                  epoch=stats.epoch,
                  exp_dir=exp_dir,
                  dataloader=test_loader,
                  model=model,
              )
          else:
              raise ValueError(
                  "Cannot evaluate and dump results to json, no test data provided."
              )
  
imports: import logging
  import os
  import time
  from typing import Any, List, Optional
  import torch
  from accelerate import Accelerator
  from pytorch3d.implicitron.evaluation.evaluator import EvaluatorBase
  from pytorch3d.implicitron.models.base_model import ImplicitronModelBase
  from pytorch3d.implicitron.models.generic_model import EvaluationMode
  from pytorch3d.implicitron.tools import model_io, vis_utils
  from pytorch3d.implicitron.tools.config import registry, ReplaceableBase, run_auto_creation
  from pytorch3d.implicitron.tools.stats import Stats
  from torch.utils.data import DataLoader, Dataset
  from .utils import seed_all_random_engines
label_desc: Use image node_id 2 for calling the ImplicitronTrainingLoop obj's underlying member method code with example usage: obj.run() without return types