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.

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(
        with_id="CLS-PRE-8",
    )
    
    How do I find the ID?

    The Neptune ID is a unique identifier for the object. In the table view, it's displayed in the leftmost column.

    The ID is stored in the system namespace. If the object is active, you can obtain its ID with neptune_object["sys/id"].fetch(). For example:

    >>> run = neptune.init_run(project="ml-team/classification")
    >>> run["sys/id"].fetch()
    'CLS-26'
    
  2. Assign the run ID to a field of your choice.

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

    Tip

    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()
    

Result

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()