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

Call init/destroy_process_group once. #3143

Merged
merged 7 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion tests/python/mpi_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def barrier(self):
self._communicator.barrier()


@pytest.fixture
@pytest.fixture(scope="session")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because setup_process_group, has module scope, uses mpi_test, mpi_test must have module or session scope.

def mpi_test():
fixture = MpiTest()
yield fixture
Expand Down
35 changes: 19 additions & 16 deletions tests/python/test_transformer_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ class ComputeType(Enum):
BACKWARD = auto()


@pytest.fixture(scope="module")
def setup_process_group(mpi_test) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move to mpi_fixtures.py?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do that if I have to duplicate the code. This test is an exception -- normally we want nvFuser to set up process groups.

os.environ["MASTER_ADDR"] = "localhost"
# The default port as used by https://github.com/pytorch/pytorch/blob/45a8b5682eb69d865cbf68c7f2f689b56b4efd53/torch/csrc/distributed/c10d/TCPStore.hpp#L51.
os.environ["MASTER_PORT"] = "29500"
dist.init_process_group(
backend="nccl",
init_method="env://",
samnordmann marked this conversation as resolved.
Show resolved Hide resolved
world_size=mpi_test.size,
rank=mpi_test.rank,
)
yield
dist.destroy_process_group()


# This benchmark is instrumented with cudaProfilerStart/Stop. Therefore, one
# can collect stats of the first few non-warmup benchmark iterations using
#
Expand All @@ -32,13 +47,10 @@ class ComputeType(Enum):
@pytest.mark.mpi
@pytest.mark.parametrize(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure but it might work to specify scope=function here and remove the scope arguments from the two fixtures

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand your suggestion. AFAIK, scope is an attribute of a fixture, not of a test.

"compute_type",
# TODO(#3119): add the backward test back.
# [ComputeType.FORWARD, ComputeType.BACKWARD],
# ids=["forward", "backward"],
[ComputeType.FORWARD],
ids=["forward"],
[ComputeType.FORWARD, ComputeType.BACKWARD],
ids=["forward", "backward"],
)
def test_transformer_layer(mpi_test, benchmark, compute_type):
def test_transformer_layer(mpi_test, setup_process_group, benchmark, compute_type):
# Hyperparameters for GPT-3
hidden_size = 12288
num_heads = 96
Expand All @@ -51,15 +63,6 @@ def test_transformer_layer(mpi_test, benchmark, compute_type):
rank = mpi_test.rank
wujingyue marked this conversation as resolved.
Show resolved Hide resolved

torch.cuda.set_device(rank)
os.environ["MASTER_ADDR"] = "localhost"
# The default port as used by https://github.com/pytorch/pytorch/blob/45a8b5682eb69d865cbf68c7f2f689b56b4efd53/torch/csrc/distributed/c10d/TCPStore.hpp#L51.
os.environ["MASTER_PORT"] = "29500"
dist.init_process_group(
backend="nccl",
init_method="env://",
world_size=size,
rank=rank,
)
tp_group = dist.new_group()
wujingyue marked this conversation as resolved.
Show resolved Hide resolved

transformer_layer = te.TransformerLayer(
Expand Down Expand Up @@ -132,4 +135,4 @@ def benchmark_fn(y, dy, profile):
rounds=5,
)

dist.destroy_process_group()
dist.destroy_process_group(group=tp_group)
Loading