Skip to content

DVC magic

Paweł Redzyński edited this page Jan 4, 2021 · 6 revisions

Configurationless dvc integration example

Usually in loggers one need to "initialize" the logger/experiment, in order to save the logs. With dvc and dvclive user can go straight to logging.

train.py:

import dvclive
import time

def get_params():
    from ruamel.yaml import YAML
    yaml = YAML(typ="safe")
    params_path = "params.yaml"
    with open(params_path, "r") as fd:
        return yaml.load(fd)

def metric(i):
    p = float(get_params()["power"])
    return 1 - 1/(1+i**p)

def loss(i):
    return 1-(metric(i))


if __name__ == "__main__":
    for i in range(100):
        dvclive.log("metric", metric(i))
        dvclive.log("loss", loss(i))

Note that we are not calling init, nor next_epoch

Install dvc from dvclive branch on main repo.

  1. Copy train.py
  2. echo "power: 0.2" > params.yaml
  3. git init --quiet && dvc init --quiet
  4. git add -A && git commit -m "initial"
  5. dvc run -n train --params power -d train.py --live training_logs python train.py
  6. git add -A && git commit -am "baseline"
  7. echo "power: 0.4" > params.yaml && dvc repro train
  8. dvc plots diff

We end up having training_logs inside our repo.

Clone this wiki locally