-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Fix: Respect required=False
in add_lightning_class_args
when subclass_mode=False
#20856
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
base: master
Are you sure you want to change the base?
Changes from all commits
5cb5880
4bab579
d2ba52b
09cc8f4
ff311ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1860,6 +1860,34 @@ def test_lightning_cli_args_and_sys_argv_warning(): | |||||||||||||||
LightningCLI(TestModel, run=False, args=["--model.foo=789"]) | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
def test_add_class_args_required_false_skips_addition(tmp_path): | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @KAVYANSHTYAGI you did not run the test to check whether the code was working. I know this because it is not possible that it works. When you open a pull request it would be good that beforehand you run the tests. And the test should fail without the code changes and succeed with them. |
||||||||||||||||
from lightning.pytorch import callbacks, cli | ||||||||||||||||
|
||||||||||||||||
class FooCheckpoint(callbacks.ModelCheckpoint): | ||||||||||||||||
def __init__(self, dirpath, *args, **kwargs): | ||||||||||||||||
super().__init__(dirpath, *args, **kwargs) | ||||||||||||||||
Comment on lines
+1866
to
+1868
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There is no reason for this class since |
||||||||||||||||
|
||||||||||||||||
class SimpleModel: | ||||||||||||||||
def __init__(self): | ||||||||||||||||
pass | ||||||||||||||||
|
||||||||||||||||
class SimpleDataModule: | ||||||||||||||||
def __init__(self): | ||||||||||||||||
pass | ||||||||||||||||
Comment on lines
+1870
to
+1876
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
class FooCLI(cli.LightningCLI): | ||||||||||||||||
def __init__(self): | ||||||||||||||||
super().__init__( | ||||||||||||||||
model_class=SimpleModel, datamodule_class=SimpleDataModule, run=False, save_config_callback=None | ||||||||||||||||
) | ||||||||||||||||
Comment on lines
+1879
to
+1882
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
What is the point of this? It doesn't seem relevant to the test. |
||||||||||||||||
|
||||||||||||||||
def add_arguments_to_parser(self, parser): | ||||||||||||||||
parser.add_lightning_class_args(FooCheckpoint, "checkpoint", required=False) | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
# Expectation: No error raised even though FooCheckpoint requires `dirpath` | ||||||||||||||||
FooCLI() | ||||||||||||||||
Comment on lines
+1887
to
+1888
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This must have at least But anyway, |
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
def test_lightning_cli_jsonnet(cleandir): | ||||||||||||||||
class MainModule(BoringModel): | ||||||||||||||||
def __init__(self, main_param: int = 1): | ||||||||||||||||
|
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.
This method is only called on parser construction, not during parsing. So at this point there isn't any config. Because of the
getattr(self, "config", {})
this doesn't fail but it will never do anything.