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
Name | Type | Default | Description |
---|---|---|---|
data | Dict[str, Union[float, int]] | None | Dictionary of metrics to log. Each metric value is associated with a step. To log multiple metrics at once, pass multiple key-value pairs. |
step | Union[float, int] | None | 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. |
timestamp | datetime , optional | None | 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. |
preview | bool , optional | False | Whether the logged metrics are preview values. |
preview_completion | float , optional | 0 | 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 . |
Exceptions
If steps logged to the client are not increasing, Neptune raises the NeptuneSeriesStepNonIncreasing
exception and terminates the training process.
This behavior doesn't apply when logging 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.
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.