-
Notifications
You must be signed in to change notification settings - Fork 80
Fix index errors on world size > 0 #252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a629996
fix index error
awaelchli d0dc996
intra-node shuffle fixes
awaelchli 285d2e9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 310b9f1
format
awaelchli 014b702
type error
awaelchli 9d0f35d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 02caabd
update
awaelchli a071e8c
comments
awaelchli fccbeab
Merge branch 'bugfix/resume-index-error' of https://github.com/lightn…
awaelchli 12ee94a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,97 @@ | ||
| import itertools | ||
|
|
||
| from litdata.streaming.item_loader import Interval | ||
| from litdata.utilities.env import _DistributedEnv | ||
| from litdata.utilities.shuffle import ( | ||
| _aggregate_shared_chunks_per_rank, | ||
| _associate_chunks_and_intervals_to_workers, | ||
| _find_chunks_per_workers_on_which_to_skip_deletion, | ||
| _get_shared_chunks, | ||
| _group_chunks_by_nodes, | ||
| _intra_node_chunk_shuffle, | ||
| _map_node_worker_rank_to_chunk_indexes_to_not_delete, | ||
| ) | ||
|
|
||
|
|
||
| def test_intra_node_chunk_shuffle(): | ||
| chunks_per_ranks = [[0, 1], [2, 3], [4, 5], [6, 7]] | ||
|
|
||
| shuffled_indexes = _intra_node_chunk_shuffle(_DistributedEnv(4, 1, 1), chunks_per_ranks, 42, 2) | ||
| assert shuffled_indexes == [5, 2, 0, 7, 6, 1, 3, 4] | ||
| chunks_per_workers = [ | ||
| [0, 1], # rank 0, node 0, worker 0 | ||
| [2, 3], # rank 0, node 0, worker 1 | ||
| [4, 5], # rank 1, node 0, worker 0 | ||
| [6, 7], # rank 1, node 0, worker 1 | ||
| [8, 9], # rank 2, node 1, worker 0 | ||
| [10, 11], # rank 2, node 1, worker 1 | ||
| [12, 13], # rank 3, node 1, worker 0 | ||
| [14, 15], # rank 3, node 1, worker 1 | ||
| ] | ||
|
|
||
| shuffled_indexes = _intra_node_chunk_shuffle(_DistributedEnv(4, 1, 2), chunks_per_ranks, 42, 2) | ||
| assert shuffled_indexes == [3, 2, 1, 0, 7, 6, 5, 4] | ||
| # Each rank shuffles the chunks the same way | ||
| shuffled_per_rank = [ | ||
| _intra_node_chunk_shuffle( | ||
| distributed_env=_DistributedEnv(4, rank, 2), | ||
| num_workers=2, | ||
| chunks_per_workers=chunks_per_workers, | ||
| seed=42, | ||
| current_epoch=0, | ||
| ) | ||
| for rank in range(4) | ||
| ] | ||
| expected = [1, 5, 0, 7, 2, 4, 3, 6, 9, 13, 8, 15, 10, 12, 11, 14] | ||
| assert shuffled_per_rank[0] == shuffled_per_rank[1] == shuffled_per_rank[2] == shuffled_per_rank[3] == expected | ||
|
|
||
| chunks_per_ranks = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13], [14, 15]] | ||
| shuffled_indexes = _intra_node_chunk_shuffle(_DistributedEnv(8, 7, 2), chunks_per_ranks, 42, 2) | ||
| assert shuffled_indexes == [5, 2, 0, 7, 6, 1, 3, 4, 13, 10, 8, 15, 14, 9, 11, 12] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, the test was asserting the final output list which by itself is not very meaningful (apart from asserting it doesn't change from one version to the next). I extended the test to show the other important properities:
|
||
| # shuffles are different each epoch | ||
| shuffled_per_rank = [ | ||
| _intra_node_chunk_shuffle( | ||
| distributed_env=_DistributedEnv(4, 0, 2), | ||
| num_workers=2, | ||
| chunks_per_workers=chunks_per_workers, | ||
| seed=42, | ||
| current_epoch=epoch, | ||
| ) | ||
| for epoch in range(4) | ||
| ] | ||
| for i, j in itertools.product(range(4), range(4)): | ||
| # check that the shuffles are different (pairwise comparison) | ||
| if i <= j: | ||
| continue | ||
| assert shuffled_per_rank[i] != shuffled_per_rank[j] | ||
|
|
||
|
|
||
| def test_group_chunks_by_nodes(): | ||
| # 1 node x 1 processes x 2 workers | ||
| chunks_per_workers = [[0, 1], [2, 3]] | ||
| result = _group_chunks_by_nodes(chunks_per_workers, world_size=1, num_nodes=1, num_workers_per_process=2) | ||
| expected = [[0, 1, 2, 3]] | ||
| assert result == expected | ||
|
|
||
| # 1 node x 2 processes x 2 workers | ||
| chunks_per_workers = [ | ||
| [0, 1], # rank 0, node 0, worker 0 | ||
| [2, 3], # rank 0, node 0, worker 1 | ||
| [4, 5], # rank 1, node 0, worker 0 | ||
| [6, 7], # rank 1, node 0, worker 1 | ||
| ] | ||
| result = _group_chunks_by_nodes(chunks_per_workers, world_size=2, num_nodes=1, num_workers_per_process=2) | ||
| expected = [[0, 1, 2, 3, 4, 5, 6, 7]] | ||
| assert result == expected | ||
|
|
||
| # 2 nodes x 2 processes x 2 workers | ||
| chunks_per_workers = [ | ||
| [0, 1], # rank 0, node 0, worker 0 | ||
| [2, 3], # rank 0, node 0, worker 1 | ||
| [4, 5], # rank 1, node 0, worker 0 | ||
| [6, 7], # rank 1, node 0, worker 1 | ||
| [8, 9], # rank 2, node 1, worker 0 | ||
| [10, 11], # rank 2, node 1, worker 1 | ||
| [12, 13], # rank 3, node 1, worker 0 | ||
| [14, 15], # rank 3, node 1, worker 1 | ||
| ] | ||
| result = _group_chunks_by_nodes(chunks_per_workers, world_size=4, num_nodes=2, num_workers_per_process=2) | ||
| expected = [ | ||
| [0, 1, 2, 3, 4, 5, 6, 7], # chunks in node 0 | ||
| [8, 9, 10, 11, 12, 13, 14, 15], # chunks in node 1 | ||
| ] | ||
| assert result == expected | ||
|
|
||
|
|
||
| def test_associate_chunks_and_intervals_to_workers(): | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since chunks are now associated by worker and not rank (#237), the grouping by node here was still wrong. I extracted this grouping to a new function so I can more easily test it.