def load_model(bento_model: str | Tag | Model, *args: t.Any, **kwargs: t.Any) -> t.Any:
    """
    Load the Transformers model from BentoML local modelstore 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.
        args: Additional model args to be passed into the model if the object is a Transformers PreTrained protocol.
              This shouldn't be used when the bento_model is a pipeline.
        kwargs: Additional keyword arguments to pass into the pipeline.

    Returns:
        ``transformers.pipeline.base.Pipeline``: The Transformers pipeline loaded
        from the model store.

    Example:

    .. code-block:: python

        import bentoml
        pipeline = bentoml.transformers.load_model('my_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}."
        )

    options = t.cast(ModelOptions, bento_model.info.options)
    api_version = bento_model.info.api_version
    task = options.task
    pipeline: transformers.Pipeline | None = None
    if api_version == "v1":
        # NOTE: backward compatibility
        from transformers.pipelines import get_supported_tasks

        logger.warning(
            "Upgrading '%s' to with newer 'save_model' is recommended. Loading model with version 1.",
            bento_model,
        )

        # Set trust_remote_code to True to allow loading custom pipeline.
        kwargs.setdefault("trust_remote_code", False)
        kwargs.update(options.kwargs)
        if len(kwargs) > 0:
            logger.debug(
                "Loading '%s' pipeline (tag='%s') with kwargs %s.",
                task,
                bento_model.tag,
                kwargs,
            )

        # v1 pickled the pipeline with 'pipeline.v1.pkl'.
        fname = "pipeline.v1.pkl"
        if os.path.exists(bento_model.path_of(fname)):
            with open(bento_model.path_of(fname), "rb") as f:
                pipeline = cloudpickle.load(f)

        if task not in get_supported_tasks():
            logger.debug("'%s' is a custom task. Registering it to the registry.", task)
            kwargs["trust_remote_code"] = True
            # most likely a custom pipeline
            if pipeline is None:
                # if the pipeline is not loaded from the pickle, and it is custom, then we should be able to load
                # it with model=bento_model.path
                return transformers.pipeline(model=bento_model.path, **kwargs)
            else:
                register_pipeline(
                    task,
                    pipeline.__class__,
                    tuple(
                        convert_to_autoclass(auto_class) for auto_class in options.pt
                    ),
                    tuple(
                        convert_to_autoclass(auto_class) for auto_class in options.tf
                    ),
                    options.default,
                    options.type,
                )

        kwargs.setdefault("pipeline_class", pipeline.__class__ if pipeline else None)

        assert task in get_supported_tasks(), (
            f"Task '{task}' is not a valid task for pipeline (available: {get_supported_tasks()})."
        )

        return (
            transformers.pipeline(task=task, model=bento_model.path, **kwargs)
            if pipeline is None
            else pipeline
        )
    else:
        if api_version != "v2":
            logger.warning(
                "Got unknown API version '%s', unexpected errors may occur.",
                api_version,
            )

        if "_pretrained_class" in bento_model.info.metadata:
            with open(bento_model.path_of(PRETRAINED_PROTOCOL_NAME), "rb") as f:
                protocol: PreTrainedProtocol = cloudpickle.load(f)
            return protocol.from_pretrained(bento_model.path, *args, **kwargs)
        else:
            assert len(args) == 0, (
                "Positional args are not supported for pipeline. Make sure to only use kwargs instead."
            )
            with open(bento_model.path_of(PIPELINE_PICKLE_NAME), "rb") as f:
                pipeline_class: type[transformers.Pipeline] = cloudpickle.load(f)

            from transformers.pipelines import get_supported_tasks

            if task not in get_supported_tasks():
                logger.debug(
                    "'%s' is not a supported task, trying to load custom pipeline.",
                    task,
                )

                register_pipeline(
                    task,
                    pipeline_class,
                    tuple(
                        convert_to_autoclass(auto_class) for auto_class in options.pt
                    ),
                    tuple(
                        convert_to_autoclass(auto_class) for auto_class in options.tf
                    ),
                    options.default,
                    options.type,
                )
                kwargs["trust_remote_code"] = True

            kwargs.setdefault("pipeline_class", pipeline_class)

            assert task in get_supported_tasks(), (
                f"Task '{task}' is not a valid task for pipeline (available: {get_supported_tasks()})."
            )

            kwargs.update(options.kwargs)
            if len(kwargs) > 0:
                logger.debug(
                    "Loading '%s' pipeline (tag='%s') with kwargs %s.",
                    task,
                    bento_model.tag,
                    kwargs,
                )
            try:
                return transformers.pipeline(
                    task=task, model=bento_model.path, **kwargs
                )
            except Exception:
                # NOTE: When loading a custom pipeline that is not available on huggingface hub,
                # the class registered in the pipeline registry will be a path to a Python file path.
                # Currently, it doesn't handle relative imports correctly, so users will need to use
                # external_modules when using 'save_model'.
                logger.debug(
                    "If you are loading a custom pipeline, See https://huggingface.co/docs/transformers/main/en/add_new_pipeline#how-to-create-a-custom-pipeline for more information. We recommend to upload the custom pipeline to HuggingFace Hub to ensure consistency. You can also try adding the pipeline instance to 'external_modules': 'import importlib; bentoml.transformers.save_model(..., external_modules=[importlib.import_module(pipeline_instance.__module__)])'"
                )
                raise
Load the Transformers model from BentoML local modelstore 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.
args: Additional model args to be passed into the model if the object is a Transformers PreTrained protocol.
This shouldn't be used when the bento_model is a pipeline.
kwargs: Additional keyword arguments to pass into the pipeline.

Returns:
``transformers.pipeline.base.Pipeline``: The Transformers pipeline loaded
from the model store.

Example:

.. code-block:: python

import bentoml
pipeline = bentoml.transformers.load_model('my_model:latest')
src/bentoml/_internal/frameworks/transformers.py