code: def load_model(
      bento_model: str | Tag | Model, device_id: str = "cpu"
  ) -> Engine.DefaultPredictor | nn.Module:
      """
      Load the detectron2 model from BentoML local model store with given name.
  
      Args:
          bento_model: Either the tag of the model to get from the store,
                       or a BentoML :class:`~bentoml.Model` instance to load the
                       model from.
          device_id: The device to load the model to. Default to "cpu".
  
      Returns:
          One of the following:
          - ``detectron2.engine.DefaultPredictor`` if the the checkpointables is saved as a Predictor.
          - ``torch.nn.Module`` if the checkpointables is saved as a nn.Module
  
      Example:
  
      .. code-block:: python
  
          import bentoml
          predictor = bentoml.detectron2.load_model('predictor:latest')
  
          model = bentoml.detectron2.load_model('model:latest')
      """
      if not isinstance(bento_model, Model):
          bento_model = get(bento_model)
  
      if bento_model.info.module not in (MODULE_NAME, __name__):
          raise NotFound(
              f"Model {bento_model.tag} was saved with module {bento_model.info.module}, not loading with {MODULE_NAME}."
          )
  
      cfg = bento_model.custom_objects["config"]
      cfg.MODEL.DEVICE = device_id
  
      metadata = bento_model.info.metadata
      if metadata.get("_is_predictor", True):
          return Engine.DefaultPredictor(cfg)
      else:
          model = Modeling.build_model(cfg)
          model.to(device).eval()
          Checkpoint.DetectionCheckpointer(model).load(
              bento_model.path_of(
                  f"{MODEL_FILENAME}{DETECTOR_EXTENSION}"
              )
          )
          return model
  
imports: from __future__ import annotations
  import logging
  import typing
  from types import ModuleType
  import bentoml
  from ...exceptions import MissingDependencyException
  from ...exceptions import NotFound
  from ..models.model import Model
  from ..models.model import ModelContext
  from ..models.model import ModelSignature
  from ..models.model import PartialKwargsModelOptions
  from ..runner.utils import Params
  from ..tag import Tag
  from ..types import LazyType
  from ..utils import LazyLoader
  from ..utils.pkg import get_pkg_version
  from .common.pytorch import PyTorchTensorContainer
  from .common.pytorch import inference_mode_ctx
  from .common.pytorch import torch
label_desc: Use image node_id 2 for calling a global function with example usage: load_model(bento_model, device_id) and returns: Engine, model