Skip to main content
App version: 3.4.8

log_metrics()

Python package: neptune-scale

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 if preview=False.
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.
previewbool, optionalFalseWhether the logged metrics are preview values.
preview_completionfloat, optional0A 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

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,
)