Skip to content

Associate model versions with runs#

When you track an experiment in Neptune, the run gets a unique ID. By storing the ID of one or more runs in the metadata of a model, you unambiguously connect a given model version with a certain experiment. This helps create a lineage between models and related experiments and data.

To create a model version and associate it with a run:

  1. Import Neptune and initialize a ModelVersion object:

    import neptune
    model_version = neptune.init_model_version(
        model="CLS-PRE", # (1)!
    1. The Neptune ID of the model

    To use an existing model version, instead of the model parameter, use the with_id parameter and pass a model version ID:

    model_version = neptune.init_model_version(
    How do I find the ID?

    The Neptune ID is a unique identifier for the run. The Experiments tab displays it in the leftmost column.

    In the run structure, the ID is stored in the system namespace (sys).

    • If the run is active, you can obtain its ID with run["sys/id"].fetch(). For example:

      >>> run = neptune.init_run()
      >>> run["sys/id"].fetch()
    • If you set a custom run ID, it's stored at sys/custom_run_id:

      >>> run["sys/custom_run_id"].fetch()
  2. Assign the run ID to a field of your choice.

    model_version["run/id"] = run["sys/id"].fetch()


    If you don't have a connection open to the relevant run, you can:

    • Reinitialize the run: run = neptune.init_run(with_id="CLS-14")
    • Enter the run ID manually: model_version["run/id"] = "CLS-14"
  3. (optional) It can also be helpful to record the URL of the run:

    model_version["run/url"] = run.get_url()


In Neptune, the run ID is logged in the run/id field of the model version.

You can query the logged values from the model_version object with:

run_id = model_version["run/id"].fetch()

run_url = model_version["run/url"].fetch()