code: def forward(self, sample_list):
      module_output = self.bert(sample_list)
      sequence_output, pooled_output = (
          module_output[0],
          module_output[1],
      )
      prediction_scores, seq_relationship_score = self.cls(
          sequence_output, pooled_output
      )
  
      output = {}
      if (
          self.encoder_config.output_hidden_states
          or self.encoder_config.output_attentions
      ):
          output["extras"] = module_output[2:]
  
      loss_key = (
          f"{sample_list.dataset_name}/{sample_list.dataset_type}"
      )
  
      if (
          "lm_label_ids" in sample_list
          and sample_list.lm_label_ids is not None
      ):
          output["logits"] = prediction_scores
          lm_label_ids = sample_list.lm_label_ids
          # Only take last scores which are text's scores and ignore image scores
          text_scores = (
              prediction_scores[:, -(lm_label_ids.size(1)) :]
              .contiguous()
              .view(-1, self.encoder_config.vocab_size)
          )
          masked_lm_loss = self.loss_fct(
              text_scores,
              sample_list.lm_label_ids.contiguous().view(-1),
          )
          output["losses"] = {}
          output["losses"][
              f"{loss_key}/masked_lm_loss"
          ] = masked_lm_loss
  
      # Add alignment loss if present
      if (
          "image_text_alignment" in sample_list
          and sample_list.image_text_alignment is not None
      ):
          output["seq_relationship_logits"] = seq_relationship_score
          alignment_loss = self.loss_fct(
              seq_relationship_score.contiguous().view(-1),
              sample_list.image_text_alignment.contiguous().view(-1),
          )
          output["losses"][
              f"{loss_key}/alignment_loss"
          ] = alignment_loss
  
      return output
  
imports: import os
  from copy import deepcopy
  from dataclasses import dataclass
  from typing import Dict, Optional, Union
  import torch
  from mmf.common.registry import registry
  from mmf.models.base_model import BaseModel
  from mmf.models.interfaces.mmbt import MMBTGridHMInterface
  from mmf.modules.encoders import EncoderFactory, ImageEncoderFactory, ImageEncoderTypes, MultiModalEncoderBase, ResNet152ImageEncoder, TextEncoderFactory, TextEncoderTypes, TransformerEncoder
  from mmf.modules.hf_layers import replace_with_jit
  from mmf.utils.checkpoint import load_pretrained_model
  from mmf.utils.configuration import get_mmf_cache_dir
  from mmf.utils.modeling import get_optimizer_parameters_for_bert
  from omegaconf import DictConfig, II, OmegaConf
  from torch import nn, Tensor
label_desc: Use image node_id 3 for calling the MMBTForPreTraining obj's underlying member method code with example usage: obj.forward(sample_list) and returns: output