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
Dictionary of metrics to log. Each metric value is associated with a step. To log multiple metrics at once, pass multiple key-value pairs.
Index of the log entry. Must be increasing if preview=False
.
Tip: Using float rather than int values can be useful, for example, when logging substeps in a batch.
Time 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.
Whether the logged metrics are preview values.
A value between 0 and 1 that indicates the completion level of the metric computation. Higher value reflects a higher level of completion.
Ignored if preview
is set to False
.
Step requirements
-
Within a particular metric, steps must be increasing.
- Steps can be logged out of order only if the value is a preview value logged after the last regular step.
-
In fork runs, the step can't be smaller than the fork step. For details, see Fork an experiment.
-
For examples, see Log metrics: Setting step values.
Exceptions
Neptune may warn or 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
warning. This doesn't terminate the training process.
This step order requirement doesn't apply to preview values. For example, you can log a preview for step 10 and then again for step 9 without errors, if steps 9, 10, and all the following steps have preview
set to True
.
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.
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,
)