-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Refactor use of **kwargs in PL classes for better LightningCLI support #11653
Comments
I don't think (2) or (3) will happen because, from past experience, people are really allergic to having to create these extra objects. And since they would be created dynamically, users could not easily figure out what arguments can be passed and what they do. My preference is doing (1) for the popular classes used in the CLI to reap the benefits described in your pitch. |
Don't underestimate the downsides of (1). For example for If (3) is done without deprecation of the current I have just added a fourth option that could also be interesting. |
To me, a killer feature of To me, doing (2), (3), or (4) is adapting the code to fit the parser needs. If the (1) is somewhat valuable because the user avoids 1 jump to read the argument annotations and docstrings, at the cost of duplication. That's why it's my preference.
I agree. We could keep the code as-is for these tricky classes and just let go of the validation.
Could this option be done by |
Indeed this has been the objective of Going this route for certain will require way more effort and time. I have never used ast and also haven't thought it through. It might be going down a rabbit hole and introduce difficult to fix problems. Almost certain that it would not be a support for any
In my opinion it depends on the case and how you look at it. Having (2) or (3) and a parameter called
That is fine. I am just trying to list out all the possibilities so that better decisions can be made. |
I can get on board with this, but this disqualifies (2) and (3) as they would require long deprecation processes. |
I will look into ast and later let you what could be done. Regarding (1) it also has the advantage of being simple enough to be implemented by any contributor. And definitely would provide a better user experience than omni-us/jsonargparse#114. |
This issue has been automatically marked as stale because it hasn't had any recent activity. This issue will be closed in 7 days if no further activity occurs. Thank you for your contributions, Pytorch Lightning Team! |
An update about this. I have been looking at option (5). As I thought, it is considerably complex. Still, I think it will be eventually implemented in jsonargparse. Though this will take time. Thus, (1) as interim solution could be considered. |
Proposed refactor
All the
__init__
parameters from classes in the pytorch-lightning repo that are susceptible to be used viaLightningCLI
should be resolvable by jsonargparse: parameter name, type and docstring description.A list of potential classes that would be good to refactor is the following. Probably each class needs to be considered separately and some might have higher priority than others.
See Possibilities section below for ideas on how to refactor.
Motivation
This has been a recurrent issue, for example:
There is a proposal to allow specifying values for unresolved parameters which would skip validation omni-us/jsonargparse#114. The downside is no support for several nice features (see Pitch). This can be a solution for some cases. But it is not be the ideal solution, particularly for classes in the pytorch-lightning repo which can be more easily considered for modifications.
Pitch
With this refactor all features from the CLIs become available:
--print_config
.Possibilities
Add all parameters to the class. This is how several people have been solving this issue, e.g. LightningCLI: Linking arguments from model to checkpoint #9887 (comment)
**kwargs
might change, thus creating problems.Have a specific parameter with dict type. For example in the case of
TensorBoardLogger
there could be a parametersummary_writer_kwargs: Dict[str, Any]
. The existing**kwargs
would be deprecated, showing a warning if used.**kwargs
.param1=val, ...
tosummary_writer_kwargs=dict(param1=val, ...)
.Have a specific parameter with a dataclass type. For example in the case of
TensorBoardLogger
there could be a parametersummary_writer_options: SummaryWriterOptions
. The dataclass would be automatically generated from a signature, thus avoiding code duplication or discrepancies in parameters. See below possible function that could create these dataclasses.param1=val, ...
to first have an importfrom ... import SummaryWriterOptions
and then when used ... summary_writer_kwargs=SummaryWriterOptions(param1=val, ...)`.Similar to (3) but instead of a dataclass, it would be a normal class also automatically generated. The
__init__
would define the parameters, but it would ignore them. This class would be used as a parent class, so jsonargparse would resolve the parameters via inheritance. For example forTensorBoardLogger
the definition could be something likeclass TensorBoardLogger(SummaryWriterOptions, LightningLoggerBase):
.Extend the support of
**kwargs
parameter discovery in jsonargparse using ast, such that no refactoring is needed.Please propose more possibilities.
The deprecations mentioned above could be optional. It wouldn't be a problem to keep the new parameter but also the existing
**kwargs
. This way there is not need for people to change their existing code.The
dataclass_from_signature
function very likely will be added to and maintained in jsonargparse irrespective of this.Additional context
If you enjoy Lightning, check out our other projects! ⚡
Metrics: Machine learning metrics for distributed, scalable PyTorch applications.
Lite: enables pure PyTorch users to scale their existing code on any kind of device while retaining full control over their own loops and optimization logic.
Flash: The fastest way to get a Lightning baseline! A collection of tasks for fast prototyping, baselining, fine-tuning, and solving problems with deep learning.
Bolts: Pretrained SOTA Deep Learning models, callbacks, and more for research and production with PyTorch Lightning and PyTorch.
Lightning Transformers: Flexible interface for high-performance research using SOTA Transformers leveraging Pytorch Lightning, Transformers, and Hydra.
cc @Borda @justusschock @awaelchli @rohitgr7 @tchaton @carmocca @mauvilsa @akihironitta
The text was updated successfully, but these errors were encountered: