Skip to content

Fix async map checkpoint accounting across repeated resumes - #8575

Merged
lhoestq merged 1 commit into
huggingface:mainfrom
SBrouck:fix/async-map-resume-counter
Sep 10, 2026
Merged

lhoestq merged 1 commit into
huggingface:mainfrom
SBrouck:fix/async-map-resume-counter

Conversation

@SBrouck

@SBrouck SBrouck commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Resuming an iterable dataset with an asynchronous map function works once, but a checkpoint captured during the resumed iteration can skip additional examples on the next resume. A deterministic identity coroutine over IDs 0–9, checkpointed after two outputs and again after one more output, produces [0, 1, 2, 5, 6, 7, 8, 9] on main at 19f69de53015525126e6d3f96859acb90498e364.

The asynchronous output iterator restores the source snapshot without clearing num_examples_since_previous_state. Replayed outputs, including the ones skipped for the current resume, are counted again on top of the loaded value. Reset this counter when establishing the asynchronous snapshot, keeping the separately captured skip count intact.

The regression test covers repeated serialized checkpoints with synchronous and asynchronous callbacks, Arrow and Python sources, batched and unbatched maps, indices, and concurrency limits of 2 and 1000. Six of its sixteen cases fail before the change; all pass after it.

Validation on macOS ARM64 / Python 3.14.7 / PyArrow 25.0.1:

  • Targeted regression plus existing async and index tests: 30 passed.
  • tests/test_iterable_dataset.py -m unit -k 'not test_interleave_dataset_with_sharding': 461 passed, 45 skipped, 6 deselected. Optional frameworks such as torch are not installed; this is not full cross-platform or distributed validation.
  • Ruff 0.11.8 lint and format checks, and git diff --check: pass.
  • Additional local async scenarios improve from 29/120 exact sequences to 119/120. One batched Arrow filter scenario fails identically before and after this patch. It was reduced to repeated checkpoints on RebatchedArrowExamplesIterable without map/filter/async: a partially consumed chunk is counted twice. A diagnostic intervention on that separate chunk counter removes the filter failure but does not fix the async-map reproduction. That rebatching issue is not included in this patch. No claim is made that all checkpoint problems are resolved.

This appears distinct from #8295, which repaired stale state references after loading, and from #8408, which addresses shuffle buffers. Open PR #7656 also concerns map checkpointing, but its current diff delegates state methods to the source rather than fixing this asynchronous replay counter. The original #7630 reproduction already returns the expected continuation on this main revision. This patch addresses checkpoints taken after an async resume. Please advise if coordination with that work is needed.

AI assistance: I used Codex to help investigate the issue and prepare the fix and regression tests. I have reviewed the code, tests, and investigation results. The validation reported above was executed locally.

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@lhoestq lhoestq left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch !

@lhoestq
lhoestq merged commit 8606c66 into huggingface:main Sep 10, 2026
10 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants