class_docstr: Single training iteration loop of the model.
  
  Performs: data read, forward, loss computation, backward, optimizer step, parameter updates.
  
  Various intermediate steps are also performed:
  - logging the training loss, training eta, LR, etc to loggers
  - logging to tensorboard,
  - performing any self-supervised method specific operations (like in MoCo approach, the
  momentum encoder is updated), computing the scores in swav
  - checkpointing model if user wants to checkpoint in the middle
  of an epoch
code: def __call__(self, task: ClassyTask):
      assert isinstance(
          task, ClassyTask
      ), "task is not instance of ClassyTask"
  
      # reset the last batch info at every step
      task.last_batch = LastBatchInfo()
  
      # We will time the training step and some of its sections, and accumulate values
      # into perf_stats if it were defined in local_variables:
      timer_train_step = PerfTimer("train_step_total", task.perf_stats)
      timer_train_step.start()
  
      # Create the next sample to process
      sample = self.construct_sample_for_model(task)
  
      # Only need gradients during training
      grad_context = (
          torch.enable_grad() if task.train else torch.no_grad()
      )
      ddp_context = self.create_ddp_context(task)
      torch_amp_context = self.create_amp_context(task)
  
      with grad_context, ddp_context, torch_amp_context:
          # Forward pass of the model
          with PerfTimer("forward", task.perf_stats), record_function(
              "forward"
          ):
              if task.enable_manual_gradient_reduction:
                  # Manually sync params and buffers for DDP.
                  manual_sync_params(task.model)
              model_output = task.model(sample["input"])
  
          # If the model outputs only one tensor, we take it out of the list.
          if len(model_output) == 1:
              model_output = model_output[0]
  
          task.last_batch.sample = sample
          task.last_batch.model_output = model_output
          target = sample["target"]
  
          # Run hooks on forward pass
          task.run_hooks(SSLClassyHookFunctions.on_forward.name)
  
          # Compute loss
          with PerfTimer(
              "loss_compute", task.perf_stats
          ), record_function("loss_compute"):
              local_loss = self.compute_loss(task, model_output, target)
  
          # Reduce the loss value across all nodes and gpus.
          with PerfTimer("loss_all_reduce", task.perf_stats):
              loss = local_loss.detach().clone()
              task.last_batch.loss = all_reduce_mean(loss)
          task.losses.append(
              task.last_batch.loss.data.cpu().item() * target.size(0)
          )
  
          # Update the meters
          self.update_meters(task, model_output, target)
  
          task.last_batch.model_output = model_output
          task.last_batch.target = target
  
          # Update the iteration number, check loss is not NaN and measure batch time
          # now if it's a test phase since test phase doesn't have update step.
          task.run_hooks(SSLClassyHookFunctions.on_loss_and_meter.name)
  
      # Run backward now and update the optimizer
      if task.train:
          with PerfTimer("backward", task.perf_stats), record_function(
              "backward"
          ):
              self.run_backward(task, local_loss)
          task.run_hooks(SSLClassyHookFunctions.on_backward.name)
          with PerfTimer(
              "optimizer_step", task.perf_stats
          ), record_function("optimizer_step"):
              self.run_optimizer_step(task)
  
          task.run_hooks(SSLClassyHookFunctions.on_update.name)
          task.num_updates += task.get_global_batchsize()
  
      timer_train_step.stop()
      timer_train_step.record()
      return task
  
imports: import contextlib
  from types import SimpleNamespace
  from typing import Any, Dict
  import torch
  from classy_vision.generic.distributed_util import all_reduce_mean
  from classy_vision.tasks import ClassyTask
  from classy_vision.tasks.classification_task import AmpType
  from vissl.hooks import SSLClassyHookFunctions
  from vissl.trainer.train_steps import register_train_step
  from vissl.utils.activation_checkpointing import manual_gradient_all_reduce, manual_sync_params
  from vissl.utils.fsdp_utils import is_fsdp_model
  from vissl.utils.misc import is_apex_available, torch_version
  from vissl.utils.perf_stats import PerfTimer
  from vissl.utils.profiler import record_function
label_desc: Use image node_id 1 for calling the StandardTrainStep obj's underlying member method code with example usage: obj.__call__(task) and returns: task