-
-
Notifications
You must be signed in to change notification settings - Fork 62
Experimental omegaconf+ parser mode that supports interpolation across configs and arguments #765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…cross configs and command line arguments (#461).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #765 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 6933 6966 +33
=========================================
+ Hits 6933 6966 +33 ☔ View full report in Codecov by Sentry. |
…ffect Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! It's a great feature.
I tried with my codebase and one big issue is that the "key path" is now absolute instead of local to the file.
For instance, before this worked
python my_jsonargparse_cli.py --job_config=job_config.yaml
And job_config.yaml example:
foo:
f: ${bar.b}
bar:
b: 123But with this change, it requires the following
foo:
f: ${job_config.bar.b}
bar:
b: 123Is this expected? This job config key is under a nested key like so
parser = new_parser(add_config=True)
parser.add_function_arguments(launch, skip={"filepath", "job_config"})
parser.add_class_arguments(JobConfigDataclass, nested_key="job_config", instantiate=False)Not being backwards compatible is a problem for seamlessly upgraing to omegaconf+
|
Also, following my own recipe as described in #479 (comment). The following breaks with class Foo:
def __init__(self, f=2):
...
class Bar:
def __init__(self, b=3):
...
def fn(foo: Foo = Foo(), bar: Bar = Bar()):
...
from jsonargparse import ArgumentParser, ActionConfigFile
from jsonargparse import get_loader, set_loader
def enable_backwards_compatibility(parser: ArgumentParser) -> None:
loader = get_loader(mode=parser.parser_mode)
def custom(config_input: str):
return loader(config_input)
set_loader("backwards_compatibility_loader", custom)
parser.parser_mode = "backwards_compatibility_loader"
parser = ArgumentParser(parser_mode="omegaconf+") # <- change this
enable_backwards_compatibility(parser)
parser.add_argument("-c", "--config", action=ActionConfigFile)
parser.add_function_arguments(fn)
args = parser.parse_args()
print(args)foo:
class_path: __main__.Foo
init_args:
f: ${bar.init_args.b}
bar:
class_path: __main__.Bar
init_args:
b: -3python repro.py --config=config.yamlBefore it would print Namespace(config=[Path_fr(config.yaml, cwd=/home/ubuntu/carlos/titan)], foo=Namespace(class_path='__main__.Foo', init_args=Namespace(f=-3)), bar=Namespace(class_path='__main__.Bar', init_args=Namespace(b=-3)))But with Namespace(config=[Path_fr(config.yaml, cwd=/home/ubuntu/carlos/titan)], foo=Namespace(class_path='__main__.Foo', init_args=Namespace(f='${bar.init_args.b}')), bar=Namespace(class_path='__main__.Bar', init_args=Namespace(b=-3))) |
|
@carmocca thanks for the feedback! I will take a look at it. For now
Yes, it is expected as mentioned in experimental-omegaconf-mode. That is why I implemented it as a separate This feature had been around for long and this is how I finally found a way to implement it. And the key paths didn't seem to be a big issue because it is trivial to do relative. So you would need to change from |
|
Makes sense. Backwards compatibility of configs is a big deal to me so without a mechanism to "upgrade" existing input configs to use the new format (" |
Could be instead def enable_backwards_compatibility(parser: ArgumentParser) -> None:
loader = get_loader(mode=parser.parser_mode)
def custom(config_input: str):
return loader(config_input)
set_loader(parser.parser_mode, custom) |
@carmocca with #774 you can now optionally enable conversion of absolute to relative paths in interpolations. But note that there are too many possibilities of absolute paths, and this conversion will not work for every possible case. |
|
Seems to work well in my brief test. I can test more extensively when there's a wheel to deploy |



What does this PR do?
Fixes #439
Fixes #461
Fixes Lightning-AI/pytorch-lightning#13607
Fixes Lightning-AI/pytorch-lightning#15109
Fixes Lightning-AI/pytorch-lightning#20722
Before submitting