Run

Run

A Run in Neptune is a representation of all metadata that you log to Neptune, beginning when you start a tracked run with neptune.init() and ending when the script finishes or when you explicitly stop the experiment with .stop() .

import neptune.new as neptune
# Create new experiment
run = neptune.init('my_workspace/my_project')
# Log parameters
params = {'max_epochs': 10, 'optimizer': 'Adam'}
run['parameters'] = params
# Log metadata
run['train/metric_name'].log()
run['predictions'].log(image)
run['model'].upload(path_to_model)
# Log whatever else you want
...
# Stop tracking and clean up
run.stop()

You can log many ML metadata types, including:

  • metrics,

  • losses,

  • model weights,

  • images,

  • interactive charts,

  • predictions,

  • and much more.

Have a look at the complete list of metadata types you can log.

Besides logging data, you can also download run's data to your local machine.

You can also resume the runs you have created in the past and update them or continue logging metadata to them.

[] (field lookup)

You can access any run's field through a dict-like field lookup run[field_path].

This way you can both track metadata:

run['params/max_epochs'] = 20
for epoch in range(20):
run['epoch/acc'].log(epoch_accuracy)

As well as fetch already tracked metadata - fetching parameters when resuming a run or downloading metadata for a custom analysis:

learning_rate = run['params/lr'].fetch()
run['train/diagnostic_plots'].download()
acc_df = run['train/epoch/acc'].fetch_values()

Returns

The returned type depends on the field's type and whether a field is stored under the given path

Field

Returns

The field exists.

The returned type matches type of the field.

The field does not exist

Handler object

The path is a namespace e.g. train when a field train/acc exists.

Namespace handler object

Examples

import neptune.new as neptune
run = neptune.init('my_workspace/my_project')
# Create new Float field
run['parameters/momentum'] = 0.9
# Update value of the field
run['parameters/momentum'] = 0.8
# Error - it's impossible to store a File under Float field
run['parameters/momentum'].upload('sample_data.csv') # Error
# Create new Series fields
run['train/logs'].log('Experimenting Day 1:')
run['train/acc'].log(0.01)
# Continue logging to existing Series fields
run['train/logs'].log('I embark on a journey')
run['train/acc'].log(0.02)
# If you access a Namespace handler
# you can interact with it in a similar way
# to the Run object
params_ns = run['parameters']
params_ns['lr'] = 0.3 # Stores 0.3 under path 'parameters/lr'

=

Convenience alias for .assign().

.assign()

Assign values to multiple fields from a dictionary. You can use this method to quickly log all run's parameters.

Parameters

value

(dict ) - A dictionary with values to assign, where keys become the paths of the fields.

The dictionary can be nested - in such case the path will be a combination of all keys.

wait

(Boolean, optional, default is False) - If True the client will first wait to send all tracked metadata to the server. This makes the call synchronous, see Connection modes guide.

Examples

import neptune.new as neptune
run = neptune.init()
# Assign multiple fields from a dictionary
params = {"max_epochs": 10, "optimizer": "Adam"}
run["parameters"] = params
# You can always log explicitely parameters one by one
run["parameters/max_epochs"] = 10
run["parameters/optimizer"] = "Adam"
# Dictionaries can be nested
params = {"train": {"max_epochs": 10}}
run["parameters"] = params
# This will log 10 under path "parameters/train/max_epochs"

Pretty prints the structure of the run's metadata. Paths are ordered lexicographically and the whole structure is neatly colored.

See also: .get_structure().

.get_structure()

Returns a run's metadata structure in form of a dictionary.

This method can be used to traverse the run's metadata structure programmatically when using Neptune in automated workflows.

See also: .print_structure().

The returned object is a shallow copy of an internal run's structure. Any modifications to it may result in tracking malfunction.

Returns

dict with the run's metadata structure.

.pop()

Removes the field stored under the path completely and all data associated with it.

Parameters

path

(str ) - Path of the field to be removed.

wait

(Boolean, optional, default is True) - If True the client will first wait to send all tracked metadata to the server. This makes the call synchronous, see Connection modes guide.

Examples

import neptune.new as neptune
run = neptune.init()
run['parameters/learninggg_rata'] = 0.3
# Delete a field along with it's data
run.pop('parameters/learninggg_rata')
run['parameters/learning_rate'] = 0.3
# Training finished
run['trained_model'].upload('model.pt')
# 'model_checkpoint' is a File field
run.pop('model_checkpoint')

.stop()

Stops the tracked run and kills the synchronization thread. .stop() will be automatically called when a script that created the run finishes or on the destruction of Neptune context. When using Neptune with Jupyter notebooks it's a good practice to stop the tracked run manually as it will be stopped automatically only when the Jupyter kernel stops.

Parameters

seconds

(int or float, optional, default is None) - The method will wait for the specified time for all tracking calls to finish, before stopping the tracked run. If None will wait for all tracking calls to finish.

Example

If you are creating tracked runs from the script you don't need to call .stop():

import neptune.new as neptune
run = neptune.init()
[...] # Your training or monitoring code
# If you are executing Python script .stop()
# is automatically called at the end for every run

If you are performing multiple training jobs from one script one after the other it is a good practice to .stop() the finished tracked runs as every open run keeps an open connection with Neptune, monitors hardware usage, etc. You can also use Context Managers - Neptune will automatically call .stop()on the destruction of Run context:

import neptune.new as neptune
# If you are running consecutibe training jobs from the same script
# stop the tracked runs manually at the end of single training job
for config in configs:
run = neptune.init()
[...] # Your training or monitoring code
run.stop()
# You can also use with statement and context manager
for config in configs:
with neptune.init() as run:
[...] # Your training or monitoring code
# .stop() is automatically called
# when code execution exits the with statement

If you are using Jupyter notebooks for creating your runs you need to manually invoke .stop() once the training and evaluation is done.

.wait()

Wait for all the tracking calls to finish.

Parameters

disk_only

(Boolean, optional, default is False) - If True the process will only wait for data to be saved locally from memory, but will not wait for them to reach Neptune servers.

.sync()

Synchronizes local representation of the run with Neptune servers.

Parameters

wait

(Boolean, optional, default is True) - If True the client will first wait to send all tracked metadata to the server. This makes the call synchronous, see Connection modes guide.