fix(iterable-dataset): implement stateful protocol for resume#172
Merged
Conversation
MultiModalIterableDataset did not implement state_dict / load_state_dict,
so StatefulDataLoader could not persist the per-worker iteration cursor.
On resume, __iter__ unconditionally reset cur_idx=0 and the trainer
naive-forwarded from the start of the data even though global_step was
restored, wasting compute.
- Add state_dict() / load_state_dict() returning {cur_idx}.
- Guard the cur_idx=0 resets in __iter__ behind a _resuming flag that
load_state_dict sets and __iter__ consumes once.
Verified by checkpointing at step 2 (workers at cur_idx=43/24) and
resuming for 2 more steps: workers continue to 68/66 instead of
restarting from 0.
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.
Problem
MultiModalIterableDatasetdid not implementstate_dict()/load_state_dict(), soStatefulDataLoaderhad no way to persist the per-worker iteration cursor. On resume,__iter__unconditionally resetself.cur_idx = 0, so even thoughglobal_stepand dataloader-level fetch state were restored, the dataset re-walked from the start of the shard — the trainer effectively naive-forwarded a chunk of data before producing the first useful batch.Fix
state_dict()/load_state_dict()that persist{cur_idx}(called per worker byStatefulDataLoader).cur_idx = 0resets in both__iter__branches (packing / non-packing) behind a_resumingflag thatload_state_dictsets and__iter__consumes once.Per-worker sharding is deterministic given
data_seed + world_size + num_workers, so persistingcur_idxalone is sufficient as long as those don't change across resume.Verification
Two-phase test with
scripts/launch/qwen3_vl_test.shon 4 GPUs / 2 workers per rank, packing enabled,save_steps=2:max_steps=2 save_steps=2max_steps=4 save_steps=2Read directly from
checkpoint-*/dataloader_state/*.pt→_snapshot._worker_snapshots[*].dataset_state. Workers continue from the saved position instead of restarting at 0.Notes
state_dictto the online packer too.