code: def build_lightning_model(
      config: Union[
          DictConfig, "mmf.models.base_model.BaseModel.Config"
      ],
      checkpoint_path: str = None,
  ) -> "mmf.models.base_model.BaseModel":
      from mmf.models.base_model import BaseModel
  
      if not checkpoint_path:
          model = build_model(config)
          model.is_pl_enabled = True
          return model
  
      # If it is not an OmegaConf object, create the object
      if not isinstance(config, DictConfig) and isinstance(
          config, BaseModel.Config
      ):
          config = OmegaConf.structured(config)
  
      model_name = config.model
      model_class = registry.get_model_class(model_name)
  
      if model_class is None:
          raise RuntimeError(
              f"No model registered for name: {model_name}"
          )
  
      """ model.build is called inside on_load_checkpoint as suggested here:
      https://github.com/PyTorchLightning/pytorch-lightning/issues/5410
      """
  
      if is_main():
          model_class.load_requirements(model_class, config=config)
          model = model_class.load_from_checkpoint(
              checkpoint_path, config=config, strict=False
          )
          synchronize()
      else:
          synchronize()
          model = model_class.load_from_checkpoint(
              checkpoint_path, config=config, strict=False
          )
  
      model.init_losses()
      model.is_pl_enabled = True
      return model
  
imports: import logging
  import os
  import warnings
  from enum import Enum
  from typing import Any, Dict, List, Optional, Tuple, Union
  import mmf
  import pytorch_lightning
  import torch
  from mmf.common.meter import Meter
  from mmf.common.registry import registry
  from mmf.datasets.iteration_strategies import ConstantIterationStrategy, IterationStrategy, SizeProportionalIterationStrategy
  from mmf.datasets.processors.processors import Processor
  from mmf.utils.configuration import Configuration, get_global_config
  from mmf.utils.distributed import is_dist_initialized, is_main, is_xla, synchronize
  from mmf.utils.general import get_optimizer_parameters
  from omegaconf import DictConfig, OmegaConf
  from packaging import version
label_desc: Use image node_id 3 for calling a global function with example usage: build_lightning_model(config, checkpoint_path) and returns: model, model