question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[CLI] Cannot pass init_args to override config file

See original GitHub issue

🐛 Bug

Suppose I have a CLI configuration file, but I have no way to modify the Datamodule or Model init_args in it via command line arguments.

To Reproduce

I thought the traceback is clear enough, so I don’t reproduce with a BoringModel. If you really need it, please let me know.

Here is the reproduce steps:

  1. git clone https://github.com/tshu-w/lightning-template.git
  2. conda create -n env python=3.9 && conda activate env && pip install -r requirements.txt
  3. make sure run fit --config configs/mrpc.yaml --print_config=skip_null works fine.
  4. run fit --config configs/mrpc.yaml --data.batch_size=64 --print_config=skip_null raise error.

Traceback

Traceback (most recent call last):
  File "/home1/wangtianshu/lightning-template/run", line 33, in <module>
    main()
  File "/home1/wangtianshu/lightning-template/run", line 20, in main
    cli = LitCLI(
  File "/home1/wangtianshu/.local/share/conda/envs/template/lib/python3.9/site-packages/pytorch_lightning/utilities/cli.py", line 516, in __init__
    self.parse_arguments(self.parser)
  File "/home1/wangtianshu/.local/share/conda/envs/template/lib/python3.9/site-packages/pytorch_lightning/utilities/cli.py", line 655, in parse_arguments
    self.config = parser.parse_args()
  File "/home1/wangtianshu/.local/share/conda/envs/template/lib/python3.9/site-packages/pytorch_lightning/utilities/cli.py", line 230, in parse_args
    argv = self._convert_argv_issue_84(classes, k, argv)
  File "/home1/wangtianshu/.local/share/conda/envs/template/lib/python3.9/site-packages/pytorch_lightning/utilities/cli.py", line 290, in _convert_argv_issue_84
    class_path = passed_args[f"{argv_key}.class_path"]
KeyError: '--data.class_path'

Expected behavior

run fit --config configs/mrpc.yaml --data.batch_size=64 --print_config=skip_null works correctly.

Environment

  • Packages:
    • numpy: 1.22.2
    • pyTorch_debug: False
    • pyTorch_version: 1.11.0+cu113
    • pytorch-lightning: 1.5.10
    • tqdm: 4.63.0
  • System:
    • OS: Linux
    • architecture:
      • 64bit
      • ELF
    • processor: x86_64
    • python: 3.9.7
    • version: #219-Ubuntu SMP Tue Aug 11 12:26:50 UTC 2020

cc @borda @carmocca @mauvilsa

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
carmoccacommented, Apr 1, 2022

Opened that report in a separate issue @quancs

0reactions
quancscommented, Apr 1, 2022

Opened that report in a separate issue @quancs

I thought my problem is relavant to this one (both related with init_args, and may have the same solution), so I posted it in this issue. Anyway, thank you for moving it. ^^

Read more comments on GitHub >

github_iconTop Results From Across the Web

Subclass init_args overwritten with multiple config files #89
It works from the commandline, i.e. --trainer.init_args.<param> will overwrite the trainer <param> , but it doesn't work for multiple ...
Read more >
How do I override Git configuration options by command line ...
Yes, you can pass it with -c , like: git -c http.proxy=someproxy clone https://github.com/user/repo.git.
Read more >
Overriding the Configuration File from the CLI
The --co option enables you to override the configuration file from the command line, so you can change parameters on the fly as...
Read more >
jsonargparse — jsonargparse documentation
The default config files are always parsed first, this means that any command line argument will override its values. It is also possible...
Read more >
AWS CLI Configuration Variables - AWS Documentation
The AWS CLI config file, which defaults to ~/.aws/config has the ... will override the credentials located in the profile provided by AWS_PROFILE...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found