Skip to main content

Run

Python package: neptune-scale

Representation of experiment tracking run logged with Neptune Scale.

Initialization

Initialize with the class constructor:

from neptune_scale import Run

run = Run(...)

Or with a context manager:

from neptune_scale import Run

with Run(...) as run:
...

Parameters

NameTypeDefaultDescription
run_idstr-Identifier of the run. Must be unique within the project. Max length: 128 bytes.
projectstr, optionalNone Name of a project in the form workspace-name/project-name. If None, the value of the NEPTUNE_PROJECT environment variable is used.
api_tokenstr, optionalNoneYour Neptune API token or a service account's API token. If None, the value of the NEPTUNE_API_TOKEN environment variable is used. To keep your token secure, don't place it in source code. Instead, save it as an environment variable.
resumebool, optionalFalseIf False, creates a new run.
To continue an existing run, set to True and pass the ID of an existing run to the run_id argument. To fork a run, use fork_run_id and fork_step instead.
mode"async" or "disabled""async"Mode of operation. If set to "disabled", the run doesn't log any metadata.
experiment_namestr, optionalNoneName of the experiment to associate the run with.
creation_timedatetime, optionaldatetime.now()Custom creation time of the run. If not provided, the current time is used. If provided, and timestamp.tzinfo is not set, the time is assumed to be in the local timezone.
fork_run_idstr, optionalNoneThe ID of the run to fork from.
fork_stepint, optionalNoneThe step number to fork from.
max_queue_sizeint, optional1000000Maximum number of operations queued for processing. 1 000 000 by default. You should raise this value if you see the on_queue_full_callback function being called.
on_queue_full_callbackCallable[[BaseException, Optional[float]], None], optionalNoneCallback function triggered when the queue is full. The function must take as an argument the exception that made the queue full and, as an optional argument, a timestamp of when the exception was last raised.
on_network_error_callbackCallable[[BaseException, Optional[float]], None], optionalNoneCallback function triggered when a network error occurs.
on_error_callbackCallable[[BaseException, Optional[float]], None], optionalNoneThe default callback function triggered when an unrecoverable error occurs. Applies if an error wasn't caught by other callbacks. In this callback you can choose to perform your cleanup operations and close the training script. For how to end the run in this case, use terminate().
on_warning_callbackCallable[[BaseException, Optional[float]], None], optionalNoneCallback function triggered when a warning occurs.

Examples

Create a run:

from neptune_scale import Run

with Run(
run_id="likable-barracuda",
experiment_name="swim-further",
) as run:
...

Create a run and pass Neptune credentials as arguments:

from neptune_scale import Run

with Run(
project="team-alpha/project-x",
api_token="h0dHBzOi8aHR0cHM6...Y2MifQ==",
run_id="likable-barracuda",
experiment_name="swim-further",
) as run:
...

For help, see Create an experiment.

To restart (fork) an experiment, create a forked run:

with Run(
run_id="adventurous-barracuda",
experiment_name="swim-further",
fork_run_id="likable-barracuda",
fork_step=102,
) as run:
...

Resume a run:

with Run(
run_id="likable-barracuda", # a Neptune run with this ID already exists
resume=True,
) as run:
...

Create a non-experiment run:

with Run(run_id="likable-barracuda") as run:
...
note

Forking and history is only supported for experiment runs.

To take advantage of these and other features that concern analysis of multiple related runs, create experiments rather than stand-alone runs.



log_configs()

Logs the specified metadata to a Neptune run.

You can log configurations or other single values. Pass the metadata as a dictionary {key: value} with:

  • key: path to where the metadata should be stored in the run.
  • value: the piece of metadata to log.

For example, {"parameters/learning_rate": 0.001}. In the attribute path, each forward slash / nests the attribute under a namespace. Use namespaces to structure the metadata into meaningful categories.

Parameters

NameTypeDefaultDescription
dataDict[str, Union[float, bool, int, str, datetime, list, set, tuple]], optionalNoneDictionary of configs or other values to log.

Example

Create a run and log metadata:

from neptune_scale import Run

with Run(...) as run:
run.log_configs(
data={
"parameters/learning_rate": 0.001,
"parameters/batch_size": 64,
},
)


log_metrics()

Logs the specified metrics to a Neptune run.

You can log metrics representing a series of numeric values. Pass the metadata as a dictionary {key: value} with:

  • key: path to where the metadata should be stored in the run.
  • value: the piece of metadata to log.

For example, {"metrics/accuracy": 0.89}. In the attribute path, each forward slash / nests the attribute under a namespace. Use namespaces to structure the metadata into meaningful categories.

Parameters

NameTypeDefaultDescription
dataDict[str, Union[float, int]]NoneDictionary of metrics to log. Each metric value is associated with a step. To log multiple metrics at once, pass multiple key-value pairs.
stepUnion[float, int]NoneIndex of the log entry. Must be increasing.
Tip: Using float rather than int values can be useful, for example, when logging substeps in a batch.
timestampdatetime, optionalNoneTime of logging the metadata. If not provided, the current time is used. If provided, and timestamp.tzinfo is not set, the time is assumed to be in the local timezone.

Example

Create a run and log metrics:

from neptune_scale import Run

with Run(...) as run:
run.log_metrics(
data={"loss": 0.14, "acc": 0.78},
step=1.2,
)

Note: To correlate logged values, make sure to send all metadata related to a step in a single log_metrics() call, or specify the step explicitly.

When the run is forked off an existing one, the step can't be smaller than the step value of the fork point.



add_tags()

Adds the list of tags to the run.

Parameters

NameTypeDefaultDescription
tagsUnion[List[str], Set[str], Tuple[str]]-List or set of tags to add to the run.
group_tagsbool, optionalFalseAdd group tags instead of regular tags.

Example

with Run(...) as run:
run.add_tags(tags=["tag1", "tag2", "tag3"])


remove_tags()

Removes the specified tags from the run.

Parameters

NameTypeDefaultDescription
tagsUnion[List[str], Set[str], Tuple[str]]-List or set of tags to remove from the run.
group_tagsbool, optionalFalseRemove group tags instead of regular tags.

Example

with Run(...) as run:
run.remove_tags(tags=["tag2", "tag3"])


wait_for_submission()

Waits until all metadata is submitted to Neptune for processing.

When submitted, the data is not yet saved in Neptune. See also wait_for_processing().

Parameters

NameTypeDefaultDescription
timeoutfloat, optionalNoneIn seconds, the maximum time to wait for submission.
verbosebool, optionalTrueIf True, prints messages about the waiting process.

Example

from neptune_scale import Run

with Run(...) as run:
run.log_configs(...)
...
run.wait_for_submission()
run.log_metrics(...) # called once queued Neptune operations have been submitted


wait_for_processing()

Waits until all metadata is processed by Neptune.

Once the call is complete, the data is saved in Neptune.

Parameters

NameTypeDefaultDescription
timeoutfloat, optionalNoneIn seconds, the maximum time to wait for processing.
verbosebool, optionalTrueIf True, prints messages about the waiting process.

Example

from neptune_scale import Run

with Run(...) as run:
run.log_configs(...)
...
run.wait_for_processing()
run.log_metrics(...) # called once submitted data has been processed


close()

The regular way to end a run. Waits for all locally queued data to be processed by Neptune and closes the run. See also wait_for_processing().

This is a blocking operation. Call the function at the end of your script, after your model training is completed.

Example

from neptune_scale import Run

run = Run(...)

# [your logging and training code]

run.close()

If using a context manager, Neptune automatically closes the run upon exiting the context:

with Run(...) as run:
...

# run is closed at the end of the context


terminate()

In case of an unrecoverable error, you can terminate the failed run in your error callback.

This effectively disables processing in-flight operations as well as logging new data. However, the training process isn't interrupted.

Example

from neptune_scale import Run

def my_error_callback(exc):
run.terminate()


run = Run(..., on_error_callback=my_error_callback)