Skip to content

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

KAVYANSHTYAGI
Copy link
Contributor

@KAVYANSHTYAGI KAVYANSHTYAGI commented May 25, 2025

What does this PR do?

This PR fixes an inconsistency in LightningCLI.add_lightning_class_args() where the required=False flag was being ignored when subclass_mode=False (which is the default).
According to the documentation, setting required=False should make providing the corresponding config optional — but in practice, argument registration was enforced regardless, leading to errors if required constructor parameters (e.g., dirpath in ModelCheckpoint) were not provided.

This change adds a conditional check that skips argument registration when:

subclass_mode=False

required=False

and the config key (nested_key) is not provided by the user

Additionally, a test case was added to verify that this behavior works as expected.

Fixes #20851 #20851

Before submitting

Was this discussed/agreed via a GitHub issue? yes

Did you read the contributor guideline, Pull Request section? yes

Did you make sure your PR does only one thing, instead of bundling different changes together? yes

Did you write any new necessary tests? yes

Did you verify new and existing tests pass locally with your changes? yes

Did you update the documentation if necessary?

Did you list all the breaking changes introduced by this pull request?

Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

PR review

Anyone in the community is welcome to review the PR.

Yes :)

📚 Documentation preview 📚: https://pytorch-lightning--20856.org.readthedocs.build/en/20856/

@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pl Generic label for PyTorch Lightning package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add_lightning_class_args required argument ignored if not using subclass mode
1 participant