Skip to content

Comments

Fix LightningCLI optional callback handling in subclass mode#21527

Open
KAVYANSHTYAGI wants to merge 10 commits intoLightning-AI:masterfrom
KAVYANSHTYAGI:optional-call-draft-handle
Open

Fix LightningCLI optional callback handling in subclass mode#21527
KAVYANSHTYAGI wants to merge 10 commits intoLightning-AI:masterfrom
KAVYANSHTYAGI:optional-call-draft-handle

Conversation

@KAVYANSHTYAGI
Copy link
Contributor

@KAVYANSHTYAGI KAVYANSHTYAGI commented Feb 4, 2026

When add_lightning_class_args(..., subclass_mode=True, required=False) is used for callbacks and no CLI argument is provided, the resolved value is None.

Previously, LightningCLI.instantiate_trainer unconditionally appended these values to the Trainer callbacks list, allowing None entries to silently propagate.

This PR filters out None callback entries before passing them to the Trainer, preserving the invariant that Trainer.callbacks contains only Callback instances.

A regression test is added to cover optional subclass-mode callback arguments.

@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Feb 4, 2026
@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79%. Comparing base (215d7d9) to head (9d55321).
✅ All tests successful. No failed tests found.

❗ There is a different number of reports uploaded between BASE (215d7d9) and HEAD (9d55321). Click for more details.

HEAD has 429 uploads less than BASE
Flag BASE (215d7d9) HEAD (9d55321)
cpu 132 33
python 12 3
lightning_fabric 36 0
pytest 66 0
python3.10 12 3
lightning 60 15
python3.12 36 9
python3.13 12 3
python3.11 24 6
python3.12.7 36 9
pytorch2.8 12 6
pytorch_lightning 36 18
pytest-full 66 33
pytorch2.6 6 3
pytorch2.5.1 6 3
pytorch2.9 6 3
pytorch2.7 6 3
pytorch2.2.2 6 3
pytorch2.1 12 6
pytorch2.4.1 6 3
pytorch2.3 6 3
Additional details and impacted files
@@            Coverage Diff            @@
##           master   #21527     +/-   ##
=========================================
- Coverage      87%      79%     -8%     
=========================================
  Files         270      267      -3     
  Lines       24069    24018     -51     
=========================================
- Hits        20868    18962   -1906     
- Misses       3201     5056   +1855     

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.

1 participant