Stop ConcatDataset from re-sharding itself on every epoch - #16133
Open
VaggelisGian wants to merge 1 commit into
Open
Stop ConcatDataset from re-sharding itself on every epoch#16133VaggelisGian wants to merge 1 commit into
VaggelisGian wants to merge 1 commit into
Conversation
With map-style sources, __iter__ stored pt_data.Subset back into self.datasets. Every later call iterated over the already-sharded subsets and sharded them again, so under world_size > 1 each rank saw fewer items every successive epoch and samples duplicated once a shard shrank below the rank slice. The temperature and random index generators also computed their sampling weights from the shrinking subset lengths, drifting the mixture between epochs. Build the Subset list locally inside __iter__ and leave self.datasets untouched; the local list feeds get_iterable, the index generator, item lookup, and the exhaustion handler alike. Adds four unit tests. test_iter_is_repeatable_across_epochs and test_ranks_get_disjoint_shards fail on the unfixed code (second epoch differs from the first, ranks overlap across repeated iterations) and pass after the fix. Signed-off-by: Vaggelis <baggelis100@gmail.com>
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.
Important
The
Update branchbutton must only be pressed in very rare occassions.An outdated branch is never blocking the merge of a PR.
Please reach out to the automation team before pressing that button.
What does this PR do ?
ConcatDataset.__iter__wrote its rank'storch.utils.data.Subsetshards back intoself.datasets, so every epoch re-sharded already-sharded data: underworld_size > 1each rank received fewer samples every successive epoch, and the temperature/random samplers computed their weights from shrinking lengths. This PR stops the mutation.Collection: common
Changelog
ConcatDataset.__iter__now builds a local list ofSubsetshards per iteration and leavesself.datasetsuntouched. The local list feedsget_iterable, the index generator (temperature/random/round-robin), item lookup, and the mid-epoch exhaustion handler.tests/collections/common/data/test_dataset_concat.py.Observed before the fix with two map-style datasets of 10 and 7 items on 2 ranks: epoch 1 gave rank 0
[a0..a4]and rank 1[a5..a9]halves; iterating again sharded those halves a second time (5 -> 2 items for rank 0) and duplicated samples once a shard shrank below the rank slice. Sampler weights drifted between epochs because generator probabilities were derived from the mutated lengths.Usage
No API or config change. Existing training setups get stable per-rank data across epochs:
GitHub Actions CI
The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.
Trusted PRs run automatically through copy-pr-bot. For an untrusted PR, a maintainer can trigger CI by commenting
/ok to test <head-sha>; repeat this after a new push if the PR remains untrusted.Before your PR is "Ready for review"
Pre checks:
PR Type:
Who can review?
Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.
Additional Information
CodeSwitchedDataset.prep_underlying_datasetsin the same file has the same write-back pattern intoself.datasets[lang]and is re-invoked from its__iter__; it is a separate class with separate sampling machinery and is intentionally left out here to keep this PR single-purpose. Happy to follow up separately.Exact checks run locally (Python 3.12.6 via dedicated venv, torch available):
Intentionally skipped: full common+asr suites (blast radius is one method plus its new tests), docs build (
uvunavailable on this machine),pre-commitbinary absent locally; black/isort/flake8 were run directly against the repo's pinned configs instead.