Skip to content

load_model

yohou_mlflow.load_model(model_uri, dst_path=None, *, extra_trusted_types=None, extra_trusted_prefixes=None, extra_version_rules=None, strict=True)

Load a yohou forecaster saved by this flavour.

Checks run in this order, and each one stops the load before anything from the file is constructed: the format version, the package versions, then the types in the skops file against the trust policy.

Parameters

Name Type Description Default
model_uri str

Any MLflow model URI, for example "models:/name/1" or a local path.

required
dst_path str or None

Local directory to download the model into.

None
extra_trusted_types iterable of str or None

Exact type names to trust in addition to the built-in policy. The saved model cannot add to this list.

None
extra_trusted_prefixes iterable of str or None

Module prefixes to trust, each ending in ".". The saved model cannot add to them.

None
extra_version_rules mapping of str to str or None

Rules for packages outside the built-in ones, applied to each such package the model recorded.

None
strict bool

When True, a package version mismatch raises VersionMismatchError. When False, it emits a VersionMismatchWarning and the load proceeds.

True

Returns

Type Description
yohou forecaster

The forecaster, in the state it was saved in.

Raises

Type Description
FormatVersionError

If the model was saved in a format version this release cannot read.

VersionMismatchError

If strict and the installed versions break the comparison rules.

UntrustedTypesError

If the skops file holds types outside the policy and the caller's additions.

ValueError

If a trusted prefix is not a module path ending in ".", or a version rule is unknown or names a built-in package.

See Also

check_compatibility : Run the same checks without loading anything.

Source Code

Source code in src/yohou_mlflow/_persistence.py
def load_model(
    model_uri: str,
    dst_path: str | None = None,
    *,
    extra_trusted_types: Iterable[str] | None = None,
    extra_trusted_prefixes: Iterable[str] | None = None,
    extra_version_rules: Mapping[str, str] | None = None,
    strict: bool = True,
) -> Any:
    """Load a yohou forecaster saved by this flavour.

    Checks run in this order, and each one stops the load before anything from the
    file is constructed: the format version, the package versions, then the types in
    the skops file against the trust policy.

    Parameters
    ----------
    model_uri : str
        Any MLflow model URI, for example ``"models:/name/1"`` or a local path.
    dst_path : str or None, default=None
        Local directory to download the model into.
    extra_trusted_types : iterable of str or None, default=None
        Exact type names to trust in addition to the built-in policy. The saved model
        cannot add to this list.
    extra_trusted_prefixes : iterable of str or None, default=None
        Module prefixes to trust, each ending in ``"."``. The saved model cannot add to
        them.
    extra_version_rules : mapping of str to str or None, default=None
        Rules for packages outside the built-in ones, applied to each such package the
        model recorded.
    strict : bool, default=True
        When ``True``, a package version mismatch raises `VersionMismatchError`. When
        ``False``, it emits a `VersionMismatchWarning` and the load proceeds.

    Returns
    -------
    yohou forecaster
        The forecaster, in the state it was saved in.

    Raises
    ------
    FormatVersionError
        If the model was saved in a format version this release cannot read.
    VersionMismatchError
        If ``strict`` and the installed versions break the comparison rules.
    UntrustedTypesError
        If the skops file holds types outside the policy and the caller's additions.
    ValueError
        If a trusted prefix is not a module path ending in ``"."``, or a version rule is unknown or
        names a built-in package.

    See Also
    --------
    check_compatibility : Run the same checks without loading anything.
    """
    validate_prefixes(extra_trusted_prefixes)
    validate_version_rules(extra_version_rules)
    local = download_artifacts(artifact_uri=model_uri, dst_path=dst_path)
    forecaster, _ = _load_local(
        local,
        extra_trusted_types=extra_trusted_types,
        extra_trusted_prefixes=extra_trusted_prefixes,
        extra_version_rules=extra_version_rules,
        strict=strict,
    )
    return forecaster