Remove unnecessary TODO comment in fit_loop.py #21265
Draft
+0
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Removes an outdated TODO comment from
src/lightning/pytorch/loops/fit_loop.py
that suggested moving themax_steps
check 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 loop
However, the current implementation is correct and the TODO is unnecessary because:
global_step
tracks steps across epochs: Theglobal_step
counter 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.done
property evaluates when to leave the entire fit process. Sincemax_steps
determines 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_steps
is reached, making the code more complex without any benefit.Testing
The existing test suite validates this behavior:
test_fit_loop_done_log_messages
- Tests thedone
property including themax_steps
checktest_min_max_steps_epochs
- Testsmax_steps
behavior 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.