Skip to content

[None][fix] mhc: disable PARALLEL distributed tuning for MhcFusedHc - #14675

Merged
hyukn merged 1 commit into
NVIDIA:feat/deepseek_v4from
hyukn:fix/mhc_fused_hc_disable_parallel
May 28, 2026
Merged

hyukn merged 1 commit into
NVIDIA:feat/deepseek_v4from
hyukn:fix/mhc_fused_hc_disable_parallel

Conversation

@hyukn

@hyukn hyukn commented May 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

PR #14458 enabled distributed_tuning_strategy=DistributedTuningStrategy.PARALLEL on both MhcPreMappingRunner and MhcFusedHcRunner. The MhcFusedHc setting triggers a non-deterministic CUDA Illegal Memory Access on TP=8 disagg GEN workers during the post-autotune max-batch CUDA-graph-capture step.

This PR keeps the MhcPre PARALLEL change (where the autotune saving comes from) and disables only the MhcFusedHc PARALLEL change (where the crash comes from).

Reproduction (xqiao container dsv4-435a0a-pr14458, 3-node disagg, 1024-1024 dataset)

Observed on two recipes that ship the same container:

  • 1024-1024/disagg_ctx1_gen1_tep8_batch256_eplb0_mtp0 (TP=8 GEN, max_batch=256)
  • 8192-1024/disagg_ctx1_gen1_dep8_batch512_eplb384_mtp1 (DEP8 GEN, max_batch=512)

Crash signature: rank 6 [executor] Failed to initialize executor: CUDA_ERROR_ILLEGAL_ADDRESS at mla_custom_op_inplace (attention.py:1022), during warmup-2 at Run warmup with 256 tokens, include 256 generation tokens — the cuda-graph-capture step.

A/B/C/D matrix (TP=8 disagg, 3-node, max_batch=256):

MhcPre PARALLEL MhcFusedHc PARALLEL result
ON ON 🔥 IMA in 2 of 3 reruns (A, A2 crashed; A3 passed by luck)
OFF OFF ✅ clean
OFF ON 🔥 IMA (C)
ON OFF ✅ clean (D — this PR's configuration)

Mechanism

MhcFusedHcRunner.__init__ creates self._ws_cache = _FusedHcWorkspaceCache(...). forward() then does:

(residual_cur, post_mix_cur, ..., done_counter_ws) = self._ws_cache.get(
    B, num_k_splits, tile_m, x_prev.device)

The LRU is keyed on (B, ws_ks=max(1, num_k_splits), m_batches, device) — i.e. on the chosen tactic's (num_k_splits, tile_m) fields.

Under PARALLEL, _maybe_parallelize_tactics gives each rank [t for idx, t in enumerate(tactics) if idx % tp_size == tp_rank]. Each rank's local profiling populates the LRU with workspace entries only for the tactics it measured. After _merge_cache_data picks the global-best tactic per shape, ranks that didn't locally measure that tactic miss the workspace LRU at first replay and call _alloc() → torch.empty(...). Because the post-autotune max-batch warmup is a CUDA-graph-capture stage, the fresh allocation lands in a region inconsistent with the captured snapshot, and the next collective kernel (here MLA attention) dereferences a stale pointer → IMA.

MhcPreMappingRunner.forward() does fresh torch.empty(...) every call keyed only on (M, n, hidden_size) — independent of tactic — so its per-rank allocation history is identical under PARALLEL. No divergence, no crash.

Cost

distributed_tuning_strategy=PARALLEL on MhcFusedHc adds essentially no autotune saving on this recipe at TP=8:

GEN autotune block 1 CTX autotune block 1
both PARALLEL (PR #14458 HEAD) 4m 42s 8m 43s
only MhcPre PARALLEL (this PR) 4m 46s 9m 19s
both INDEPENDENT (full revert) 4m 53s 12m 42s

The MhcPre PARALLEL change still buys ~27% CTX autotune reduction (12m 42s → 9m 19s). Disabling MhcFusedHc PARALLEL costs ~52 s of CTX autotune in the worst case, within JIT-compile noise.

Follow-up

Re-enabling MhcFusedHc PARALLEL is feasible after _FusedHcWorkspaceCache is reworked. Two candidate fixes:

  1. Drop tactic-dependent keying from the LRU (size workspace to max over all valid tactics; cost: bounded by the largest (num_k_splits, tile_m) combination).
  2. Add a post-merge warmup hook that pre-populates each rank's LRU for the chosen tactic before the CUDA-graph-capture warmup begins.

🤖 Generated with Claude Code

@hyukn
hyukn requested a review from a team as a code owner May 28, 2026 06:57
@hyukn
hyukn requested review from QiJune and removed request for a team May 28, 2026 06:57
PR NVIDIA#14458 enabled `distributed_tuning_strategy=DistributedTuningStrategy.PARALLEL`
on both MhcPreMappingRunner and MhcFusedHcRunner. The MhcFusedHc setting
triggers a non-deterministic CUDA Illegal Memory Access on TP=8 disagg GEN
workers during the post-autotune max-batch CUDA-graph capture (observed on
the 1024-1024 disagg_ctx1_gen1_tep8_batch256 recipe and the 8192-1024
disagg_ctx1_gen1_dep8_batch512 recipe; ~67% crash rate across 3 reruns of
the same config).

Mechanism: MhcFusedHcRunner has a per-instance LRU workspace cache
(`_FusedHcWorkspaceCache`) keyed on `(B, num_k_splits, tile_m, device)` —
all derived from the chosen tactic. Under PARALLEL, each rank measures
only `idx % tp_size == tp_rank` of the tactics, so each rank's LRU ends up
populated with workspace entries for a different tactic subset. After
`_merge_cache_data` writes the global-best tactic to the autotuner cache,
ranks that didn't locally measure that tactic hit a workspace-cache miss
and call `torch.empty(...)` fresh — inside the post-autotune
CUDA-graph-capture region for the max-batch warmup step. Fresh
allocations are incompatible with capture; the next collective kernel
(MLA attention) dereferences a stale/uncaptured pointer → IMA on the
cache-miss rank (rank 6 at TP=8 in the observed cases).

MhcPreMappingRunner does NOT have this problem: its forward() uses fresh
`torch.empty(...)` every call, keyed only on `(M, n, hidden_size)`,
independent of the chosen tactic. So per-rank tactic-subset profiling
under PARALLEL produces identical allocation histories across ranks.

Per-op cost data on this disagg recipe shows MhcFusedHc PARALLEL adds
~no autotune saving (GEN: 4m 42s with both PARALLEL vs 4m 46s with only
MhcPre PARALLEL — within JIT noise), so dropping it is a clean revert
with no perf cost. MhcPre PARALLEL still buys ~27% CTX autotune
reduction on the same recipe.

A/B/C/D variant matrix at TP=8 disagg (3 nodes, max_batch=256):
  - MhcPre=ON,  MhcFused=ON  (A): IMA in 2/3 reruns
  - MhcPre=OFF, MhcFused=OFF (B): clean
  - MhcPre=OFF, MhcFused=ON  (C): IMA
  - MhcPre=ON,  MhcFused=OFF (D): clean ← this PR's configuration

Re-enabling MhcFusedHc PARALLEL is a follow-up after the workspace LRU
is reworked (e.g. by dropping tactic-dependent keying, or by harmonizing
the LRU across ranks post-merge).

Signed-off-by: Yukun He <[email protected]>
@hyukn
hyukn force-pushed the fix/mhc_fused_hc_disable_parallel branch from a922991 to f4f920a Compare May 28, 2026 07:04
@hyukn
hyukn merged commit f6f6f14 into NVIDIA:feat/deepseek_v4 May 28, 2026
5 checks passed
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 10, 2026
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 11, 2026
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 12, 2026
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants