def load(
    bento_identifier: str | Tag | Bento,
    working_dir: t.Optional[str] = None,
    standalone_load: bool = False,
    reload: bool = False,
) -> AnyService:
    """Load a Service instance by the bento_identifier

    Args:
        bento_identifier: target Service to import or Bento to load
        working_dir: when importing from service, set the working_dir
        standalone_load: treat target Service as standalone. This will change global
                         current working directory and global model store.

    Returns:
        The loaded :obj:`bentoml.Service` instance.

    The argument ``bento_identifier`` can be one of the following forms:

    * Tag pointing to a Bento in local Bento store under `BENTOML_HOME/bentos`
    * File path to a Bento directory
    * "import_str" for loading a service instance from the `working_dir`

    Example load from Bento usage:

    .. code-block:: python

        # load from local bento store
        load("FraudDetector:latest")
        load("FraudDetector:4tht2icroji6zput")

        # load from bento directory
        load("~/bentoml/bentos/iris_classifier/4tht2icroji6zput")


    Example load from working directory by "import_str" usage:

    .. code-block:: python

        # When multiple service defined in the same module
        load("fraud_detector:svc_a")
        load("fraud_detector:svc_b")

        # Find svc by Python module name or file path
        load("fraud_detector:svc")
        load("fraud_detector.py:svc")
        load("foo.bar.fraud_detector:svc")
        load("./def/abc/fraud_detector.py:svc")

        # When there's only one Service instance in the target module, the attributes
        # part in the svc_import_path can be omitted
        load("fraud_detector.py")
        load("fraud_detector")
    """
    if isinstance(bento_identifier, (Bento, Tag)):
        # Load from local BentoStore
        return load_bento(bento_identifier, reload=reload)
    bento_path = os.path.expanduser(
        os.path.abspath(os.path.join(working_dir or ".", bento_identifier))
    )
    if os.path.isdir(bento_path):
        if os.path.isfile(
            os.path.expanduser(os.path.join(bento_path, BENTO_YAML_FILENAME))
        ):
            # Loading from path to a built Bento
            svc = load_bento_dir(bento_path, reload=reload)
            logger.info("Service loaded from Bento directory: %s", svc)
        else:
            for filename in DEFAULT_BENTO_BUILD_FILES:
                if os.path.isfile(
                    config_file := os.path.expanduser(
                        os.path.join(bento_path, filename)
                    )
                ):
                    build_config = BentoBuildConfig.from_file(config_file)
                    BentoMLContainer.model_aliases.set(build_config.model_aliases)
                    svc = import_service(
                        build_config.service, working_dir=bento_path, reload=reload
                    )
                    logger.debug("'%s' loaded from '%s': %s", svc.name, bento_path, svc)
                    break
            else:
                if os.path.isfile(os.path.join(bento_path, "service.py")):
                    logger.info("Loading service from default location 'service.py'")
                    svc = import_service(
                        "service.py", working_dir=bento_path, reload=reload
                    )
                else:
                    raise ImportServiceError(
                        f"Failed to load bento or import service '{bento_identifier}'. "
                        f"The directory '{bento_path}' does not contain a valid bentofile.yaml or service.py."
                    )
    else:
        try:
            # Loading from service definition file, e.g. "my_service.py:svc"
            svc = import_service(
                bento_identifier, working_dir=working_dir, reload=reload
            )
            logger.debug("'%s' imported from source: %s", svc.name, svc)
        except ImportServiceError as e1:
            try:
                # Loading from local bento store by tag, e.g. "iris_classifier:latest"
                svc = load_bento(bento_identifier)
                logger.debug("'%s' loaded from Bento store: %s", svc.name, svc)
            except (NotFound, ImportServiceError) as e2:
                raise ImportServiceError(
                    f"Failed to load bento or import service '{bento_identifier}'.\n"
                    f"If you are attempting to import bento in local store: '{e1}'.\n"
                    f"If you are importing by python module path: '{e2}'."
                ) from e2
    return svc
Load a Service instance by the bento_identifier

Args:
bento_identifier: target Service to import or Bento to load
working_dir: when importing from service, set the working_dir
standalone_load: treat target Service as standalone. This will change global
current working directory and global model store.

Returns:
The loaded :obj:`bentoml.Service` instance.

The argument ``bento_identifier`` can be one of the following forms:

* Tag pointing to a Bento in local Bento store under `BENTOML_HOME/bentos`
* File path to a Bento directory
* "import_str" for loading a service instance from the `working_dir`

Example load from Bento usage:

.. code-block:: python

# load from local bento store
load("FraudDetector:latest")
load("FraudDetector:4tht2icroji6zput")

# load from bento directory
load("~/bentoml/bentos/iris_classifier/4tht2icroji6zput")


Example load from working directory by "import_str" usage:

.. code-block:: python

# When multiple service defined in the same module
load("fraud_detector:svc_a")
load("fraud_detector:svc_b")

# Find svc by Python module name or file path
load("fraud_detector:svc")
load("fraud_detector.py:svc")
load("foo.bar.fraud_detector:svc")
load("./def/abc/fraud_detector.py:svc")

# When there's only one Service instance in the target module, the attributes
# part in the svc_import_path can be omitted
load("fraud_detector.py")
load("fraud_detector")
src/bentoml/_internal/service/loader.py