Edit on GitHub


def log_metric(
    name: str,
    val: Union[int, float, str],
    timestamp: bool = False,
    plot: Optional[bool] = True


from dvclive import Live

with Live() as live:
    live.log_metric("train/loss", 0.4)
    live.log_metric("val/loss", 0.9)


On each Live.log_metric(name, val) call DVCLive will create a metrics history file in {Live.plots_dir}/metrics/{name}.tsv:

โ”œโ”€โ”€ metrics.json
โ””โ”€โ”€ plots
    โ””โ”€โ”€ metrics
        โ”œโ”€โ”€ train
        โ”‚   โ””โ”€โ”€ loss.tsv
        โ””โ”€โ”€ val
            โ””โ”€โ”€ loss.tsv
$ cat dvclive/plots/metrics/train/loss.tsv
timestamp      step  loss
1623671484747  0     0.4

The metrics history can be visualized with dvc plots:

$ dvc plots diff dvclive/plots

Each subsequent call to Live.log_metric(name, val) will add a new row to {Live.plots_dir}/metrics/{name}.tsv:

live.log_metric("train/loss", 0.2, timestamp=True)
live.log_metric("val/loss", 0.4, timestamp=True)
timestamp      step  loss
1623671484747  0     0.4
1623671484892  1     0.2

In addition, DVCLive will store the latest value logged in Live.summary, so it can be serialized with calls to Live.make_summary(), Live.next_step() or when exiting the with block:

  "step": 1,
  "train": {
    "loss": 0.2
  "val": {
    "loss": 0.4

The metrics summary can be visualized with dvc metrics:

$ dvc metrics diff dvclive/metrics.json


  • name - name of the metric being logged.

  • val - the value to be logged.

  • timestamp - whether to automatically log timestamp in the metrics history file.

  • plot - whether to add the metric value to the metrics history file for plotting. If False, the metric will only be saved to the metrics summary.


  • dvclive.error.InvalidDataTypeError - thrown if the provided val does not have a supported type.

๐Ÿ› Found an issue? Let us know! Or fix it:

Edit on GitHub

โ“ Have a question? Join our chat, we will help you:

Discord Chat