-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Remove unnecessary TODO comment in fit_loop.py #21265
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?
Conversation
The TODO suggested moving max_steps check inside training loop, but this is correctly placed in fit_loop since global_step tracks steps across epochs and the fit_loop is responsible for deciding when to stop the entire fit process. Moving it would require additional flag variables, making the code more complex without any benefit. Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
src/lightning/pytorch/loops/fit_loop.py
⚡ Required checks status: All passing 🟢Groups summary🟢 pytorch_lightning: Tests workflow
These checks are required after the changes to 🟢 pytorch_lightning: lit GPU
These checks are required after the changes to 🟢 Benchmarks
These checks are required after the changes to 🟢 pytorch_lightning: Docs
These checks are required after the changes to 🟢 mypy
These checks are required after the changes to 🟢 install
These checks are required after the changes to Thank you for your contribution! 💜
|
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## master #21265 +/- ##
=========================================
- Coverage 87% 79% -8%
=========================================
Files 269 266 -3
Lines 23744 23689 -55
=========================================
- Hits 20572 18671 -1901
- Misses 3172 5018 +1846 |
What does this PR do?
Removes an outdated TODO comment from
src/lightning/pytorch/loops/fit_loop.pythat suggested moving themax_stepscheck inside the training loop.Why is this change needed?
The TODO comment on line 179 suggested:
# TODO: Move track steps inside training loop and move part of these condition inside training loopHowever, the current implementation is correct and the TODO is unnecessary because:
global_steptracks steps across epochs: Theglobal_stepcounter is cumulative across all epochs, not per-epoch, so it makes sense to check it at the fit loop level rather than within the epoch loop.Fit loop is the right place for this check: The
fit_loop.doneproperty evaluates when to leave the entire fit process. Sincemax_stepsdetermines when the entire training should stop (not just a single epoch), checking it here is the appropriate design.Moving it would add unnecessary complexity: Relocating this check to the epoch loop would require introducing additional flag variables to communicate back to the fit loop when
max_stepsis reached, making the code more complex without any benefit.Testing
The existing test suite validates this behavior:
test_fit_loop_done_log_messages- Tests thedoneproperty including themax_stepschecktest_min_max_steps_epochs- Testsmax_stepsbehavior across 7 different scenariosAll tests pass successfully with no regressions.
Fixes #<issue_number>
cc @lantiga @justusschock
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.