aimz.mlflow.save_model#
- aimz.mlflow.save_model(model, path, conda_env=None, code_paths=None, mlflow_model=None, signature=None, input_example=None, pip_requirements=None, extra_pip_requirements=None, metadata=None)[source]#
Save an aimz model to a path on the local file system.
- Parameters:
model (ImpactModel) – An aimz model (an instance of
ImpactModel) to be saved.path (str | Path) – Local path where the model is to be saved.
conda_env (dict | None) –
Either a dictionary representation of a Conda environment or the path to a conda environment yaml file. If provided, this describes the environment this model should be run in. At a minimum, it should specify the dependencies contained in get_default_conda_env(). If
None, a conda environment with pip requirements inferred bymlflow.models.infer_pip_requirements()is added to the model. If the requirement inference fails, it falls back to using get_default_pip_requirements. pip requirements fromconda_envare written to a piprequirements.txtfile and the full conda environment is written toconda.yaml. The following is an example dictionary representation of a conda environment:{ "name": "mlflow-env", "channels": ["conda-forge"], "dependencies": [ "python=3.8.15", { "pip": [ "aimz==x.y.z" ], }, ], }
code_paths (list | None) –
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. Files declared as dependencies for a given model should have relative imports declared from a common root path if multiple files are defined with import dependencies between them to avoid import errors when loading the model.
For a detailed explanation of
code_pathsfunctionality, recommended usage patterns and limitations, see the code_paths usage guide.mlflow_model (Model | None) –
mlflow.models.Modelthis flavor is being added to.signature (ModelSignature | None) –
an instance of the
ModelSignatureclass that describes the model’s inputs and outputs. If not specified but aninput_exampleis supplied, a signature will be automatically inferred based on the supplied input example and model. To disable automatic signature inference when providing an input example, setsignaturetoFalse. To manually infer a model signature, callinfer_signature()on datasets with valid model inputs, such as a training dataset with the target column omitted, and valid model outputs, like model predictions made on the training dataset, for example:from mlflow.models import infer_signature train = df.drop_column("target_label") predictions = ... # compute model predictions signature = infer_signature(train, predictions)
input_example (ModelInputExample) – one or several instances of valid model input. The input example is used as a hint of what data to feed the model. It will be converted to a Pandas DataFrame and then serialized to json using the Pandas split-oriented format, or a numpy array where the example will be serialized to json by converting it to a list. Bytes are base64-encoded. When the
signatureparameter isNone, the input example is used to infer a model signature.pip_requirements (Iterable[str] | str | None) – Either an iterable of pip requirement strings (e.g.
["aimz", "-r requirements.txt", "-c constraints.txt"]) or the string path to a pip requirements file on the local filesystem (e.g."requirements.txt"). If provided, this describes the environment this model should be run in. IfNone, a default list of requirements is inferred bymlflow.models.infer_pip_requirements()from the current software environment. If the requirement inference fails, it falls back to using get_default_pip_requirements. Both requirements and constraints are automatically parsed and written torequirements.txtandconstraints.txtfiles, respectively, and stored as part of the model. Requirements are also written to thepipsection of the model’s conda environment (conda.yaml) file.extra_pip_requirements (Iterable[str] | str | None) –
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"). If provided, this describes additional pip requirements that are appended to a default set of pip requirements generated automatically based on the user’s current software environment. Both requirements and constraints are automatically parsed and written torequirements.txtandconstraints.txtfiles, respectively, and stored as part of the model. Requirements are also written to thepipsection of the model’s conda environment (conda.yaml) file.Warning
The following arguments can’t be specified at the same time:
conda_envpip_requirementsextra_pip_requirements
This example demonstrates how to specify pip requirements using
pip_requirementsandextra_pip_requirements.metadata (dict | None) – Custom metadata dictionary passed to the model and stored in the MLmodel file.
- Return type:
None