Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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: 7 additions & 0 deletions tests/test_utils/recipes/h100/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ products:
scope: [unit-tests]
n_repeat: [1]
time_limit: [1800]
- test_case: [tests/unit_tests/distributed/mfsdp_v2/**/*.py]
products:
- environment: [lts, dev]
tag: [latest]
scope: [unit-tests]
n_repeat: [1]
time_limit: [1800]
- test_case: [tests/unit_tests/a2a_overlap/**/*.py]
products:
- environment: [lts, dev]
Expand Down
61 changes: 61 additions & 0 deletions tests/unit_tests/distributed/mfsdp_v2/conftest.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, I can put these tests under tests/unit_tests/distributed/megatron_fsdp/experimental. I don't think the extra level of nesting is worthwhile just to reuse conftest.py, but I'm happy to do that if you prefer.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.

import dataclasses
import os
from collections.abc import Iterator

import pytest
import torch
import torch.distributed as dist


@dataclasses.dataclass(frozen=True)
class DistributedSetup:
"""Per-rank distributed test setup."""

rank: int
world_size: int
device: torch.device


@pytest.fixture(scope="session", autouse=True)
def cleanup():
"""Destroy the default process group after the mFSDP v2 bucket."""
yield
if dist.is_initialized():
try:
if torch.cuda.is_available():
# Pass the device explicitly to suppress PyTorch's NCCL barrier warning.
dist.barrier(device_ids=[torch.cuda.current_device()])
else:
dist.barrier()
except Exception:
return
dist.destroy_process_group()


@pytest.fixture(scope="function")
def distributed_setup() -> Iterator[DistributedSetup]:
"""Read torchrun rank state and set up this rank's local device."""
if "RANK" not in os.environ or "WORLD_SIZE" not in os.environ:
pytest.skip("Not running under torchrun. Use torchrun to run this test file.")

rank = int(os.environ["RANK"])
world_size = int(os.environ["WORLD_SIZE"])
local_rank = int(os.environ.get("LOCAL_RANK", rank))

if torch.cuda.is_available():
torch.cuda.set_device(local_rank)
device = torch.device(f"cuda:{local_rank}")
else:
device = torch.device("cpu")

yield DistributedSetup(rank=rank, world_size=world_size, device=device)

if dist.is_initialized():
# Keep the default process group alive for later distributed tests.
if device.type == "cuda":
# Pass the device explicitly to suppress PyTorch's NCCL barrier warning.
dist.barrier(device_ids=[device.index])
Comment on lines +42 to +43

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This file is copied from distributed/megatron_fsdp; the only changes are these two lines.

else:
dist.barrier()
Loading