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

test_transformer_engine measures SP with overlapping. #3591

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
35 changes: 34 additions & 1 deletion tests/python/test_transformer_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,22 @@ def setup_process_group(mpi_test) -> None:
[Parallelism.TENSOR_PARALLEL, Parallelism.SEQUENCE_PARALLEL],
ids=["tp", "sp"],
)
def test_transformer_layer(setup_process_group, benchmark, compute_type, parallelism):
@pytest.mark.parametrize(
"overlap",
[False, True],
ids=["nonoverlap", "overlap"],
)
def test_transformer_layer(
setup_process_group,
monkeypatch,
benchmark,
compute_type: ComputeType,
parallelism: Parallelism,
overlap: bool,
):
if overlap and parallelism == Parallelism.TENSOR_PARALLEL:
pytest.skip("Tensor parallelism doesn't support overlapping")

# Hyperparameters for GPT-3
hidden_size = 12288
num_heads = 96
Expand All @@ -82,6 +97,7 @@ def test_transformer_layer(setup_process_group, benchmark, compute_type, paralle
attn_input_format="bshd",
set_parallel_mode=True,
sequence_parallel=(parallelism == Parallelism.SEQUENCE_PARALLEL),
ub_tp_comm_overlap=overlap,
tp_group=dist.group.WORLD,
)
transformer_layer.to(dtype).to("cuda")
Expand All @@ -97,6 +113,20 @@ def test_transformer_layer(setup_process_group, benchmark, compute_type, paralle
batch_size, local_sequence_length, hidden_size, dtype=dtype, device="cuda"
)

if overlap:
# Similar to https://github.com/NVIDIA/TransformerEngine/blob/e7bfc0c547d63332e4f8d65e606dc69f4c22ffbe/examples/pytorch/comm_gemm_overlap/te_layer_with_overlap.py#L27-L29
monkeypatch.setenv("CUDA_DEVICE_MAX_CONNECTIONS", "1")
if not te.cpp_extensions.device_supports_multicast():
monkeypatch.setenv("UB_SKIPMC", "1")

te.module.base.initialize_ub(
# Instructed by https://github.com/NVIDIA/TransformerEngine/blob/e7bfc0c547d63332e4f8d65e606dc69f4c22ffbe/transformer_engine/pytorch/module/base.py#L96-L99
[batch_size * sequence_length, hidden_size],
size,
dtype=dtype,
bootstrap_backend="nccl",
)

match compute_type:
case ComputeType.FORWARD:

Expand Down Expand Up @@ -155,3 +185,6 @@ def benchmark_fn(y, dy, profile):
setup=partial(setup_fn, True),
rounds=5,
)

if overlap:
te.module.base.destroy_ub()
Loading