class_docstr: Tasks store dictionaries and provide helpers for loading/iterating over
  Datasets, initializing the Model/Criterion and calculating the loss.
  
  Tasks have limited statefulness. In particular, state that needs to be
  saved to/loaded from checkpoints needs to be stored in the `self.state`
  :class:`StatefulContainer` object. For example::
  
      self.state.add_factory("dictionary", self.load_dictionary)
      print(self.state.dictionary)  # calls self.load_dictionary()
  
  This is necessary so that when loading checkpoints, we can properly
  recreate the task state after initializing the task instance.
class_docstr_tok: ["Tasks","store","dictionaries","and","provide","helpers","for","loading\/iterating","over","Datasets",",","initializing","the","Model\/Criterion","and","calculating","the","loss",".","Tasks","have","limited","statefulness",".","In","particular",",","state","that","needs","to","be","saved","to\/loaded","from","checkpoints","needs","to","be","stored","in","the","`","self.state","`",":","class",":","`","StatefulContainer","`","object",".","For","example",":",":","self.state.add_factory","(","``","dictionary","''",",","self.load_dictionary",")","print","(","self.state.dictionary",")","#","calls","self.load_dictionary","(",")","This","is","necessary","so","that","when","loading","checkpoints",",","we","can","properly","recreate","the","task","state","after","initializing","the","task","instance","."]
docstr: Do forward and backward, and return the loss as computed by *criterion*
  for the given *model* and *sample*.
  
  Args:
      sample (dict): the mini-batch. The format is defined by the
          :class:`~fairseq.data.FairseqDataset`.
      model (~fairseq.models.BaseFairseqModel): the model
      criterion (~fairseq.criterions.FairseqCriterion): the criterion
      optimizer (~fairseq.optim.FairseqOptimizer): the optimizer
      update_num (int): the current update
      ignore_grad (bool): multiply loss by 0 if this is set to True
  
  Returns:
      tuple:
          - the loss
          - the sample size, which is used as the denominator for the
            gradient
          - logging outputs to display while training
code: def train_step(
      self,
      sample,
      model,
      criterion,
      optimizer,
      update_num,
      ignore_grad=False,
  ):
      """
      Do forward and backward, and return the loss as computed by *criterion*
      for the given *model* and *sample*.
  
      Args:
          sample (dict): the mini-batch. The format is defined by the
              :class:`~fairseq.data.FairseqDataset`.
          model (~fairseq.models.BaseFairseqModel): the model
          criterion (~fairseq.criterions.FairseqCriterion): the criterion
          optimizer (~fairseq.optim.FairseqOptimizer): the optimizer
          update_num (int): the current update
          ignore_grad (bool): multiply loss by 0 if this is set to True
  
      Returns:
          tuple:
              - the loss
              - the sample size, which is used as the denominator for the
                gradient
              - logging outputs to display while training
      """
      model.train()
      model.set_num_updates(update_num)
      with torch.autograd.profiler.record_function("forward"):
          with torch.cuda.amp.autocast(
              enabled=(isinstance(optimizer, AMPOptimizer))
          ):
              loss, sample_size, logging_output = criterion(
                  model, sample
              )
      if ignore_grad:
          loss *= 0
      with torch.autograd.profiler.record_function("backward"):
          optimizer.backward(loss)
      return loss, sample_size, logging_output
  
imports: import logging
  import os
  import warnings
  from argparse import Namespace
  from typing import Any, Callable, Dict, List
  import torch
  from fairseq import search, tokenizer, utils
  from fairseq.logging import metrics
  from fairseq.data import Dictionary, FairseqDataset, data_utils, encoders, iterators
  from fairseq.dataclass import FairseqDataclass
  from fairseq.dataclass.utils import gen_parser_from_dataclass
  from fairseq.optim.amp_optimizer import AMPOptimizer
  from omegaconf import DictConfig
label_desc: Use image node_id 16 for calling the FairseqTask obj's underlying member method code with example usage: obj.train_step(sample, model, criterion, optimizer, update_num, ignore_grad) and returns: loss,  sample_size,  logging_output