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() .
1
import neptune.new as neptune
2
3
# Create new experiment
4
run = neptune.init('my_workspace/my_project')
5
6
# Log parameters
7
params = {'max_epochs': 10, 'optimizer': 'Adam'}
8
run['parameters'] = params
9
10
# Log metadata
11
run['train/metric_name'].log()
12
run['predictions'].log(image)
13
run['model'].upload(path_to_model)
14
15
# Log whatever else you want
16
...
17
18
# Stop tracking and clean up
19
run.stop()
Copied!
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:
1
run['params/max_epochs'] = 20
2
for epoch in range(20):
3
run['epoch/acc'].log(epoch_accuracy)
Copied!
As well as fetch already tracked metadata - fetching parameters when resuming a run or downloading metadata for a custom analysis:
1
learning_rate = run['params/lr'].fetch()
2
3
run['train/diagnostic_plots'].download()
4
acc_df = run['train/epoch/acc'].fetch_values()
Copied!

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 field does not exist
Handler object
The path is a namespace e.g. train when a field train/acc exists.

Examples

1
import neptune.new as neptune
2
run = neptune.init('my_workspace/my_project')
3
4
# Create new Float field
5
run['parameters/momentum'] = 0.9
6
7
# Update value of the field
8
run['parameters/momentum'] = 0.8
9
10
# Error - it's impossible to store a File under Float field
11
run['parameters/momentum'].upload('sample_data.csv') # Error
12
13
# Create new Series fields
14
run['train/logs'].log('Experimenting Day 1:')
15
run['train/acc'].log(0.01)
16
17
# Continue logging to existing Series fields
18
run['train/logs'].log('I embark on a journey')
19
run['train/acc'].log(0.02)
20
21
# If you access a Namespace handler
22
# you can interact with it in a similar way
23
# to the Run object
24
params_ns = run['parameters']
25
params_ns['lr'] = 0.3 # Stores 0.3 under path 'parameters/lr'
Copied!

=

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

1
import neptune.new as neptune
2
run = neptune.init()
3
4
# Assign multiple fields from a dictionary
5
params = {"max_epochs": 10, "optimizer": "Adam"}
6
run["parameters"] = params
7
8
# You can always log explicitely parameters one by one
9
run["parameters/max_epochs"] = 10
10
run["parameters/optimizer"] = "Adam"
11
12
# Dictionaries can be nested
13
params = {"train": {"max_epochs": 10}}
14
run["parameters"] = params
15
# This will log 10 under path "parameters/train/max_epochs"
Copied!

.print_structure()

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.
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.

.get_run_url()

Returns a direct link to run in Neptune. It's the same link that is printed at the moment of initialization of the run.

Returns

str with the URL of the run in Neptune

del

Removes the field or whole namespace stored under the path completely and all data associated with them. See also .pop().

Examples

1
import neptune.new as neptune
2
run = neptune.init()
3
4
params = {"max_epochs": 10, "optimizer": "Adam"}
5
run['model/parameters'] = params
6
7
# Delete a field with path 'model/parameters/optimizer'
8
del run['model/parameters/optimizer']
9
10
# You can also delete whole namespace
11
del run['model/parameters']
Copied!
You can also use del to remove from existing runs unneeded metadata that takes a lot of space such as training checkpoints:
1
import neptune.new as neptune
2
3
# Resume an existing run
4
run = neptune.init(run="ACC-47")
5
6
# Delete the namespace "training/checkpoints" with the training checkpoint
7
del run["training/checkpoints"]
Copied!

.pop()

Removes the field or whole namespace stored under the path completely and all data associated with them. See also .del().
Parameters
path
(str ) - Path of the field or namespace 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

1
import neptune.new as neptune
2
run = neptune.init()
3
4
run['parameters/learninggg_rata'] = 0.3
5
6
# Delete a field along with it's data
7
run.pop('parameters/learninggg_rata')
8
9
run['parameters/learning_rate'] = 0.3
10
11
12
# Training finished
13
run['trained_model'].upload('model.pt')
14
# 'model_checkpoint' is a File field
15
run.pop('model_checkpoint')
16
17
18
# .pop() can be invoked directly on fields and namespaces
19
20
# Following line
21
run.pop('parameters/learninggg_rata')
22
# is equiavlent to this line
23
run['parameters/learninggg_rata'].pop()
24
# or this line
25
run['parameters'].pop('learninggg_rata')
26
27
# You can also delete in batch whole namespace
28
run['parameters'].pop()
Copied!

.exists()

Checks if there is any field or namespace under the specified path.
Note that this method checks the local representation of the run. The field may have been created by another process (use .sync() to synchronize local representation) or the metadata may have not reached the Neptune servers so it may be impossible to fetch (use .wait() to wait for all tracking calls to finish).
Parameters
path
(str) - The path to check for the existence of a field or a namespace

Examples

1
import neptune.new as neptune
2
3
# Resume a run with a SAN-34 identifier
4
run = neptune.init(run="SAN-34")
5
6
# If the training is complete remove training checkpoints if they are there
7
if run.exists("model/checkpoints") and run["train/finished"].fetch() == True:
8
del run['model/checkpoints']
Copied!
When working in the asynchronous (default) mode remember that metadata you track may not be available immediately to fetch from the server even if it appears in the local representation. In order to prevent that you can use .wait().
1
import neptune.new as neptune
2
run = neptune.init()
3
4
run["learning_rate"] = 0.1
5
6
# The path exists in the local representation
7
if run.exists("learning_rate"):
8
# However, the tracking call may have not reached Neptune servers yet
9
run["learning_rate"].fetch() # Error - the field does not exist
Copied!

.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():
1
import neptune.new as neptune
2
run = neptune.init()
3
4
[...] # Your training or monitoring code
5
6
# If you are executing Python script .stop()
7
# is automatically called at the end for every run
Copied!
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:
1
import neptune.new as neptune
2
3
# If you are running consecutibe training jobs from the same script
4
# stop the tracked runs manually at the end of single training job
5
for config in configs:
6
run = neptune.init()
7
[...] # Your training or monitoring code
8
run.stop()
9
10
# You can also use with statement and context manager
11
for config in configs:
12
with neptune.init() as run:
13
[...] # Your training or monitoring code
14
# .stop() is automatically called
15
# when code execution exits the with statement
Copied!
If you are using Jupyter notebooks for creating your runs you need to manually invoke .stop() once the training and evaluation is done.

.fetch()

Fetch values of all non-File Atom fields as a dictionary.
The result will preserve the hierarchical structure of the run's metadata but will contain only non-File Atom fields. You can use this method e.g. to quickly retrieve run parameters.

Returns

dict containing all non-File Atom fields values.

Examples

1
import neptune.new as neptune
2
3
# Resume run with SUN-123 identifier
4
run = neptune.init(project="my_workspace/my_project", run="SUN-123")
5
6
# Fetch the runs parameters
7
params = run["model/params"].fetch()
Copied!

.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.

Examples

1
import neptune.new as neptune
2
3
# Connect to a run from Worker #3
4
worker_id = 3
5
run = neptune.init(run='DIST-43', monitoring_namespace='monitoring/{}'.format(worker_id))
6
7
# Try to access logs that were created in meantime by Worker #2
8
worker_2_status = run['status/2'].fetch() # Error if this field was created after this script starts
9
10
run.sync() # Synchronizes local representation with Neptune servers.
11
worker_2_status = run['status/2'].fetch() # No error
Copied!
Last modified 1mo ago