Fix stateful dataloader checkpointing across processes - #4165
Conversation
|
@SunMarc would you mind reviewing this PR when you have a chance - thank you! |
Friendly bump @SunMarc, and tagging @muellerzr since this addresses the per-rank StatefulDataLoader checkpoint workaround discussed in #3080. Would either of you be able to review? Cheers |
|
Thanks for this PR — the per-rank filenames are a real fix for the shared-file collision. One gap worth flagging during review: the new regression Full analysis + reproducer: #4195. A |
What does this PR do?
This PR fixes stateful dataloader checkpointing during distributed training by saving each process's state separately. A stateful dataloader can hold process-specific cursor, dataset, worker, and RNG state. Currently, every process writes its state to the same
dl_state_dict.binfilename in a shared checkpoint directory, so the final file contains whichever process wrote last, and other processes can restore the wrong data position.Distributed checkpoints now use rank-qualified filenames such as
dl_state_dict_rank0.bin. Loading prefers the current process's file and falls back to the legacy unqualified filename, which preserves compatibility with existing checkpoints. Single-process checkpoint filenames remain unchanged.Related context
Discussed in #3080, where manually saving and loading the dataloader state on every rank is described as the current workaround. This PR addresses that per-rank checkpoint persistence gap.
Tests
torchdatadependency is unavailable.make qualitypytest -q tests/test_state_checkpointing.py -k "not map_location"— 18 passedpytest -q tests/test_accelerator.py -k stateful_dataloader— 17 passedBefore submitting
Who can review?
Anyone in the community is free to review the PR once the tests have passed.