Skip to content

exp run: --set-params forces YAML 1.2 (breaks code that uses 1.1) #5971

Closed as not planned
@flippedcoder

Description

@flippedcoder

Bug Report

dvc exp run --set-param lr=0.000001

Here's the error:

Traceback (most recent call last):
  File "/Users/milecia/Repos/checkpoints-tutorial/train.py", line 123, in <module>
    main()
  File "/Users/milecia/Repos/checkpoints-tutorial/train.py", line 110, in main
    train(model, x_batch, y_batch, params["lr"], params["weight_decay"])
  File "/Users/milecia/Repos/checkpoints-tutorial/train.py", line 45, in train
    optimizer = torch.optim.Adam(model.parameters(), lr=lr,
  File "/Users/milecia/Repos/checkpoints-tutorial/.venv/lib/python3.9/site-packages/torch/optim/adam.py", line 36, in __init__
    if not 0.0 <= lr:
TypeError: '<=' not supported between instances of 'float' and 'str'

Description

The problem is that the yaml library only supports yaml 1.1 when DVC uses yaml1.2. This issue seems to happen when exponents are generated.

The data science community and the Python ecosystem in general is stuck in YAML1.1. We could try to be compatible by generating exponents with the dot at least, that way we could be compatible on both sides. I am not sure how straightforward the fix this will be though. (and this should only affect --set-param, not the dvc.lock and yaml files).

Reproduce

  1. Go to the checkpoints tutorial repo
  2. Replace from ruamel.yaml import YAML with import yaml
  3. Replace these 2 lines yaml=YAML(typ='safe') params = yaml.load(f) with params = yaml.safe_load(f)
  4. dvc exp run --set-param lr=0.000001
  5. The lr in params.yaml should be updated to an exponent and you get the error above

Expected

Running dvc exp run --set-param lr=0.000001 should start running the experiment with the new lr

Environment information

Output of dvc doctor:

DVC version: 2.1.0 (brew)
---------------------------------
Platform: Python 3.9.4 on macOS-11.3-x86_64-i386-64bit
Supports: azure, gdrive, gs, http, https, s3, ssh, oss, webdav, webdavs

Metadata

Metadata

Assignees

No one assigned

    Labels

    A: experimentsRelated to dvc expdiscussionrequires active participation to reach a conclusionenhancementEnhances DVCp3-nice-to-haveIt should be done this or next sprintproduct: VSCodeIntegration with VSCode extensionresearch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions