class_docstr: Transformer with Masked Language Model
docstr: Training Iteration
docstr_tok: ["Training","Iteration"]
code: def training_step(self, batch, batch_idx):
      """Training Iteration"""
      ## 1. ENCODER-DECODER
      mlm_preds, cls_preds = self(batch)
      ## 2. LOSS
      mlm_targs = batch["target_tokens"].long()
      cls_targs = batch["target_cls"].long()
      mlm_loss = self.mlm_loss(
          mlm_preds.permute(0, 2, 1), target=mlm_targs
      )
      cls_loss = self.cls_loss(cls_preds, target=cls_targs)
  
      self.log(
          "train/loss_mlm",
          mlm_loss.detach(),
          on_step=True,
          on_epoch=True,
      )
      self.log(
          "train/loss_cls",
          cls_loss.detach(),
          on_step=True,
          on_epoch=True,
      )
  
      loss = self.cls_w * cls_loss + self.mlm_w * mlm_loss
      ## 3. METRICS
      if (self.global_step + 1) % (self.trainer.log_every_n_steps) == 0:
          self.log_metrics(
              predictions=(mlm_preds.detach(), cls_preds.detach()),
              targets=(mlm_targs.detach(), cls_targs.detach()),
              loss=loss.detach(),
              stage="train",
              on_step=True,
              on_epoch=True,
          )
      return loss
  
imports: from abc import ABC
  from base64 import decode
  from math import gamma
  import torch
  import torch.nn
  import torch.nn.functional
  import torchmetrics
  import pickle
  import pytorch_lightning
  from pytorch_lightning import seed_everything
  import os
  from pathlib import Path
  import logging
  from src.transformer.transformer_utils import *
  from src.transformer.transformer import Transformer, MaskedLanguageModel, CLS_Decoder
label_desc: Use image node_id 4 for calling the TransformerEncoder obj's underlying member method code with example usage: obj.training_step(batch, batch_idx) and returns: loss