class_docstr: For integration with MMF's trainer, datasets and other features,
  models needs to inherit this class, call `super`, write a build function,
  write a forward function taking a ``SampleList`` as input and returning a
  dict as output and finally, register it using ``@registry.register_model``
  
  Args:
      config (DictConfig): ``model_config`` configuration from global config.
class_docstr_tok: ["For","integration","with","MMF","'s","trainer",",","datasets","and","other","features",",","models","needs","to","inherit","this","class",",","call","`","super","`",",","write","a","build","function",",","write","a","forward","function","taking","a","``","SampleList","``","as","input","and","returning","a","dict","as","output","and","finally",",","register","it","using","``","@","registry.register_model","``","Args",":","config","(","DictConfig",")",":","``","model_config","``","configuration","from","global","config","."]
code: def from_pretrained(cls, model_name_or_path, *args, **kwargs):
      # Check if the path exists, if not it is pretrained, otherwise,
      # we will try to load the checkpoint from the path
      if not PathManager.exists(model_name_or_path):
          model_key = model_name_or_path.split(".")[0]
          model_cls = registry.get_model_class(model_key)
          assert (
              model_cls == cls
          ), f"Incorrect pretrained model key {model_name_or_path} "
          "for class {cls.__name__}"
      output = load_pretrained_model(
          model_name_or_path, *args, **kwargs
      )
      config, checkpoint, full_config = (
          output["config"],
          output["checkpoint"],
          output["full_config"],
      )
  
      # Save original config for state reset later
      config_temp_holder = registry.get("config")
      # Register full config from checkpoint when loading the model
      registry.register("config", full_config)
  
      # Some models need registry updates to be load pretrained model
      # If they have this method, call it so they can update accordingly
      if hasattr(cls, "update_registry_for_pretrained"):
          cls.update_registry_for_pretrained(config, checkpoint, output)
  
      instance = cls(config)
      instance.is_pretrained = True
      instance.build()
      incompatible_keys = instance.load_state_dict(
          checkpoint, strict=False
      )
  
      # The model has loaded, reset the state
      registry.register("config", config_temp_holder)
  
      if len(incompatible_keys.missing_keys) != 0:
          logger.warning(
              f"Missing keys {incompatible_keys.missing_keys} in the"
              + " checkpoint.\n"
              + "If this is not your checkpoint, please open up an "
              + "issue on MMF GitHub. \n"
              + f"Unexpected keys if any: {incompatible_keys.unexpected_keys}"
          )
  
      if len(incompatible_keys.unexpected_keys) != 0:
          logger.warning(
              "Unexpected keys in state dict: "
              + f"{incompatible_keys.unexpected_keys} \n"
              + "This is usually not a problem with pretrained models, but "
              + "if this is your own model, please double check. \n"
              + "If you think this is an issue, please open up a "
              + "bug at MMF GitHub."
          )
  
      instance.eval()
  
      return instance
  
imports: import collections
  import logging
  import warnings
  from copy import deepcopy
  from dataclasses import dataclass
  from typing import Any, Dict, List, Optional, Union
  import pytorch_lightning
  from mmf.common.registry import registry
  from mmf.common.report import Report
  from mmf.common.sample import SampleList, to_device
  from mmf.modules.losses import LossConfig, Losses
  from mmf.utils.checkpoint import load_pretrained_model
  from mmf.utils.checkpoint_updater import MMFToPLCheckpointUpdater
  from mmf.utils.download import download_pretrained_model
  from mmf.utils.file_io import PathManager
  from mmf.utils.general import get_current_device
  from mmf.utils.logger import log_class_usage
  from omegaconf import DictConfig, MISSING, OmegaConf
label_desc: Use image node_id 27 for calling the BaseModel obj's underlying member method code with example usage: obj.from_pretrained(cls, model_name_or_path) and returns: instance