[fix][train] Shut down DataLoader workers on exit - #1998
Open
bvolpato wants to merge 2 commits into
Open
Conversation
bvolpato
marked this pull request as ready for review
August 6, 2026 15:18
Contributor
There was a problem hiding this comment.
Code Review
This pull request ensures that trainer resources, specifically DataLoader worker processes, are properly shut down when training finishes or encounters an error. It introduces a shutdown_dataloader utility function to stop worker processes owned by a StatefulDataLoader, and integrates this into the shutdown methods of both SFTTrainer and Trainer. Additionally, finally blocks are added to the entry points to guarantee that shutdown is always executed. Feedback suggests improving the readability of the dataloader shutdown logic in SFTTrainer by separating the train and evaluation dataloader shutdown blocks instead of using an intermediate list.
bvolpato
force-pushed
the
bvolpato/shutdown-dataloader-workers
branch
2 times, most recently
from
August 7, 2026 00:21
d74713a to
1a025cd
Compare
bvolpato
force-pushed
the
bvolpato/shutdown-dataloader-workers
branch
from
August 13, 2026 01:21
1a025cd to
366d401
Compare
bvolpato
force-pushed
the
bvolpato/shutdown-dataloader-workers
branch
from
August 14, 2026 04:41
366d401 to
b1a262c
Compare
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
StatefulDataLoaderowns worker processes through its iterator. RL and SFT entrypoints only cleaned up dataloaders on successful runs, so training exceptions could leave train or evaluation workers alive.Changes
finallyblock and close every train and evaluation dataloader.Normal Python unwinding is covered. Abrupt termination such as
SIGKILLremains outside scope.Testing
123 passed)1467 passed, 5 skipped, 5 deselected)pre-commit run --all-filesgit diff --check upstream/main