Associating models with runs
How to connect a registered model with a tracked run in Neptune
When you track an experiment in Neptune, the run gets a unique id. By storing a run id 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. 1.
    Import Neptune and initialize a Model version object:
1
import neptune.new as neptune
2
3
model_version = neptune.init_model_version(
4
model="MODEL_ID",
5
)
Copied!
where MODEL_ID is the Neptune id of the model, stored in sys/id. For example, PROJ-MOD.
  • For more details, see Creating model versions.
  • To use an existing model version, instead of the model parameter, use the version parameter and pass the model version id as its argument:
1
model_version = neptune.init_model_version(
2
version="MODEL_VERSION_ID",
3
)
Copied!
2. Assign the run id to a field of your choice.
1
model_version["run/id"] = run["sys/id"].fetch()
Copied!
If the relevant run is not active, you can:
  • Reinitialize the run: run = neptune.init(run="RUN_ID")
  • Enter the run id manually: model_version["run/id"] = "RUN_ID"
where RUN_ID is the Neptune id of the run. For example, PROJ-14.
3. (optional) It can also be helpful to record the URL of the run:
1
model_version["run/url"] = run.get_url()
Copied!

Result

In Neptune, the run id is logged in the run namespace of the model version.
Export as PDF
Copy link
Contents