Skip to content

Conversation

@LTMeyer
Copy link

@LTMeyer LTMeyer commented Oct 20, 2025

What does this PR do?

This PR fixes learning rate not being updated at the end of epoch when on_train_batch_start returns -1.

Fixes #21296

It postpones the existing raise StopIteration after the learning rate update.

Before submitting
  • Was this discussed/agreed via a GitHub issue? (not for typos and docs): Related issue LR is not updated when on_train_batch_start returns -1 #21296 hasn't been discussed yet.
  • 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?
  • Did you make sure to update the documentation with your changes? (if necessary) No
  • Did you write any new necessary tests? (not for typos and docs) Yes
  • Did you verify new and existing tests pass locally with your changes? Yes
  • Did you list all the breaking changes introduced by this pull request? None
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors) Yes

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:

Reviewer checklist
  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

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

@github-actions github-actions bot added fabric lightning.fabric.Fabric pl Generic label for PyTorch Lightning package labels Oct 20, 2025
Copy link
Collaborator

@SkafteNicki SkafteNicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we please also add some testing that the changed logic then correctly updates the learning rate when response=-1?

When `on_train_batch_start` returns -1, the rest of the epoch is skipped. The lr update should still happen at the end of the epoch. - Test is_last_batch has been set correctly - Test lr has been updated at the end of each epoch
@LTMeyer LTMeyer requested a review from SkafteNicki October 27, 2025 08:30
@LTMeyer
Copy link
Author

LTMeyer commented Oct 28, 2025

Could we please also add some testing that the changed logic then correctly updates the learning rate when response=-1?

@SkafteNicki I've just added tests. Not sure about the most appropriate location though.
10d18d9 actually added tests:

  • to check last_batch is set when rest of epoch was skipped.
  • to check lr is being updated at the end of epoch when on_train_batch_start returns -1.

I've checked that these tests were indeed failing before the changes introduced in the current PR.

@codecov
Copy link

codecov bot commented Nov 7, 2025

Codecov Report

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

❗ There is a different number of reports uploaded between BASE (d046a96) and HEAD (e3c416c). Click for more details.

HEAD has 108 uploads less than BASE
Flag BASE (d046a96) HEAD (e3c416c)
cpu 54 27
python 6 3
lightning_fabric 12 0
pytest 27 0
python3.12.7 18 9
lightning 30 15
python3.11 12 6
python3.10 12 6
python3.12 6 3
Additional details and impacted files
@@ Coverage Diff @@ ## master #21307 +/- ## ========================================= - Coverage 87% 79% -8%  ========================================= Files 269 266 -3 Lines 23744 23692 -52 ========================================= - Hits 20569 18675 -1894  - Misses 3175 5017 +1842 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fabric lightning.fabric.Fabric pl Generic label for PyTorch Lightning package

2 participants