Repository navigation
Save the shuffle buffer content in the state dict so resuming is exact - #8408
thejamesgore wants to merge 1 commit into
Conversation
|
I reported the duplicate this fixes over in #7901, so I checked this branch against the full sweep I had rather than just the one case. Twenty-seven configurations, varying seed, checkpoint offset, buffer size and shard count, on The third column is the strict one: the resumed stream is compared element by element against the uninterrupted stream, so this is exact resume rather than merely the absence of a repeat. On 5.0.1 the same sweep gives duplicates in 3 of 27 and loses The backward-compatible path also behaves. Stripping the new keys out of a checkpoint, which is what a state dict written by an older version looks like, reproduces the old behaviour precisely rather than failing in some new way: That is the same 1 duplicate and 17 missing rows as the original report, so old checkpoints stay loadable and stay exactly as lossy as they were, which seems like the right call. One note for anyone reproducing this: the new keys are nested under Your account of the mechanism also matches what I saw and is more precise than mine. I had stopped at |
|
hey @thejamesgore, ran into the duplicate on resume bug while testing shuffle checkpoints and found this pr, so wanted to share where it's at now it still happens on the latest release and on main. 40 row dataset,
eg with 1 shard, resuming at k=7 gives back the thing is this branch doesn't merge anymore. #8407 (merged sep 7) changed if u don't have time to pick it back up i'm happy to help with the rebase or the state part, just didn't want to open a competing pr without asking. can also share the script i used for the table if it helps disclosure: used claude code to help with the investigation |
|
I'm happy to pick this up tonight thanks for the update
…On Fri, 23 Oct 2026, 17:41 Aaron Anish Thadathil, ***@***.***> wrote:
*aaronanish-t* left a comment (huggingface/datasets#8408)
<#8408 (comment)>
hey @thejamesgore <https://github.com/thejamesgore>, ran into the
duplicate on resume bug while testing shuffle checkpoints and found this
pr, so wanted to share where it's at now
it still happens on the latest release and on main. 40 row dataset, shuffle(seed=1,
buffer_size=8), checkpoint after every possible k:
version shards cut points that re-yield an already seen example
5.1.0 1 20 / 39
5.1.0 4 20 / 39
main (ef61228) 1 20 / 39
main (ef61228) 4 20 / 39
eg with 1 shard, resuming at k=7 gives back [10, 11] again even though
both already came out before the checkpoint. with buffer_size=1 or a
buffer bigger than the dataset resume is exact, so it's the buffer like u
said
the thing is this branch doesn't merge anymore. #8407
<#8407> (merged sep 7)
changed BufferShuffledExamplesIterable to the "fill, shuffle, yield half,
keep half" approach, and merging this into main conflicts in
src/datasets/iterable_dataset.py and tests/test_iterable_dataset.py. i
think the saved state (buffer + rng position) needs to be updated for the
new algorithm too, not just rebased, since it uses one permutation per
refill now instead of one pick per example
if u don't have time to pick it back up i'm happy to help with the rebase
or the state part, just didn't want to open a competing pr without asking.
can also share the script i used for the table if it helps
*disclosure: used claude code to help with the investigation*
—
Reply to this email directly, view it on GitHub
<#8408?email_source=notifications&email_token=ATZI6JAFYJ6UIPT6MB3A2XT5VOC2XA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTMMZWHE4TAMJQHE42M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-6369901099>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATZI6JGRRAZZ5SWCPNENNNL5VOC2XAVCNFSNUABFKJSXA33TNF2G64TZHMZDKMBSGEZTEOBWHNEXG43VMU5TKMBYGAZTAOJUGM42C5QC>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Overview
There are two problems when resuming a shuffled iterable dataset. The known one from the warning and the discussion in #7901 is that the shuffle buffer content isn't saved in the state dict so you lose roughly
buffer_sizeexamples every resume.The second is you can get an example twice. The
RebatchedArrowExamplesIterablethat wraps the pipeline resumes by rewinding to aprevious_statesnapshot and skipping chunks it already delviered which assumes the inner stream is deterministic from its state. The shuffle buffer isn't as it restarts empty with a fresh rng so the rewound rows get reshuffled differently and an already yielded row can come out again. I instrumented it at the issue's k=20: the resume re-reads rows 58 and 158. 158 was still in the buffer but 58 had already been yielded so that's the {58: 2} in the issue. Silent duplicates in a training run that resumes often is worse than the documented loss.## Fix
Save the buffer content, the rng pick count and the end-of-data shuffle flag in the state dict. Resume restores the buffer and fast-forwards the rng, so it carries on exactly where it left off and both problems go away.
Two costs dealt with: state gets captured once per yielded example, so
state_dict()keeps the buffer as a tuple instead of deep-copying it. And the buffered arrow tables are usually zero-copy slices of a whole source table, a buffer_size=1000 checkpoint over 50k rows came out at 1.6 GiB. Slices get rewritten as stand-alone tables before entering the buffer, which brings it down to ~400 KiB.Resolves #7901