Add already_sharded option to skip double-sharding of DataLoaders#4087
Open
devangpratap wants to merge 2 commits into
Open
Add already_sharded option to skip double-sharding of DataLoaders#4087devangpratap wants to merge 2 commits into
devangpratap wants to merge 2 commits into
Conversation
When a user shards their DataLoader per-process (e.g. with a rank-aware DistributedSampler), Accelerator.prepare shards it a second time, so each process ends up iterating only a fraction of its intended data. This adds an `already_sharded` flag to DataLoaderConfiguration (and prepare_data_loader) that tells Accelerate to keep the user's sharding and skip its own, while still applying device placement, set_epoch forwarding, and state tracking. It is rejected together with dispatch_batches or split_batches, since those modes conflict with a dataloader that is already split per process.
135e74a to
c4dd843
Compare
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?
When a user already shards their DataLoader across processes (for example with a rank-aware
DistributedSampler),Accelerator.prepareshards it a second time. The data ends up split twice, so each process only iterates a fraction of the samples it should. This is a recurring report: #3520, #4062, #4075.This adds an
already_shardedoption toDataLoaderConfiguration(threaded through toprepare_data_loader). When set, Accelerate assumes each process's DataLoader is already sharded and skips its own sharding, while still keeping the rest of the wrapper behaviour: device placement,set_epochforwarding, and dataloader state tracking.already_sharded=Trueis rejected together withdispatch_batches=Trueorsplit_batches=True, since both conflict with a dataloader that is already split per process. Accelerate'seven_batchespadding is also skipped in this mode, so the user is responsible for each process iterating the same number of batches.Fixes #4075 (also addresses #3520 and #4062).
Before submitting
Who can review?
@SunMarc