-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
π TODO: Follow up work on module arguments rework in #1896
-
1. (docs) Make clear the multiple ways args can and cannot be passed in.
Example:class LitModel(LightningModule): def __init__(self, arg1, arg2): ... Trainer.add_argparse_args(parser) LitModel.add_model_specific_args(parser) LitModel(parser.parse_args()) # this will fail
This won't work since the list of arguments in constructor is a fixed size.
We can fix it in two ways:- Add
**kwargsto the init signature to catch any unnecessary args (not good design but works) - Split the parsers to separate model args from Trainer args
- Add
-
2. (docs) make it clear which types we save to the checkpoints and which not (nn.Module for example). The name "module_arguments" maybe misleading to believe all args are saved.
-
3. Some old code was left commented, including tests, as mentioned by @yukw777
-
4. (tests) The model checkpointing has changed, we should thoroughly test that the correct args are loaded.
-
5. (tests) Test case for positional args
-
6. (bugfix) Fix for when super() is not called or called after other local vars were added, e.g.,
class LitModel(LightningModule): def __init__(self, arg1, arg2): my_local_var = 2 super().__init__() # module_arguments now contains "my_local_var" LitModel.load_from_checkpoint(...) # this fails # TypeError: __init__ got an unexpected argument "my_local_var"
We obviously don't want any local vars other than the arguments in the checkpoint.
-
7. (bugfix) In Python we are not forced to call the instance "self", this is currently hardcoded and leads to:
class LitModel(LightningModule): def __init__(obj, arg1, arg2): obj.arg1 = arg1 super().__init__() # module_arguments will contain LitModel() itself
same applies to the conventional naming of "*args" and "**kwargs"
-
8. (tests) make sure the LRfinder still works as expected by passing in the suggested learning rate as argument (fixed in Bugfix: Lr finder and hparams compatibilityΒ #2821 )
-
9. (enhancement) @festeh wants to add support for dataclasses
-
10. (bugfix) some of the examples are broken because of the problem mentioned in 1.
-
11. (test) multiple inheritance
-
12. Should error or warn when
self.auto_collect_arguments()is called somewhere other than in init. A specific use case that is currently not working is Crash trying to construct module_arguments when module is created in a methodΒ #1976
Feel free to add additional bullet points I missed :)