Skip to content
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

Fix node calculation in replication for World object #685

Merged
merged 4 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion streaming/base/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ def replicate(self, replication: int) -> Self:
rank = self.rank // replication # Evenly divide ranks.
num_ranks = self.num_ranks // replication # Floor divide our rank.
worker = rank * self.workers_per_rank + self.worker_of_rank # Derive worker.
num_nodes = (num_ranks + self.ranks_per_node - 1) // self.ranks_per_node # Ceil divide.
# Attempt to evenly divide ranks per node. If not possible, the World
# object will just use one node.
if num_ranks % self.ranks_per_node == 0:
num_nodes = num_ranks // self.ranks_per_node
else:
num_nodes = 1
ranks_per_node = num_ranks // num_nodes # Evenly divide ranks per node.
return World(
num_nodes=num_nodes,
Expand Down
8 changes: 6 additions & 2 deletions tests/test_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,22 @@ def test_partition_nodrop_norepeat(physical_nodes: int, canonical_nodes: int, ra
assert samples_seen_set == set(range(num_samples))


@pytest.mark.parametrize('physical_nodes', [1, 4])
@pytest.mark.parametrize('physical_nodes', [1, 4, 7, 13])
@pytest.mark.parametrize('canonical_nodes', [12, 4, 64])
@pytest.mark.parametrize('ranks_per_node', [8])
@pytest.mark.parametrize('workers_per_rank', [1, 8])
@pytest.mark.parametrize('batch_size', [2, 8])
@pytest.mark.parametrize('num_samples', [1024, 16384])
@pytest.mark.parametrize('sample_in_epoch', [0, 256])
@pytest.mark.parametrize('replication', [2, 4])
@pytest.mark.parametrize('replication', [2, 4, 8])
def test_replication_samples(physical_nodes: int, canonical_nodes: int, ranks_per_node: int,
workers_per_rank: int, batch_size: int, num_samples: int,
sample_in_epoch: int, replication: int):

# Make sure canonical nodes works with physical nodes
if physical_nodes % canonical_nodes != 0 and canonical_nodes % physical_nodes != 0:
canonical_nodes = physical_nodes

# Create a World object reflecting the hardware -- the actual nodes and rank
actual_world = World(physical_nodes, ranks_per_node, workers_per_rank, 0)

Expand Down
Loading