code: def shared_step(self, batch: Any, batch_idx: int, phase="train"):
      is_train = phase == "train"
      loss, output, targets = self.step(batch, is_train=is_train)
      with torch.no_grad():
          metrics_mlm = getattr(self, f"{phase}_metrics").acc_mlm(
              output["mlm"], targets["mlm"]
          )
          metrics_nsp = getattr(self, f"{phase}_metrics").acc_nsp(
              output["nsp"], targets["nsp"]
          )
          metrics = {
              f"{phase}/acc_mlm": metrics_mlm,
              f"{phase}/acc_nsp": metrics_nsp,
          }
      if is_train:
          # We log every step since the dataset is manually duplicated, making "epoch" meaningless
          self.log(
              f"{phase}/loss",
              loss,
              on_step=True,
              on_epoch=False,
              prog_bar=False,
              sync_dist=True,
          )
          self.log_dict(
              metrics,
              on_step=True,
              on_epoch=False,
              prog_bar=True,
              sync_dist=True,
          )
      else:
          self.log(
              f"{phase}/loss",
              loss,
              on_step=False,
              on_epoch=True,
              prog_bar=False,
              sync_dist=True,
          )
          self.log_dict(
              metrics,
              on_step=False,
              on_epoch=True,
              prog_bar=True,
              sync_dist=True,
          )
      return {"loss": loss, "output": output, "targets": targets}
  
imports: from typing import Any, List
  import inspect
  import torch
  import hydra
  from pytorch_lightning import LightningModule, LightningDataModule
  from torchmetrics import MetricCollection
  from einops import rearrange
  from omegaconf import OmegaConf
  from src.utils.utils import get_logger
  from src.optim.param_grouping import group_parameters_for_optimizer
  from src.utils.checkpoint import load_checkpoint
  import datasets
label_desc: Use image node_id 3 for calling the BERTModel obj's underlying member method code with example usage: obj.shared_step(batch, batch_idx, phase) and returns: dict