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,
)
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.
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.
Logging incomplete metrics
You can log partial series results and mark them as preview values.
For details, see Metric previews.
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
:
- Linux
- macOS
- Windows
Append a line with the export command to your .profile
or other shell initialization file:
export NEPTUNE_SKIP_NON_FINITE_METRICS=False
Append a line with the export command to your .profile
or other shell initialization file:
export NEPTUNE_SKIP_NON_FINITE_METRICS=False
In a terminal app, such as PowerShell or Command Prompt, enter the setx
command and press enter:
setx NEPTUNE_SKIP_NON_FINITE_METRICS False
To activate the change, restart the terminal app.
You can also navigate to Settings → Edit the system environment variables and add the variable there.