aimz.mlflow.log_model#
- aimz.mlflow.log_model(model, conda_env=None, code_paths=None, registered_model_name=None, signature=None, input_example=None, await_registration_for=300, pip_requirements=None, extra_pip_requirements=None, metadata=None, name=None, params=None, model_type=None, model_id=None, step=0, tags=None)[source]#
Log an aimz model as an MLflow artifact for the current run..
- Parameters:
model (ImpactModel) – An aimz model (an instance of
ImpactModel) 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.registered_model_name (str | None) – If given, each time a model is trained, it is registered as a new model version of the registered model with this name. The registered model is created if it does not already exist.
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 (DataFrame | ndarray | dict | list | csr_matrix | csc_matrix | str | bytes | tuple) – 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.await_registration_for (int | None) – Number of seconds to wait for the model version to finish being created and is in
READYstatus. By default, the function waits for five minutes. Specify0orNoneto skip waiting.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.
name (str | None) – Model name.
params (dict[str, object] | None) – A dictionary of parameters to log with the model.
model_type (str | None) – The type of the model.
model_id (str | None) – The ID of the model.
step (int) – The step at which to log the model outputs and metrics
tags (dict[str, object] | None) – A dictionary of tags to log with the model.
- Returns:
A
ModelInfoinstance that contains the metadata of the logged model.- Return type: