Skip to content

Manage the model stage#

Using runs#

This example assumes using tags to indicate model stage.

To change the model stage:

  1. Initialize the run representing the model:

    import neptune
    
    run = neptune.init_run(
        with_id="CLS-56", # (1)!
    )
    
    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()
      'CLS-26'
      
    • If you set a custom run ID, it's stored at sys/custom_run_id:

      >>> run["sys/custom_run_id"].fetch()
      'vigilant-puffin-20bt9'
      
  2. Delete the tag for the previous stage:

    run["sys/tags"].remove("staging")
    
  3. Add the tag for the new stage:

    run["sys/tags"].add("production")
    
  4. To stop the connection to Neptune and sync all data, call the stop() method:

    run.stop()
    

Conditionally changing the stage#

You can make the stage transition conditional by fetching the relevant metadata from the run and checking the value.

The following code snippet fetches an accuracy value from the logged metrics, then compares it against a threshold of 0.9 before making the change:

run = neptune.init_run(with_id="CLS-56")

val_acc = run["validation/acc"].fetch()

if val_acc <= 0.7:
    run["sys/tags"].remove("staging")
    run["sys/tags"].add("archived")

Using model registry#

Manage model metadata with experiments

We recommend using runs to manage model metadata. Runs come with extra features such as group tags, custom views, and dashboards, offering rich comparison and visualization support.

For details, see Logging model metadata with runs.

You can manage the stage transitions of each model version separately.

The available stages are:

  • None (default)
  • Staging
  • Production
  • Archived

Changing the stage in the app#

  1. Navigate to your models through the project menu (left nav → Models).
  2. Click a model in the table to access its versions.
  3. In the Stage column next to the model version ID, click the stage drop-down and select a different stage from the list.
  4. To confirm the transition, in the dialog that opens, click Change stage.

Changing the stage through the API#

  1. Initialize a Neptune model version by passing the ID of an existing version:

    import neptune
    
    model_version = neptune.init_model_version(
        with_id="CLS-PRE-4",
    )
    
    How do I find the ID?

    The Neptune ID is a unique identifier for the object. It's shown in the leftmost column of the table view.

    The ID is stored in the system namespace, in the "sys/id" field.

  2. Pass the desired stage to the change_stage() method of the model version object:

    model_version.change_stage("staging")
    

    Tip

    This method is synchronous, which means that the stage is changed as soon as the line is executed.

  3. To stop the connection to Neptune and sync all data, call the stop() method and execute the script or cell:

    model_version.stop()