Skip to main content
App version: 3.4.5

Log metrics

A metric can be accuracy, MSE, or any numerical value. Neptune displays all float series as charts.

To log a numerical series, use the log_metrics() function:

from neptune_scale import Run

run = Run()

for step in epoch:
# your training loop
run.log_metrics(
data={"acc": 0.78},
step=step,
)
info

Neptune supports 64-bit floating-point numbers, which have a precision of 16 digits.

To log multiple metrics in a single call, pass multple key-value pairs to the data dictionary:

run.log_metrics(
data={"loss": 0.13, "acc": 0.79},
step=step,
)

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.

Setting custom step values

You can specify custom index values with the step argument:

run.log_metrics(
data={"loss": 0.13, "acc": 0.79},
step=2,
)

The step argument can be an int or float value.

Float values can be useful, for example, as substeps:

run.log_metrics(
data={"loss": 0.11, "acc": 0.81},
step=2.1,
)

Setting custom timestamp

To provide a custom timestamp, pass a Python datetime value to the timestamp argument:

run.log_metrics(
data=...,
step=...,
timestamp=datetime.utcnow(),
)

If the timestamp argument isn't provided, the current time is used.

note

If timestamp.tzinfo is not set, the time is assumed to be in the local timezone.

Logging metrics to fork runs

When forking a run, metrics are inherited up until and including the step specified as the fork point.

For details, see Fork an experiment.

Error handling

Neptune may raise exceptions if there are malformed or inconsistent values.

Non-increasing steps

If steps logged to the client are not increasing, Neptune raises the NeptuneSeriesStepNonIncreasing exception. This triggers the default on_error_callback, which terminates the training process.

You can override the default behavior by implementing your own callbacks to handle error scenarios. For details, see Neptune API error handling.

Non-finite values

By default, Neptune skips non-finite values such as Inf and NaN when logging a series. To raise an exception when such values are encountered, set the NEPTUNE_SKIP_NON_FINITE_METRICS environment variable to False:

Append a line with the export command to your .profile or other shell initialization file:

export NEPTUNE_SKIP_NON_FINITE_METRICS=False