-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Nested class instantiation fails for classes with typehints unsupported by jsonargparse
#337
Comments
@mauvilsa Any feedback regarding this? I'm sure you've got a lot on your plate. Thanks again for maintaining this incredibly useful package! |
Indeed I have been busy. I do have some comments.
|
No worries, thanks for the thoughtful reply!
After your feedback, returning to the original issue I was debugging (not the simplified pytest repro I wrote but using
Nice! I'll definitely keep that in mind, I think Lightning should do that to avoid the ugly strings still being used in many places, not sure if you've discussed that with them but given they aren't supporting Python < 3.7, I don't see a reason they couldn't use that more extensively (once the current version of
Makes sense, I was thinking an optional trade-off (possibly enabled with an env variable) of providing a user-facing warning to highlight the issue but then relaxing the type constraint and allowing execution was a compromise that could continue offering much of the rigor/value Anyway, please let me know if you have any thoughts on a better workaround other than suggesting Lightning remove the |
Importing types inside a
I tried to add future annotations to lightning but it is not so easy. First I tried for the entire lightning package and there were many issues. For example one problem was that pydantic does not backport PEP 585 and 604 types in python 3.7-3.9, so things fail. I also tried only for It might be possible to add future annotations to |
While waiting for this use case to be supported, do you have any suggested workaround that would allow this fine-tuning profiling example for (finetuning-scheduler), to continue using the error: Parser key "trainer.strategy":
Does not validate against any of the Union subtypes
Subtypes: (<class 'str'>, <class 'lightning.pytorch.strategies.strategy.Strategy'>)
Errors:
- Expected a <class 'str'>
- Problem with given class_path 'lightning.pytorch.strategies.FSDPStrategy':
'Configuration check failed :: No action for destination key "activation_checkpointing_policy" to check its value.' Regarding the future support for this use case, feel free to rename this issue so it better captures the issue from your perspective or let me know if I need to close this issue and open a new one. Thanks so much again for work/thoughts on this!
Makes sense, I see the challenge! |
Subclassing is the only workaround that comes to mind. Anyway, adding support for |
That's awesome, should be really useful. Thanks! |
Still work in progress, but you can try it out #344. |
Works beautifully, thanks so much for the edifying design discussion and fix! 🚀 |
…n `jsonargparse` < 4.23.1
🐛 Bug report
When attempting to instantiate a valid class configuration with a class that has typehints unsupported by
jsonargparse
(in my application's case,ForwardRef
s), the valid configuration is rejected because the unsupported typehints cannot be validated.Though the user could technically subclass the problematic class to remove the typehints or attempt to workaround the issue in a variety of ways, I think the default behavior (or at least optionally allowable behavior) should be to relax unsupported typehints rather than reject their use entirely.
In the context of attempting to instantiate an arbitrary class, I think the typical user would prefer flexibility over guaranteed typehint validation. If not the default behavior, I think toggling this behavior with either an environment variable or command-line option should be allowed since working around such issues can otherwise be unnecessarily unwieldy. This is arguably more of a feature request than a bug report feel free to change the title/classification as you deem appropriate. Thanks again for all you work on this valuable package!
To reproduce
I've written a test that can be used both to reproduce the issue and validate one approach to solving it (described below).
No action for destination key
errorjsonargparse/jsonargparse/_typehints.py
Line 218 in 6232d8e
Expected behavior
Rather than throwing a
No action for destination key "inner_mod" to check its value
error,inner_mod
should be properly instantiated and the test should pass with the desired user feedback provided indicating an unsupported typehint was relaxed (or removed if that approach is preferred etc.).Environment
pip install jsonargparse[all]
): dev install (pip install -e ".[dev,all]" -vv
)The text was updated successfully, but these errors were encountered: