Skip to content

LightningCLI: Variable interpolation and command line arguments #13607

@mikcnt

Description

@mikcnt

🐛 Bug

Hi! I'm not sure this is actually a bug or if the one doing something wrong, but here's the problem.

I'm using OmegaConf’s variable interpolation to link one parameter in the configuration file to a second one, which I want to provide with the command line. The problem is that, when using the command line to provide one of the two parameters, the second one, linked to the first one with variable interpolation, doesn't change.

To Reproduce

  1. config.yaml
foo: default_value
bar: ${foo}
  1. main.py
from pytorch_lightning.utilities.cli import LightningCLI

class MyLightningCLI(LightningCLI):
    def add_arguments_to_parser(self, parser):
        parser.add_argument("--foo", type=str)
        parser.add_argument("--bar", type=str)


if __name__ == "__main__":
    cli = MyLightningCLI(parser_kwargs={"parser_mode": "omegaconf"})
  1. Run
python main.py fit \
    --config=config.yaml \
    --foo=some_value \
    --print_config
  1. Result

The result of this is that the foo parameter is equal to the value assigned with the command line, some_value, but the bar parameter isn't, and it is instead keeping its default value set in the config file (default_value).

seed_everything: null
trainer:
  logger: true
  checkpoint_callback: null
  ...
foo: some_value
bar: default_value
...

Expected behavior

I expected the bar parameter to be equal to the foo parameter, that is to have the value some_value:

seed_everything: null
trainer:
  logger: true
  checkpoint_callback: null
  ...
foo: some_value
bar: some_value
...

Environment

  • PyTorch Lightning Version (e.g., 1.5.0): 1.6.4
  • PyTorch Version (e.g., 1.10): 1.10.2
  • Python version (e.g., 3.9): 3.9
  • OS (e.g., Linux): Mac
  • GPU models and configuration: None (CPU)
  • How you installed PyTorch (conda, pip, source): pip

cc @carmocca @mauvilsa @akihironitta

Metadata

Metadata

Assignees

No one assigned

    Labels

    3rd partyRelated to a 3rd-partylightningclipl.cli.LightningCLIplGeneric label for PyTorch Lightning packagequestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions