code: def extract_modal_end_token(self, sample_list: Dict[str, Tensor]):
      # compute the position of the last non-masked token, which is <sep>
      gather_index = sample_list["input_mask"].sum(1, keepdim=True) - 1
      modal_end_token = (
          torch.gather(sample_list["input_ids"], 1, gather_index)
          .squeeze(1)
          .clone()
          .detach()
      )
  
      batch_size = sample_list["input_ids"].size(0)
      device = sample_list["input_ids"].device
      # remove start_token in input_ids
      sample_list["input_ids"] = torch.cat(
          [
              sample_list["input_ids"][:, 1:],
              sample_list["input_ids"][:, -1:],
          ],
          dim=1,
      )
      # update input_mask
      sample_list["input_mask"] = torch.cat(
          [
              sample_list["input_mask"][:, 1:],
              torch.zeros(
                  [batch_size, 1], dtype=torch.long, device=device
              ),
          ],
          dim=1,
      )
  
      return modal_end_token
  
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 MMBTBase obj's underlying member method code with example usage: obj.extract_modal_end_token(sample_list) and returns: modal_end_token