MLflow integration API reference

API reference for the Neptune-MLflow integration.

create_neptune_tracking_uri()

Sets up a Neptune tracking URI for logging MLflow experiment metadata.

This lets you direct your metadata to Neptune instead of MLflow, without needing to change your MLflow logging code.

The function wrapsneptune.init_run(), so you have the same parameters available for customizing your run or limiting what is logged. The exceptions arewith_idandcustom_run_id, which will be ignored if provided (as calling this function always creates a new Neptune run).

Parameters

Name Type Default Description
project str, optional None Name of a project in the formworkspace-name/project-name. If None, the value of theNEPTUNE_PROJECTenvironment variable is used.
api_token str, optional None User's API token. If None, the value of theNEPTUNE_API_TOKENenvironment variable is used.Set toneptune.ANONYMOUS_API_TOKENto log metadata anonymously.To keep your token secure, avoid placing it in source code. Instead,save it as an environment variable.
mode str, optional async Connection mode in which the tracking will work. Possible values areasync,sync,offline,read-only, anddebug.If you leave it out, the value of theNEPTUNE_MODEenvironment variable is used. If that's not set, the defaultasyncis used.
name str, optional "Untitled" Custom name of the run. You can edit it in theRun informationand add it as a column in the experiments table (sys/name).
description str, optional "" Description of the run. You can edit it in theRun informationand add it as a column in the experiments table (sys/description).
tags list, optional None Must be a list ofstrwhich represents the tags for the run. You can edit them after run is created, either in the run information or experiments table.
source_files listorstr, optional None List of source files to be uploaded. Must be list ofstror a singlestr. Uploaded sources are displayed in theSource codesection of the run.If Noneis passed, the Python file from which the run was created will be uploaded. When resuming a run, no file will be uploaded by default. Pass an empty list ([]) to upload no files.Unix style pathname pattern expansion is supported. For example, you can pass".py"to upload all Python source files from the current directory. Paths of uploaded files are resolved relative to the calculated common root of all uploaded source files. For recursion lookup, use"**/.py"(for Python 3.5 and later). For details, see thegloblibrary.
capture_stdout Boolean, optional True Whether to log the standard output stream. Is logged in themonitoringnamespace.
capture_stderr Boolean, optional True Whether to log the standard error stream. Is logged in themonitoringnamespace.
capture_hardware_metrics Boolean, optional True Whether to track hardware consumption (CPU, GPU, memory utilization). Logged in themonitoringnamespace.
fail_on_exception Boolean, optional True If an uncaught exception occurs, whether to set run'sFailedstate toTrue.
monitoring_namespace str, optional "monitoring" Namespace inside which all monitoring logs will be stored.
flush_period float, optional 5 In asynchronous (default) connection mode, how often Neptune should triggerdisk flushing(in seconds).
proxies dict, optional None Argument passed to HTTP calls made via theRequestslibrary. For details on proxies, see the Requests documentation.
capture_traceback Boolean, optional True In case of an exception, whether to log the traceback of the run.
git_ref GitReforBoolean None GitRefobject containing information about the Git repository path.If None, Neptune looks for a repository in the path of the script that is executed.To specify a different location, set toGitRef(repository_path="path/to/repo").To turn off Git tracking for the run, set toGitRef.DISABLEDorFalse.For examples, seeLogging Git info.
dependencies str, optional None Tracks environment requirements. If you pass"infer"to this argument, Neptune logs dependencies installed in the current environment. You can also pass a path to your dependency file directly. If left empty, no dependency file is uploaded.
async_lag_callback NeptuneObjectCallback, optional None Custom callback which is called if the lag between a queued operation and its synchronization with the server exceeds the duration defined byasync_lag_threshold. The callback should take aRunobject as the argument and can contain any custom code, such as callingstop()on the object.Note:Instead of using this argument, you can use Neptune's default callback by setting theNEPTUNE_ENABLE_DEFAULT_ASYNC_LAG_CALLBACKenvironment variable toTRUE.
async_lag_threshold float, optional 1800.0 In seconds, duration between the queueing and synchronization of an operation. If a lag callback (default callback enabled via environment variable or custom callback passed to theasync_lag_callbackargument) is enabled, the callback is called when this duration is exceeded.
async_no_progress_callback NeptuneObjectCallback, optional None Custom callback which is called if there has been no synchronization progress whatsoever for the duration defined byasync_no_progress_threshold. The callback should take aRunobject as the argument and can contain any custom code, such as callingstop()on the object.Note:Instead of using this argument, you can use Neptune's default callback by setting theNEPTUNE_ENABLE_DEFAULT_ASYNC_NO_PROGRESS_CALLBACKenvironment variable toTRUE.
async_no_progress_threshold float, optional 300.0 In seconds, for how long there has been no synchronization progress whatsoever. If a no-progress callback (default callback enabled via environment variable or custom callback passed to theasync_no_progress_callbackargument) is enabled, the callback is called when this duration is exceeded.

Set toneptune.ANONYMOUS_API_TOKENto log metadata anonymously.

To keep your token secure, avoid placing it in source code. Instead,save it as an environment variable.

If you leave it out, the value of theNEPTUNE_MODEenvironment variable is used. If that's not set, the defaultasyncis used.

List of source files to be uploaded. Must be list ofstror a singlestr. Uploaded sources are displayed in theSource codesection of the run.

IfNoneis passed, the Python file from which the run was created will be uploaded. When resuming a run, no file will be uploaded by default. Pass an empty list ([]) to upload no files.

Unix style pathname pattern expansion is supported. For example, you can pass".py"to upload all Python source files from the current directory. Paths of uploaded files are resolved relative to the calculated common root of all uploaded source files. For recursion lookup, use"**/.py"(for Python 3.5 and later). For details, see thegloblibrary.

IfNone, Neptune looks for a repository in the path of the script that is executed.

To specify a different location, set toGitRef(repository_path="path/to/repo").

To turn off Git tracking for the run, set toGitRef.DISABLEDorFalse.

Note:Instead of using this argument, you can use Neptune's default callback by setting theNEPTUNE_ENABLE_DEFAULT_ASYNC_LAG_CALLBACKenvironment variable toTRUE.

Note:Instead of using this argument, you can use Neptune's default callback by setting theNEPTUNE_ENABLE_DEFAULT_ASYNC_NO_PROGRESS_CALLBACKenvironment variable toTRUE.

Example

from neptune_mlflow_plugin import create_neptune_tracking_uri

uri = create_neptune_tracking_uri() # (1)!
mlflow.set_tracking_uri(uri)

with mlflow.start_run() as mlflow_run:
 ...

As a best practice, you should save your Neptune API token and project name as environment variables:

export NEPTUNE_API_TOKEN="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jv...Yh3Kb8"
export NEPTUNE_PROJECT="ml-team/classification"

Alternatively, you can pass the information when using a function that takesapi_tokenandprojectas arguments:

run = neptune.init_run(
 api_token="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jv...Yh3Kb8", # (1)!
 project="ml-team/classification", # (2)!
)
  1. In the bottom-left corner, expand the user menu and select Get my API token .
  2. You can copy the path from the project details ( → Details & privacy ).

If you haven't registered, you can log anonymously to a public project:

api_token=neptune.ANONYMOUS_API_TOKEN
project="common/quickstarts"

Make sure not to publish sensitive data through your code!

Additional options

You can pass the same keyword arguments as forneptune.init_run(). This way, you can enable more options for the run or limit what is logged.

uri = create_neptune_tracking_uri(
 name="my-custom-run-name",
 description="Description of this run",
 tags=["test", "mlflow"],
 source_files="**/.py",
 dependencies="infer",
)

neptune mlflow

Exports existing MLflow metadata to Neptune.

Command syntax:neptune mlflow [--api-token] [--project] [--mlflow-tracking-uri] [--exclude-artifacts] [--max-artifact-size]

Options Type Default Description
-p,--project str - Neptune project name. If None, the value of theNEPTUNE_PROJECTenvironment variable is used.
-a,--api-token str - Neptune API token. If None, the value of theNEPTUNE_API_TOKENenvironment variable is used.
-u,--mlflow-tracking-uri str - Your MLflow tracking URI. If not provided, it is left to the MLflow client to resolve it. For more, see theMLflow documentation.
-e,--exclude-artifacts bool False Whether to skip uploading artifacts to Neptune.
-m,--max-artifact-size int 50 Maximum size of the artifact to be uploaded to Neptune (in MB). For directories, this will be treated as the max size of the entire directory.
--help - - Show help message and exit.

Examples

If you've set your Neptune credentials as environment variables, you can use the following command to export data with default settings:

neptune mlflow

Set your Neptune API token and full project name to theNEPTUNE_API_TOKENandNEPTUNE_PROJECTenvironment variables, respectively.

export NEPTUNE_API_TOKEN="h0dHBzOi8aHR0cHM.4kl0jvYh3Kb8...ifQ=="
export NEPTUNE_PROJECT="ml-team/classification"
export NEPTUNE_API_TOKEN="h0dHBzOi8aHR0cHM.4kl0jvYh3Kb8...ifQ=="
export NEPTUNE_PROJECT="ml-team/classification"
setx NEPTUNE_API_TOKEN "h0dHBzOi8aHR0cHM.4kl0jvYh3Kb8...ifQ=="
setx NEPTUNE_PROJECT "ml-team/classification"

You can also navigate toSettings→Edit the system environment variablesand add the variables there.

%env NEPTUNE_API_TOKEN="h0dHBzOi8aHR0cHM.4kl0jvYh3Kb8...ifQ=="
%env NEPTUNE_PROJECT="ml-team/classification"

To find your credentials:

  • API token : In the bottom-left corner of the Neptune app, expand your user menu and select Get your API token . If you need the token of a service account, go to the workspace or project settings and enter the Service accounts settings.
  • Project name : Your full project name has the form workspace-name/project-name . You can copy it from the project menu ( → Details & privacy ).

If you're working in Google Colab, you can set your credentials with the os and getpass libraries:

import os
from getpass import getpass
os.environ["NEPTUNE_API_TOKEN"] = getpass("Enter your Neptune API token: ")
os.environ["NEPTUNE_PROJECT"] = "workspace-name/project-name"

Otherwise, you can pass the credentials as options:

neptune mlflow \
 --api-token I2YzgMz1h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jvh0dHBzOi8aHR0Yh3Kb8MifQ== \
 --project ml-team/llm-project \

Using the command with more options:

neptune mlflow \
 --project ml-team/llm-project-2 \
 --max-artifact-size 100 \
 /

neptune-notebooks incompatibility

The command doesn't work together with theNeptune-Jupyter extension(neptune-notebooks).

To use the command, you must uninstall neptune-notebooks first.

See also

  • neptune-mlflow repo on GitHub


This page is originally sourced from the legacy docs.