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
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')
src/bentoml/_internal/frameworks/detectron.py