Skip to content

[AMD] [Fix] Fix --attention-backend triton work for DeepSeek MLA on MI355 (null-K + decode dispatch + RoPE) - #30355

Merged
HaiShaw merged 5 commits into
sgl-project:mainfrom
yichiche:pr/deepseek-mla-triton-null-k
Jul 15, 2026
Merged

HaiShaw merged 5 commits into
sgl-project:mainfrom
yichiche:pr/deepseek-mla-triton-null-k

Conversation

@yichiche

@yichiche yichiche commented Jul 7, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

DeepSeek MLA models could not run with --attention-backend triton on gfx95 (MI300/MI355) when SGLANG_USE_AITER=1 (the ROCm image default). Triton is the common NVIDIA/AMD path and should not GPU-fault or produce wrong output on a valid backend selection.

Root cause is a recurring anti-pattern: several gfx95/aiter fused MLA paths are gated on env vars (SGLANG_USE_AITER, SGLANG_ROCM_FUSED_DECODE_MLA) or on "not in the absorb-core backend list", not on the actually selected attention backend. As a result the triton backend inherits aiter-only fused paths that it cannot consume:

  1. Prefill null-K GPU fault — in forward_absorb_core, triton fell into the aiter-fused fused_qk_rope_cat_and_cache_mla path, which writes K into the KV cache and returns an empty k (numel=0, null ptr) for the aiter kernel to read from the buffer. Triton's extend kernel reads k directly → Memory access fault on address (nil).
  2. Decode dispatch fault — _dispatch_mla_subtype honored SGLANG_ROCM_FUSED_DECODE_MLA=1 for any backend, routing triton decode to MLA_FUSED_ROPE_ROCM (forward_absorb_fused_mla_rope_prepare), which is neither MXFP4-aware (bmm sees packed w_kc, 64 vs 128) nor triton-metadata-compatible (ForwardMetadata unpack).
  3. Accuracy 0.03 — _skip_rope_for_aiter_fused_mla returned True for triton (backend not in the absorb-core list), so RoPE was silently skipped in prepare while triton took the standard cat path → garbage output.

Modifications

forward_mla.py:

  • forward_absorb_core: gate the aiter-fused path to self.current_attention_backend == "aiter" so triton builds a real k = torch.cat([k_nope, k_pe]) with save_kv_cache=True.
  • rope-in-prepare condition: allow triton through (or self.current_attention_backend == "triton").
  • _skip_rope_for_aiter_fused_mla: restrict to == "aiter" so triton applies RoPE in prepare (the 0.03 → 0.945 fix).

attention_backend_handler.py:

  • _dispatch_mla_subtype: gate MLA_FUSED_ROPE_ROCM on current_attention_backend == "aiter" so triton (and other backends) decode via the standard MLA path.

All changes are backend-scoped; aiter/fa3/flashinfer/CUDA paths are unchanged.

Accuracy Tests

DeepSeek-R1-MXFP4 (Quark MXFP4), MI355X gfx950, tp4, --kv-cache-dtype fp8_e4m3, gsm8k (200q):

Backend Config gsm8k
aiter (baseline) + spec + cuda graph 0.955
triton (this PR) no spec 0.945

--attention-backend triton now runs DeepSeek-R1-MXFP4 end-to-end with correct output.

Scope / Known Limitation

This PR makes triton MLA correct for non-speculative decode. --attention-backend triton + EAGLE speculative decoding is still broken (GPU fault in the NextN draft/verify path, independent of cuda graph) and is out of scope here — that is a separate draft-path bug. For DeepSeek MLA with speculative decoding, continue using --attention-backend aiter (fully working, 0.955).

Checklist

  • Backend-scoped; no change to aiter/CUDA behavior.
  • Verified triton correctness on real DeepSeek-R1-MXFP4 (0.945).
  • Follows [Tag] Description commit/PR convention.

CI States

Latest PR Test (Base): ❌ Run #29228875042
Latest PR Test (Extra): ❌ Run #29228874957

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@yichiche yichiche added amd run-ci CI: run the baseline test suite on this PR labels Jul 7, 2026
@yichiche yichiche changed the title [AMD] [Fix] Route triton MLA absorb path through real-K cat to fix null-k GPU fault [AMD] [Fix] Make --attention-backend triton work for DeepSeek MLA on gfx95 (null-K + decode dispatch + RoPE) Jul 7, 2026
@yichiche yichiche changed the title [AMD] [Fix] Make --attention-backend triton work for DeepSeek MLA on gfx95 (null-K + decode dispatch + RoPE) [AMD] [Fix] Fix --attention-backend triton work for DeepSeek MLA on MI355 (null-K + decode dispatch + RoPE) Jul 7, 2026
root and others added 2 commits July 7, 2026 08:06
…ll-k GPU fault

DeepSeek MLA models segfault with --attention-backend triton on gfx95 when
SGLANG_USE_AITER=1. In forward_absorb_core, triton is not in
FORWARD_ABSORB_CORE_ATTENTION_BACKENDS so it falls into the else branch, which
was gated only on _use_aiter_gfx95 (env + gfx95, not the attention backend).
That takes the aiter-fused fused_qk_rope_cat_and_cache_mla path, which writes K
into the KV cache and returns an empty k (numel=0, null ptr) for the aiter
kernel to read from the buffer. Triton's extend kernel instead reads k directly
and dereferences the null pointer -> Memory access fault on address (nil).

Gate the fused path on the attention backend not being triton so triton builds
a real k via torch.cat with save_kv_cache=True. Also allow triton through the
rope-in-prepare condition, otherwise gfx95+aiter defers rope to the fused op and
triton's cat path would receive an unrotated k.
@yichiche
yichiche force-pushed the pr/deepseek-mla-triton-null-k branch from 415807c to 16fc178 Compare July 7, 2026 08:06
@yichiche

yichiche commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

@amd-bot ci-status

@amd-bot

amd-bot commented Jul 7, 2026

Copy link
Copy Markdown

@yichiche

CI Status for PR #30355

Merge verdict: ⚠️ Do not merge on a green reading — this PR's code was never exercised by CI. The change is AMD ROCm gfx95 (MI300/MI355) only, but the AMD pipeline is incomplete: wait-for-stage-a-amd timed out (runner-capacity queue, ~4h) and all stage-b/stage-c AMD tests were skipped, including stage-b-test-1-gpu-small-amd-mi35x — the exact MI355 path this PR fixes. All executed failures (XPU, CPU, NPU, x86) are in unrelated backends/infra and none touch the changed code (0 related). But 0 related failures ≠ verified here.

Caution

This PR's changed code is not exercised by any PR-CI test that ran. The diff is gated entirely on _is_hip / _use_aiter_gfx95 / current_attention_backend, so it is inert on NVIDIA/CPU/XPU/NPU. The only jobs that would run it — AMD MI35x stage-b/c — were skipped because wait-for-stage-a-amd timed out (stage-a runner didn't start until 12:14 UTC, ~4h after the wait gate's timeout). Green does not verify this fix. Before merging, re-run AMD CI to completion (rerun / update branch, or add bypass-fastfail sparingly) so the MI35x DeepSeek-MLA-triton tests actually execute, and/or have the author confirm the manual repro: --attention-backend triton on DeepSeek MLA with SGLANG_USE_AITER=1 on gfx95.

Changed files: attention_backend_handler.py (+5/-1), attention_forward_methods/forward_mla.py (+8/-7) — both HIP/gfx95-gated.

Executed CI failure attribution: AMD: 0 executed test failures (stage-a ✅; stage-b/c skipped — see caution) · Others: 7 failures (0 related). Remaining red X's are fast-fail/finish/gate cascade jobs, not independent failures.

Other Executed Failures

Job Test File Test Function Error Related? Why
stage-b-test-1-gpu-xpu test/registered/xpu/test_deepseek_ocr.py TestDeepSeekOCR.setUpClass OSError: libavutil.so.57 / torchcodec / matplotlib missing 🟢 XPU env/dep issue; DeepSeek-OCR model load, not MLA attention path
build-test sgl-kernel/csrc/cpu/norm.cpp N/A (C++ build) norm.cpp:391:18: error: incomplete type 🟢 CPU sgl-kernel C++ build; PR touches no C++
base-a-test-cpu (0) / (2) test/registered/unit/test_legacy_global_ratchet.py TestLegacyGlobalRatchet.test_legacy_accessor_call_sites_match_the_baselines AssertionError: get_global_server_args call-sites grew 281 > 280 🟢 Repo-wide ratchet; PR adds no get_global_server_args call-site
stage-b-test-4-npu-a3 test/registered/ascend/.../HiCache/test_npu_hicache_mla.py TestAscendMlaHicache.test_a_gsm8k OSError: modeling_deepseek.py not found in modelscope cache 🟢 NPU model-download/infra; Ascend backend, not gfx95
stage-b-test-2-npu-a2 (1) test/registered/ascend/.../runtime_opts/test_npu_mla_fia_w8a8int8.py (suite) exit code 1 🟢 NPU backend, unrelated to HIP path
stage-b-test-16-npu-a3 test/registered/ascend/.../expert_parallelism/test_npu_deepep.py (suite) exit code 1 🟢 NPU DeepEP, unrelated
build-test (xeon-gnr) TestIntelAMXAttnBackendQuant test_latency_fp8_moe_model RuntimeError: Failed to parse benchmark output / KeyError 'sglang' 🟢 x86 AMX benchmark harness; unrelated

Details / what to do before merge

  • Coverage gap is the only blocker. The 7 red jobs are all pre-existing/infra failures in backends the PR cannot affect (verified against the diff: everything is behind _is_hip/_use_aiter_gfx95/current_attention_backend). They should not block this PR on causal grounds, but they also prove nothing about it.
  • Get real AMD signal. wait-for-stage-a-amd failed on a timeout, not a test failure — stage-a itself passed (on mi325). The downstream skip means the MI35x DeepSeek-MLA-triton tests never ran. Rerun the AMD workflow (or update the branch) until stage-b/c complete; consider the bypass-fastfail label if you need full signal despite the unrelated early cascade (use sparingly — higher CI cost).
  • Ask the author to attach the manual verification described in the PR body (accuracy 0.03 → 0.945 on --attention-backend triton for DeepSeek MLA on gfx95 with SGLANG_USE_AITER=1), since PR CI did not exercise it.

Generated by amd-bot using Claude Code CLI

@yichiche

yichiche commented Jul 9, 2026 •

Copy link
Copy Markdown
Collaborator Author
  • To close the gap in PR CI (not nightly), I added test/registered/models/test_deepseek_mla_dispatch.py — a hermetic unit test (no GPU/model) registered on the CUDA base-b + AMD stage-b-test-1-gpu-small-amd-mi35x lanes. It pins _dispatch_mla_subtype so the triton+decode+rocm_fused_decode_mla case stays on plain MLA instead of the aiter-only
    MLA_FUSED_ROPE_ROCM fast path (the one that GPU-faults on gfx95). Proven guard: reverting the == "aiter" gate makes test_hip_triton_decode_stays_plain_mla fail; with the fix all 3 cases pass.
  • Full e2e (R1-MXFP4 + NextN + --attention-backend triton, nightly recipe) was launched and got through arg-parse + weight-load before hitting an unrelated OOM from other jobs on the shared box; recipe is valid and can be re-run when ≥4 GPUs are free.
python -m pytest \
    ../test/registered/models/test_deepseek_mla_dispatch.py -v```
    
../test/registered/models/test_deepseek_mla_dispatch.py::TestDispatchMLASubtype::test_hip_aiter_decode_takes_fused_rope PASSED                                                     [ 50%]
../test/registered/models/test_deepseek_mla_dispatch.py::TestDispatchMLASubtype::test_hip_aiter_extend_stays_plain_mla PASSED                                                      [ 75%]
../test/registered/models/test_deepseek_mla_dispatch.py::TestDispatchMLASubtype::test_hip_triton_decode_stays_plain_mla PASSED                                                     [100%]

All pass.

@yichiche
yichiche force-pushed the pr/deepseek-mla-triton-null-k branch from cc0876d to 625cca2 Compare July 13, 2026 06:23
@yichiche

Copy link
Copy Markdown
Collaborator Author

@HaiShaw CI completed, ready to merge.

@HaiShaw
HaiShaw merged commit e78051a into sgl-project:main Jul 15, 2026
177 of 199 checks passed
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amd deepseek run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants