pip install mlflow★Core package — tracking, models, registry, UI, CLI.pip install mlflow[extras]Pulls in sklearn/pytorch/tensorflow helpers.mlflow.set_tracking_uri("file:./mlruns")Local store (default) vs a remote server URL.os.environ["MLFLOW_TRACKING_URI"]Same thing via env var — handy in CI/containers.
mlflow.set_experiment("name")★Creates the experiment if missing, then activates it.with mlflow.start_run():★Opens a run; auto-closes at block end.mlflow.start_run(run_name="x")Human-readable label shown in the UI.mlflow.start_run(run_id=id)Reopen a past run to append more logs.mlflow.start_run(nested=True)Child run inside a parent — great for HPO sweeps.mlflow.end_run()Manual close when not using a with block.
mlflow.log_param("lr", 0.01)★One hyperparameter, fixed for the run.mlflow.log_params(dict)Bulk-log a dict of hyperparameters.mlflow.log_metric("acc", 0.95, step=e)★Numeric value, optionally per training step.mlflow.log_metrics(dict)Bulk-log several metrics at once.mlflow.log_artifact("plot.png")★Attach any file — plots, configs, predictions.mlflow.log_artifacts("./plots")Log a whole directory of files.mlflow.set_tag("k", "v")Free-form metadata, e.g. model_type, owner.
mlflow.autolog()★Detects the framework in use and logs everything.mlflow.sklearn.autolog()★Params, metrics, model — captured automatically.mlflow.tensorflow.autolog()Keras/TF training loop metrics per epoch.MLFlowLogger(...)PyTorch LightningPass as logger= to pl.Trainer; logs self.log() calls.
mlflow.sklearn.log_model(model, "model")★Saves model + signature + conda/pip env.mlflow.pytorch.log_model(...)Same idea for PyTorch nn.Module.mlflow.transformers.log_model(...)Bundles a HF model + tokenizer together.mlflow.pyfunc.PythonModelCustom flavor — wrap any pre/post-processing logic.log_model(..., registered_model_name="x")★Logs and registers in one call.
mlflow.register_model(model_uri, "name")★Register an already-logged model from a run.client = MlflowClient()★Low-level API for registry operations.client.set_registered_model_alias(name, "champion", v)★Mutable named pointer — multiple aliases allowed.client.set_model_version_tag(...)e.g. validation_status: passed.client.transition_model_version_stage(...)deprecatedOld Staging/Production/Archived workflow — use aliases.
mlflow.pyfunc.load_model("models:/name@champion")★Load by alias — code never hardcodes a version.mlflow.pyfunc.load_model("models:/name/3")Load an exact version number.mlflow.flavor.load_model("runs:/id/model")Load straight from a run, pre-registry.mlflow models serve -m models:/name@champion -p 1234★Spin up a local REST inference endpoint.curl -d '{"instances":[[..]]}' …/invocationsTest the served endpoint with a JSON payload.
mlflow ui★Local web UI at http://localhost:5000.mlflow ui --port 5001 --host 0.0.0.0Expose on a custom port/interface.mlflow ui --backend-store-uri postgresql://…Point at a shared/remote tracking DB.mlflow experiments listCLI list of experiments.mlflow runs list --experiment-id 1CLI list of runs in an experiment.mlflow doctorSanity-check the local install/config.
mlflow.search_runs(experiment_ids=["1"])★Returns a pandas DataFrame of runs.filter_string="metrics.accuracy > 0.9"★UI & API both use this search syntax.mlflow.get_run(run_id)Fetch a single run's params/metrics/tags.client.search_model_versions("name='x'")List every version of a registered model.
MLproject★Entry point + parameter spec, like a Dockerfile.conda.yaml / python_env.yamlDeclares the environment dependencies.mlflow.run("uri#", parameters={…})Run a project programmatically with given params.mlflow run . -P lr=0.01Run a project from the CLI.
mlflow.start_run(nested=True)★Group HPO trials under one parent run.log_metric() inside a tight loopslowMany small calls thrash the API — batch by epoch instead.log_artifact()notlog_param()Use artifacts for files/large blobs, params for scalars.mlflow.set_tag("framework", …)Tag consistently so search/filtering stays useful.
runs:/<run_id>/modelstraight from a run's artifacts, pre-registrymodels:/<name>/3a specific registered version numbermodels:/<name>@championcurrent alias — recommended for deploymentmodels:/<name>/Productiondeprecatedold stage-based URI — migrate to aliases