module mlforecast.flavor
Global Variables
- MLMODEL_FILE_NAME
- INVALID_PARAMETER_VALUE
- DEFAULT_AWAIT_MAX_SLEEP_SECONDS
- FLAVOR_NAME
function get_default_pip_requirements
list: list of default pip requirements for MLflow Models produced by this flavor.Calls to: func:save_model()and :func:log_model()produce a pip environment that, at a minimum, contains these requirements.
function get_default_conda_env
:func:save_model()and :func:log_model()
function save_model
MLForecast model to a local path
Args:
-
model(MLForecast): FittedMLForecastmodel object. -
path(str): Local path where the model is to be saved. -
conda_env(Union[dict, str], optional): Either a dictionary representation of a Conda environment or the path to a conda environment yaml file. Defaults to None. -
code_paths(array-like, optional): A list of local filesystem paths to Python file dependencies (or directories containing file dependencies). These files are prepended to the system path when the model is loaded. Defaults to None. -
mlflow_model(mlflow.models.Model, optional): mlflow.models.Model configuration to which to add the python_function flavor. Defaults to None. -
signature(mlflow.models.signature.ModelSignature, optional): Model Signature mlflow.models.ModelSignature describes -
model input and output: py:class:Schema <mlflow.types.Schema>. The model -
signature can be: py:func:inferred <mlflow.models.infer_signature>from datasets with valid model input (e.g. the training dataset with target column omitted) and valid model output (e.g. model predictions generated on the training dataset), for example: -
.. code-block: : py
input_example(Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, csr_matrix, csc_matrix], optional): Input example provides one or several instances of valid model input. The example can be used as a hint of what data to feed the model. The given example will be converted to aPandas DataFrameand then serialized to json using thePandassplit-oriented format. Bytes are base64-encoded. Defaults to None.pip_requirements(Union[Iterable, str], optional): Either an iterable of pip requirement strings (e.g. [“mlforecast”, “-r requirements.txt”, “-c constraints.txt”]) or the string path to a pip requirements file on the local filesystem (e.g. “requirements.txt”). Defaults to None.extra_pip_requirements(Union[Iterable, str], optional): Either an iterable of pip requirement strings (e.g. [“pandas”, “-r requirements.txt”, “-c constraints.txt”]) or the string path to a pip requirements file on the local filesystem (e.g. “requirements.txt”). Defaults to None.serialization_format(str, optional): The format in which to serialize the model. This should be one of the formats “pickle” or “cloudpickle”. Defaults to “pickle”.
function log_model
MLForecast model as an MLflow artifact for the current run.
Args:
-
model(MLForecast): FittedMLForecastmodel object. -
artifact_path(str): Run-relative artifact path to save the model to. -
conda_env(Union[dict, str], optional): Either a dictionary representation of a Conda environment or the path to a conda environment yaml file. Defaults to None. -
code_paths(array-like, optional): A list of local filesystem paths to Python file dependencies (or directories containing file dependencies). These files are prepended to the system path when the model is loaded. Defaults to None. -
registered_model_name(str, optional): If given, create a model version underregistered_model_name, also creating a registered model if one with the given name does not exist. Defaults to None. -
signature(mlflow.models.signature.ModelSignature, optional): Model Signature mlflow.models.ModelSignature describes -
model input and output: py:class:Schema <mlflow.types.Schema>. The model -
signature can be: py:func:inferred <mlflow.models.infer_signature>from datasets with valid model input (e.g. the training dataset with target column omitted) and valid model output (e.g. model predictions generated on the training dataset), for example: -
.. code-block: : py
input_example(Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, csr_matrix, csc_matrix], optional): Input example provides one or several instances of valid model input. The example can be used as a hint of what data to feed the model. The given example will be converted to aPandas DataFrameand then serialized to json using thePandassplit-oriented format. Bytes are base64-encoded. Defaults to None.await_registration_for(int, optional): Number of seconds to wait for the model version to finish being created and is inREADYstatus. By default, the function waits for five minutes. Specify 0 or None to skip waiting. Defaults to None.pip_requirements(Union[Iterable, str], optional): Either an iterable of pip requirement strings (e.g. [“mlforecast”, “-r requirements.txt”, “-c constraints.txt”]) or the string path to a pip requirements file on the local filesystem (e.g. “requirements.txt”). Defaults to None.extra_pip_requirements(Union[Iterable, str], optional): Either an iterable of pip requirement strings (e.g. [“pandas”, “-r requirements.txt”, “-c constraints.txt”]) or the string path to a pip requirements file on the local filesystem (e.g. “requirements.txt”). Defaults to None.kwargs: Additional arguments for :py:class:mlflow.models.model.Model
A: py:class:ModelInfo <mlflow.models.model.ModelInfo>instance that contains the metadata of the logged model.
function load_model
MLForecast model from a local file or a run.
Args:
-
model_uri(str): The location, in URI format, of the MLflow model. For example:/Users/me/path/to/local/modelrelative/path/to/local/models3://my_bucket/path/to/modelruns:/<mlflow_run_id>/run-relative/path/to/modelmlflow-artifacts:/path/to/model
https: //www.mlflow.org/docs/latest/tracking.html#artifact-locationsdst_path(str, optional): The local filesystem path to which to download the model artifact.This directory must already exist. If unspecified, a local output path will be created. Defaults to None.
MLForecast model instance.
