Skip to content

Commit 2e3b14a

Browse files
committed
[DEPS] merge PR NVIDIA#21799 breakable-prefill NCCL window promotion (6973cb1)
# Conflicts: # tests/unittest/_torch/test_nccl_window_graph.py
2 parents 5626ccf + 6973cb1 commit 2e3b14a

5 files changed

Lines changed: 61 additions & 3 deletions

File tree

‎tensorrt_llm/_torch/models/modeling_qwen3_next.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,8 +1426,6 @@ def __init__(
14261426
):
14271427
decode_kernels = _uses_decode_kernels(model_config)
14281428
if decode_kernels:
1429-
# Every AllReduce this model builds: no NCCL_SYMMETRIC.
1430-
model_config.extra_attrs["allreduce_exclude_nccl_symmetric"] = True
14311429
# Its FP4 MoE layers tune for the decode steps.
14321430
model_config.extra_attrs["moe_decode_tuning"] = True
14331431
# Its MNNVL all-reduces run the residual RMSNorm fusions on the CuTe DSL kernels.

‎tensorrt_llm/_torch/nccl_window_graph.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,19 @@ def nccl_window_graph_capture(
112112
yield
113113

114114

115+
def promote_synchronized_nccl_window_releases() -> None:
116+
"""Make windows released so far reusable from any stream, after a device sync.
117+
118+
A released window stays bound to its release stream until promoted. Captures that
119+
run eager work first (breakable prefill warmup) must promote before that work, or
120+
best-fit depends on whether a rank's capture stream equals the release stream, and
121+
a rank that misses enters the collective window registration alone.
122+
"""
123+
release_epoch = torch.ops.trtllm.get_nccl_window_buffer_release_epoch()
124+
torch.cuda.synchronize()
125+
torch.ops.trtllm.promote_nccl_window_buffer_releases(torch.cuda.current_device(), release_epoch)
126+
127+
115128
def abandon_nccl_window_graph_owner(pool: Any) -> None:
116129
"""Forget a locally failed pool without making its C++ buffers reusable.
117130

‎tensorrt_llm/_torch/pyexecutor/breakable_cuda_graph_runner.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
from torch import nn
1111

1212
from ..models.modeling_utils import timing_metric
13-
from ..nccl_window_graph import abandon_nccl_window_graph_owner, release_nccl_window_graph_owner
13+
from ..nccl_window_graph import (
14+
abandon_nccl_window_graph_owner,
15+
promote_synchronized_nccl_window_releases,
16+
release_nccl_window_graph_owner,
17+
)
1418
from ..nccl_window_tensor_scope import discard_nccl_window_tensor_outputs
1519
from ..utils import make_weak_ref
1620
from .breakable_cuda_graph import (
@@ -124,6 +128,7 @@ def capture(
124128
if num_tokens in self._graphs:
125129
raise ValueError(f"BCG for num_tokens={num_tokens} is already captured")
126130

131+
promote_synchronized_nccl_window_releases()
127132
current_stream = torch.cuda.current_stream()
128133
self._capture_stream.wait_stream(current_stream)
129134
graph = None

‎tests/unittest/_torch/pyexecutor/test_breakable_cuda_graph.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,27 @@ def engine_forward():
476476
assert runner.num_break_graphs == 0 and runner._break_graph_pool is None
477477

478478

479+
def test_runner_capture_promotes_window_releases_before_warmup(monkeypatch):
480+
# Windows released on another stream must be reusable from the capture stream on every
481+
# rank before warmup requests any, else best-fit diverges across ranks and deadlocks.
482+
runner = BreakableCUDAGraphRunner(_Body().cuda())
483+
events = []
484+
monkeypatch.setattr(
485+
"tensorrt_llm._torch.pyexecutor.breakable_cuda_graph_runner."
486+
"promote_synchronized_nccl_window_releases",
487+
lambda: events.append("promote"),
488+
)
489+
monkeypatch.setattr(runner, "warmup", lambda *_args: events.append("warmup"))
490+
491+
def engine_forward():
492+
raise RuntimeError("stop after warmup")
493+
494+
with pytest.raises(RuntimeError, match="stop after warmup"):
495+
runner.capture(4, engine_forward)
496+
497+
assert events == ["promote", "warmup"]
498+
499+
479500
def test_runner_clear_releases_memory_pool_after_graph_reset(monkeypatch):
480501
runner = BreakableCUDAGraphRunner(_Body().cuda())
481502
pool = (12345, 67890)

‎tests/unittest/_torch/test_nccl_window_graph.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,27 @@ def forward(self, hidden_states, **kwargs):
10661066
assert layer(output) is output
10671067

10681068

1069+
def test_promote_synchronized_releases_reads_epoch_before_sync(monkeypatch):
1070+
events = []
1071+
monkeypatch.setattr(
1072+
nccl_window_graph.torch.ops.trtllm,
1073+
"get_nccl_window_buffer_release_epoch",
1074+
lambda: events.append("epoch") or 7,
1075+
)
1076+
monkeypatch.setattr(
1077+
nccl_window_graph.torch.cuda, "synchronize", lambda: events.append("synchronize")
1078+
)
1079+
monkeypatch.setattr(
1080+
nccl_window_graph.torch.ops.trtllm,
1081+
"promote_nccl_window_buffer_releases",
1082+
lambda device, epoch: events.append(("promote", device, epoch)),
1083+
)
1084+
1085+
nccl_window_graph.promote_synchronized_nccl_window_releases()
1086+
1087+
assert events == ["epoch", "synchronize", ("promote", 0, 7)]
1088+
1089+
10691090
@pytest.mark.parametrize("configured", [False, True])
10701091
def test_preallocation_uses_metadata_without_dummy_storage(monkeypatch, configured):
10711092
from tensorrt_llm._torch.custom_ops.torch_custom_ops import AllReduceRunner

0 commit comments

Comments
 (0)