fix: release slot on CancelledError instead of hard-exit at epoch boundaries#1733
Open
dinhxuanvu wants to merge 3 commits into
Open
fix: release slot on CancelledError instead of hard-exit at epoch boundaries#1733dinhxuanvu wants to merge 3 commits into
dinhxuanvu wants to merge 3 commits into
Conversation
At epoch boundaries, the trainer cancels in-flight generation workers. Workers that have already acquired a submission slot (slot_acquired=True) will receive CancelledError — this is expected behavior, not a fatal error. Previously, os._exit(1) was called in this case, killing the entire process during normal epoch transitions. Add on_submission_cancelled() to _AsyncStalenessManager that properly undoes acquire_submission_slot() by decrementing both submitted and running counters. This ensures validate_state_at_epoch_end assertions pass correctly. The os._exit(1) in the Exception handler (for EngineDeadError and other real errors) remains unchanged.
Contributor
There was a problem hiding this comment.
Code Review
This pull request replaces a hard process exit with a graceful cancellation handler (on_submission_cancelled) when a generation worker is cancelled mid-flight. The reviewer recommends adding defensive assertions to prevent the submitted and running counters from underflowing.
Prevent silent counter underflow by asserting submitted and running are positive before decrementing.
Contributor
Author
|
@SumanthRH Hey Sunmanth, sorry to ping you directly. This is a follow-up PR from #1691 that we were discussing. The original fix to use os.exit() on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
At epoch boundaries, the trainer cancels in-flight generation workers via
task.cancel(). Workers that have already acquired a submission slot (slot_acquired=True) receiveCancelledError— this is expected behavior during normal epoch transitions, not a fatal error.Previously (#1691),
os._exit(1)was called in this case, which killed the entire process during normal epoch transitions and prevented proper error log propagation.Changes
on_submission_cancelled()to_AsyncStalenessManagerthat properly undoesacquire_submission_slot()by decrementing bothsubmittedandrunningcountersos._exit(1)in theCancelledErrorhandler withon_submission_cancelled()+ returnos._exit(1)in theExceptionhandler (forEngineDeadErrorand other real errors) remains unchangedWhy
acquire_submission_slot()increments bothsubmittedandrunning. When a worker is cancelled mid-flight:on_rollout_rejected()only decrementsrunning, leavingsubmitted != acceptedat epoch endos._exit(1)kills the process entirely (too aggressive for normal behavior)on_submission_cancelled()correctly undoes both increments, sovalidate_state_at_epoch_endpassesTest plan
validate_state_at_epoch_endassertions pass at epoch boundariesEngineDeadErrorstill triggersos._exit(1)(Exception handler unchanged)