[docs] Add a concept guide on sharding iterable datasets - #4144
Open
zokost wants to merge 1 commit into
Open
Conversation
The docs cover how map-style datasets are sharded by swapping the batch_sampler, but only mention the IterableDataset path in passing. Two consequences of that path are invisible at runtime: every process reads the whole dataset (IterableDatasetShard shards elements, not sources), and a dataset that already shards by source gets sharded a second time by prepare, silently keeping a fraction of its data. Document both, with the alternatives (datasets .shard(), dispatch_batches, sharding by source and skipping prepare) and what preparing the dataloader provides that you take over when you stop: device placement, the end-of-epoch gradient sync, RNG sync, and equal batch counts per process.
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.
What does this PR do?
Adds
concept_guides/iterable_dataset_sharding.md, plus a toctree entry and a cross-link fromconcept_guides/internal_mechanism.md. Documentation only — no code changes.The docs explain that map-style datasets are sharded by swapping the
batch_sampler, but the iterable-dataset pathis only mentioned in passing. Two consequences of that path keep coming up and are invisible at runtime:
Read amplification.
IterableDatasetShardshards elements, so every process iterates the whole underlyingdataset and keeps
1 / num_processesof it. Correct, but the data is readnum_processestimes (andnum_processes × num_workerswith dataloader workers). For streaming pipelines over remote storage that is thedominant cost, and nothing in the docs says it will happen.
Double sharding. A dataset that already shards by source (files, shards, byte ranges) gets wrapped anyway,
so the stream is sharded a second time and each process silently keeps a fraction of the data it was given. No
error, no hang — the loss curve looks normal.
Related: #3547 (where the suggested workaround is to not prepare the dataloader) and #3124; the equivalent issue on
the
datasetsside is huggingface/datasets#6594. This PR documents the current behaviour and the ways around it —it does not change any of it.
The guide covers what
preparedoes to an iterable dataset, the measured cost, when to shard by source yourself,the
dispatch_batches=Truealternative, and what you take responsibility for once you stop preparing the dataloader(device placement, the end-of-epoch gradient sync via
end_of_dataloader, RNG sync, and equal batch counts perprocess).
Numbers
Every number in the guide was measured on
main, not estimated — 8 shards of 10 records,num_processes=4,batch_size=2:prepareprepareprepareReproduction script
Built locally with
doc-builder; the new page and the edited one convert to MDX and their internal links resolve.Happy to cut the page down, fold it into
internal_mechanism.md, or move it tousage_guides/if you'd rather haveit there.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Documentation: @SunMarc