Skip to content
Open
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
6 changes: 2 additions & 4 deletions comms/dsl/tuning_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,10 @@ def check_geometry(
# The cache advances only on an accepted switch: reseeding the baseline before the raise
# would let the next (still hazardous) switch slip through unflagged.
if prev is None or prev == sig:
transport._last_geometry_signature = (
sig # pyre-ignore[16]: runtime cache on the transport
)
transport._last_geometry_signature = sig
return
if os.environ.get("COMMS_DSL_ALLOW_GEOMETRY_SWITCH") == "1":
transport._last_geometry_signature = sig # pyre-ignore[16]: runtime cache
transport._last_geometry_signature = sig
return
names = sorted(fields)
raise ValueError(
Expand Down
8 changes: 3 additions & 5 deletions comms/ncclx/meta/benchmarks/nccl_comm_memory_runner.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from comms.testinfra.multiproc_benchmark_runner import ( # pyre-ignore
run_nccl_distributed_test,
)
from windtunnel.benchmarks.python_benchmark_runner.benchmark import ( # pyre-ignore
from comms.testinfra.multiproc_benchmark_runner import run_nccl_distributed_test
from windtunnel.benchmarks.python_benchmark_runner.benchmark import (
main as servicelab_main,
register_benchmark,
UserCounters,
Expand All @@ -14,7 +12,7 @@


@register_benchmark(use_counters=True)
def ncclCommMemoryMB(counters: UserCounters) -> None: # pyre-ignore
def ncclCommMemoryMB(counters: UserCounters) -> None:
for ppn in [1, 4]:
target = f"{TARGET_PREFIX}{ppn}"
memory_mb = run_nccl_distributed_test(target, SEARCH_PATTERN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
parse_actual_outputs,
print_numerical_failure_summary,
)
from torchx.components.fb.dist import hpc as fb_dist_hpc # pyre-ignore[21]
from torchx.components.fb.dist import hpc as fb_dist_hpc
from torchx.runner import get_runner # pyre-ignore[21]
from torchx.specs import CfgVal, named_resources # pyre-ignore[21]
from torchx.specs import CfgVal, named_resources

logger: logging.Logger = logging.getLogger(__name__)

Expand Down
12 changes: 5 additions & 7 deletions comms/torchcomms/device_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def _flatten_with_comm(
else:
from torch.distributed._mesh_layout import _MeshLayout

coalesced_layout = _MeshLayout([layout.collapse()]) # pyre-ignore[19]
coalesced_layout = _MeshLayout([layout.collapse()])

# Compatibility layer for DeviceMesh API changes. The new API uses _rank_map
# while the older API requires passing mesh tensor directly. This conditional
Expand Down Expand Up @@ -235,11 +235,9 @@ def _flatten_with_comm(
"Flattening with torchcomm is not supported for device mesh without mesh layout."
)
root_mesh = _mesh_resources.get_root_mesh(mesh)
_mesh_resources.child_to_root_mapping[ # pyre-ignore[16]
flattened_device_mesh
] = root_mesh
_mesh_resources.root_to_flatten_mapping.setdefault( # pyre-ignore[16]
root_mesh, {}
)[mesh_dim_name] = flattened_device_mesh
_mesh_resources.child_to_root_mapping[flattened_device_mesh] = root_mesh
_mesh_resources.root_to_flatten_mapping.setdefault(root_mesh, {})[
mesh_dim_name
] = flattened_device_mesh

return flattened_device_mesh
2 changes: 0 additions & 2 deletions comms/torchcomms/distwrap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import torch
import torch.distributed as dist

# pyre-fixme[21]: Could not find name in module (ProcessGroup backends not in stubs)
from torch.distributed import ( # noqa: F401
get_process_group_ranks,
get_rank,
Expand Down
21 changes: 12 additions & 9 deletions comms/torchcomms/distwrap/collectives.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@

# Static mapping from torch.distributed.ReduceOp to torchcomms.ReduceOp
_REDUCE_OP_MAP: dict[ReduceOp, TcReduceOp] = {
# pyrefly: ignore [bad-assignment]
ReduceOp.SUM: TcReduceOp.SUM,
# pyrefly: ignore [bad-assignment]
ReduceOp.PRODUCT: TcReduceOp.PRODUCT,
# pyrefly: ignore [bad-assignment]
ReduceOp.MIN: TcReduceOp.MIN,
# pyrefly: ignore [bad-assignment]
ReduceOp.MAX: TcReduceOp.MAX,
# pyrefly: ignore [bad-assignment]
ReduceOp.BAND: TcReduceOp.BAND,
# pyrefly: ignore [bad-assignment]
ReduceOp.BOR: TcReduceOp.BOR,
# pyrefly: ignore [bad-assignment]
ReduceOp.BXOR: TcReduceOp.BXOR,
# pyrefly: ignore [bad-assignment]
ReduceOp.AVG: TcReduceOp.AVG,
}

Expand Down Expand Up @@ -107,6 +115,7 @@ def _make_nccl_premul_sum(mul_factor: float | torch.Tensor) -> ReduceOp:

def all_reduce(
tensor: torch.Tensor,
# pyrefly: ignore [bad-function-definition]
op: ReduceOp = ReduceOp.SUM,
group: ProcessGroup | None = None,
async_op: bool = False,
Expand Down Expand Up @@ -154,6 +163,7 @@ def broadcast(
def reduce(
tensor: torch.Tensor,
dst: int | None = None,
# pyrefly: ignore [bad-function-definition]
op: ReduceOp = ReduceOp.SUM,
group: ProcessGroup | None = None,
async_op: bool = False,
Expand Down Expand Up @@ -232,6 +242,7 @@ def all_gather_into_tensor(
def reduce_scatter(
output: torch.Tensor,
input_list: list[torch.Tensor],
# pyrefly: ignore [bad-function-definition]
op: ReduceOp = ReduceOp.SUM,
group: ProcessGroup | None = None,
async_op: bool = False,
Expand All @@ -257,6 +268,7 @@ def reduce_scatter(
def reduce_scatter_tensor(
output: torch.Tensor,
input: torch.Tensor,
# pyrefly: ignore [bad-function-definition]
op: ReduceOp = ReduceOp.SUM,
group: ProcessGroup | None = None,
async_op: bool = False,
Expand Down Expand Up @@ -536,24 +548,18 @@ def batch_isend_irecv(p2p_op_list: list[Any]) -> list[dist.Work]:
return []

first_op = getattr(p2p_op_list[0], "_p2p_op", p2p_op_list[0])
# pyrefly: ignore [missing-attribute]
pg = get_group(first_op.group)
pg_info_assert_registered(pg)
# pyrefly: ignore [missing-attribute]
tc = get_torchcomms_instance(pg, tensor=first_op.tensor)

works: list[dist.Work] = []
for p2p_op in p2p_op_list:
actual_op = getattr(p2p_op, "_p2p_op", p2p_op)
# pyrefly: ignore [missing-attribute]
op_name = actual_op.op.__name__

# pyrefly: ignore [missing-attribute]
group_peer = actual_op.group_peer
if group_peer is None:
# pyrefly: ignore [missing-attribute]
if actual_op.peer is not None:
# pyrefly: ignore [bad-argument-type]
group_peer = get_group_rank(pg, actual_op.peer)
else:
raise ValueError(
Expand All @@ -562,18 +568,15 @@ def batch_isend_irecv(p2p_op_list: list[Any]) -> list[dist.Work]:
)

if "send" in op_name:
# pyrefly: ignore [missing-attribute]
work = tc.send(actual_op.tensor, group_peer, True)
elif "recv" in op_name:
# pyrefly: ignore [missing-attribute]
work = tc.recv(actual_op.tensor, group_peer, True)
else:
raise ValueError(f"Unknown P2P operation: {op_name}")
works.append(work)
return works
# Unwrap distwrap P2POp objects to torch.distributed.P2POp
unwrapped_ops = [getattr(op, "_p2p_op", op) for op in p2p_op_list]
# pyrefly: ignore [bad-argument-type]
works = dist.batch_isend_irecv(unwrapped_ops)
if works is None:
raise AssertionError("dist.batch_isend_irecv returned None")
Expand Down
3 changes: 0 additions & 3 deletions comms/torchcomms/distwrap/new_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,9 @@ def split_group( # noqa: C901
# NCCL options, we set split_share=0 on them. If the user passes
# non-NCCL options (e.g., Gloo), we pass them through unchanged.
#
# pyre-fixme[16]: Module `torch.distributed` has no attribute `ProcessGroupNCCL`.
if hasattr(dist, "ProcessGroupNCCL"):
if pg_options is None:
# pyre-fixme[16]: Module `torch.distributed` has no attribute `ProcessGroupNCCL`.
pg_options = dist.ProcessGroupNCCL.Options()
# pyre-fixme[16]: Module `torch.distributed` has no attribute `ProcessGroupNCCL`.
if isinstance(pg_options, dist.ProcessGroupNCCL.Options):
if hasattr(pg_options, "config") and hasattr(
pg_options.config, "split_share"
Expand Down
2 changes: 2 additions & 0 deletions comms/torchcomms/distwrap/tests/integration/AllReduceTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test_sync_all_reduce(self) -> None:

input_tensor = torch.ones(1024, dtype=torch.float, device=device) * (rank + 1)

# pyrefly: ignore [bad-argument-type]
dist.all_reduce(input_tensor, dist.ReduceOp.SUM, async_op=False)

expected = num_ranks * (num_ranks + 1) // 2
Expand All @@ -59,6 +60,7 @@ def test_async_all_reduce(self) -> None:

input_tensor = torch.ones(1024, dtype=torch.float, device=device) * (rank + 1)

# pyrefly: ignore [bad-argument-type]
work = dist.all_reduce(input_tensor, dist.ReduceOp.SUM, async_op=True)
if work is None:
raise AssertionError("work is None")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def test(self) -> None:
input_tensor = torch.ones(1024, dtype=torch.float, device=device) * (
rank + 1
)
# pyrefly: ignore [bad-argument-type]
dist.all_reduce(input_tensor, dist.ReduceOp.SUM, async_op=False)

expected = num_ranks * (num_ranks + 1) // 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test(self) -> None:
input_tensor = torch.ones(1024, dtype=torch.float, device=device) * (
rank + 1
)
# pyrefly: ignore [bad-argument-type]
dist.all_reduce(input_tensor, dist.ReduceOp.SUM, async_op=False)

expected = num_ranks * (num_ranks + 1) // 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test(self) -> None:
input_tensor = torch.ones(1024, dtype=torch.float, device=device) * (
rank + 1
)
# pyrefly: ignore [bad-argument-type]
dist.all_reduce(input_tensor, dist.ReduceOp.SUM, async_op=False)

expected = num_ranks * (num_ranks + 1) // 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test(self) -> None:
input_tensor = torch.ones(1024, dtype=torch.float, device=device) * (
rank + 1
)
# pyrefly: ignore [bad-argument-type]
dist.all_reduce(input_tensor, dist.ReduceOp.SUM, async_op=False)

expected = num_ranks * (num_ranks + 1) // 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test(self) -> None:
input_tensor = torch.ones(1024, dtype=torch.float, device=device) * (
rank + 1
)
# pyrefly: ignore [bad-argument-type]
dist.all_reduce(input_tensor, dist.ReduceOp.SUM, async_op=False)

expected = num_ranks * (num_ranks + 1) // 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test(self) -> None:
input_tensor = torch.ones(1024, dtype=torch.float, device=device) * (
rank + 1
)
# pyrefly: ignore [bad-argument-type]
dist.all_reduce(input_tensor, dist.ReduceOp.SUM, async_op=False)

expected = num_ranks * (num_ranks + 1) // 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test(self) -> None:
input_tensor = torch.ones(1024, dtype=torch.float, device=device) * (
rank + 1
)
# pyrefly: ignore [bad-argument-type]
dist.all_reduce(input_tensor, dist.ReduceOp.SUM, async_op=False)

expected = num_ranks * (num_ranks + 1) // 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test(self) -> None:
input_tensor = torch.ones(1024, dtype=torch.float, device=device) * (
rank + 1
)
# pyrefly: ignore [bad-argument-type]
dist.all_reduce(input_tensor, dist.ReduceOp.SUM, async_op=False)

expected = num_ranks * (num_ranks + 1) // 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test(self) -> None:
input_tensor = torch.ones(1024, dtype=torch.float, device=device) * (
rank + 1
)
# pyrefly: ignore [bad-argument-type]
dist.all_reduce(input_tensor, dist.ReduceOp.SUM, async_op=False)

expected = num_ranks * (num_ranks + 1) // 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test(self) -> None:
input_tensor = torch.ones(1024, dtype=torch.float, device=device) * (
rank + 1
)
# pyrefly: ignore [bad-argument-type]
dist.all_reduce(input_tensor, dist.ReduceOp.SUM, async_op=False)

expected = num_ranks * (num_ranks + 1) // 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def _verify_collective(self, pg: dist.ProcessGroup) -> None:
device = get_device(rank)

input_tensor = torch.ones(1024, dtype=torch.float, device=device) * (rank + 1)
# pyrefly: ignore [bad-argument-type]
dist.all_reduce(input_tensor, dist.ReduceOp.SUM, group=pg, async_op=False)

expected = num_ranks * (num_ranks + 1) // 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def test_reduce_scatter_quantized_sum(self) -> None:
work = dist.reduce_scatter_quantized(
output_tensor,
input_tensor,
# pyrefly: ignore [bad-argument-type]
dist.ReduceOp.SUM,
seed,
async_op=False,
Expand Down Expand Up @@ -109,6 +110,7 @@ def test_reduce_scatter_quantized_async(self) -> None:
work = dist.reduce_scatter_quantized(
output_tensor,
input_tensor,
# pyrefly: ignore [bad-argument-type]
dist.ReduceOp.SUM,
seed,
async_op=True,
Expand Down
30 changes: 25 additions & 5 deletions comms/torchcomms/distwrap/tests/integration/ReduceScatterTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ def test_sync_reduce_scatter(self) -> None:
output_tensor = torch.zeros(1024, dtype=torch.float, device=device)

dist.reduce_scatter(
output_tensor, input_list, op=dist.ReduceOp.SUM, async_op=False
# pyrefly: ignore [bad-argument-type]
output_tensor,
input_list,
op=dist.ReduceOp.SUM,
async_op=False,
)

# Each rank gets the sum of all ranks' contribution for its chunk
Expand All @@ -73,7 +77,11 @@ def test_async_reduce_scatter(self) -> None:
output_tensor = torch.zeros(1024, dtype=torch.float, device=device)

work = dist.reduce_scatter(
output_tensor, input_list, op=dist.ReduceOp.SUM, async_op=True
# pyrefly: ignore [bad-argument-type]
output_tensor,
input_list,
op=dist.ReduceOp.SUM,
async_op=True,
)
if work is None:
raise AssertionError("work is None")
Expand All @@ -95,7 +103,11 @@ def test_sync_reduce_scatter_tensor(self) -> None:
output_tensor = torch.zeros(1024, dtype=torch.float, device=device)

dist.reduce_scatter_tensor(
output_tensor, input_tensor, op=dist.ReduceOp.SUM, async_op=False
# pyrefly: ignore [bad-argument-type]
output_tensor,
input_tensor,
op=dist.ReduceOp.SUM,
async_op=False,
)

expected = num_ranks * (num_ranks + 1) // 2
Expand All @@ -114,7 +126,11 @@ def test_async_reduce_scatter_tensor(self) -> None:
output_tensor = torch.zeros(1024, dtype=torch.float, device=device)

work = dist.reduce_scatter_tensor(
output_tensor, input_tensor, op=dist.ReduceOp.SUM, async_op=True
# pyrefly: ignore [bad-argument-type]
output_tensor,
input_tensor,
op=dist.ReduceOp.SUM,
async_op=True,
)
if work is None:
raise AssertionError("work is None")
Expand All @@ -141,7 +157,11 @@ def test_reduce_scatter_variable_sizes(self) -> None:
output_tensor = torch.zeros(output_size, dtype=torch.float, device=device)

dist.reduce_scatter(
output_tensor, input_list, op=dist.ReduceOp.SUM, async_op=False
# pyrefly: ignore [bad-argument-type]
output_tensor,
input_list,
op=dist.ReduceOp.SUM,
async_op=False,
)

# Each rank gets the sum of all ranks' contributions
Expand Down
2 changes: 2 additions & 0 deletions comms/torchcomms/distwrap/tests/integration/ReduceTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def test_sync_reduce(self) -> None:

input_tensor = torch.ones(1024, dtype=torch.float, device=device) * (rank + 1)

# pyrefly: ignore [bad-argument-type]
dist.reduce(input_tensor, dst=0, op=dist.ReduceOp.SUM, async_op=False)

if rank == 0:
Expand All @@ -62,6 +63,7 @@ def test_async_reduce(self) -> None:

input_tensor = torch.ones(1024, dtype=torch.float, device=device) * (rank + 1)

# pyrefly: ignore [bad-argument-type]
work = dist.reduce(input_tensor, dst=0, op=dist.ReduceOp.SUM, async_op=True)
if work is None:
raise AssertionError("work is None")
Expand Down
Loading
Loading