Skip to content

dsv4.1-amd: serve DeepSeek-V4.1 on gfx950 - #41308

Merged
HaiShaw merged 10 commits into
sgl-project:mainfrom
kevin-mii:dsv41-amd-5-integration
Sep 30, 2026
Merged

HaiShaw merged 10 commits into
sgl-project:mainfrom
kevin-mii:dsv41-amd-5-integration

Conversation

@kevin-mii

@kevin-mii kevin-mii commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Integration PR of the DeepSeek-V4.1 AMD (gfx950 / MI350X) series. It follows the CUDA dsv4.1 layout (#39646, #39652, #39653, #39656, #39664, then #38798): kernel PRs by domain with no callers, then this PR with the callers. With it, DeepSeek-V4.1-Flash serves on gfx950 with DSpark.

The kernel PRs #41018, #41019, #41020 and #41021 are merged; this branch is one commit on main with the callers.

Modifications

  • Attention. deepseek_v4_backend_hip_radix.py serves V4.1: the compact V4.1 KV pages through compact_attention_hip (dsv4.1-amd: gfx950 sparse decode attention and sorted top-k #41020), the swap-AB Gluon kernel for small decode batches, DSpark draft and target-verify metadata, and breakable-CUDA-graph prefill. dsv4/low_ratio_backend_hip.py orchestrates the ratio-1 / 2 indexer, like main's dsv4/v41_indexer: FlyDSL fp4 paged MQA logits over the split index-K pools (dsv4.1-amd: KV cache layouts, FP4 indexer, compressor and router kernels #41019), then the candidate-block and sorted top-k kernels (dsv4.1-amd: gfx950 sparse decode attention and sorted top-k #41020). hip_flash_mla.py routes the HIP decode kernels (SGLANG_HACK_FLASHMLA_BACKEND=auto: aiter's sparse kernel on gfx950, tilelang elsewhere).
  • Dense fp8. fp8_hip.py serves 32x32-block fp8 checkpoints as MXFP8 on the gfx950 native route (dsv4.1-amd: gfx950 MXFP8 matmul kernels and fp8-grid producers #41018); the RMSNorm, SiLU and wo_a producers hand it fp8-grid or MXFP8 operands (deepseek_common/amd/deepseek_v4_gfx95_dense.py, deepseek_v2_hip_act.py).
  • mHC. deepseek_v4_fused_mhc.py runs each sublayer boundary as one launch, with its Sinkhorn carried by the next RMSNorm, and the TP4 all-reduce fused with the mHC post for decode batches of 1-8 rows (dsv4.1-amd: fused mHC boundary and all-reduce + mHC post kernels #41021).
  • MoE and Engram. The split-K router GEMV and gate for DeepSeek-V4 gates (dsv4.1-amd: KV cache layouts, FP4 indexer, compressor and router kernels #41019). Engram's all-reduce and reduce-scatter add BF16 rows as int32 on ROCm, so they are bit-exact.
  • Other. DSpark runs on HIP. SGLANG_OPT_USE_AITER_BATCHED_GEMM now defaults to on for ROCm. The paths validated only on gfx950 are gated on gfx950, so MI300 (gfx942) keeps main's DeepSeek-V4 paths.
  • Kept on main. No HIP attention CP (HIP prefill CP stays rejected), no torch prefill-indexer oracle on HIP, no fp32 V4 router torch.mm, and no diagnostic or cosmetic edits to main code; the fuller branch is kept on kevin-mii/sglang:dsv41-amd-5-integration-full-20260928.
  • Fixes from end-to-end testing.
    • hip_flash_mla._uniform_indptr caches only row pointers built outside graph capture. V4.1 DSpark captures a candidate_unfiltered and a candidate_filtered verify graph per batch size with the same row-pointer shape; the filtered one (longest request above 16K tokens) reused a tensor only the unfiltered graph writes, in graph-pool memory other graphs overwrite, and _pa_decode_sparse faulted (HSA_STATUS_ERROR_MEMORY_FAULT) at 32K context with concurrent requests.
    • An eager DSpark verify batch (past --cuda-graph-max-bs-decode, e.g. more than 64 requests under the default 256 running) no longer asserts on the missing host seq lens; it sizes metadata from candidate_max_seq_len_upper_bound, without a host sync.
    • DeepSeek-V4 (not V4.1) with EAGLE died on its first request on HIP: EAGLE fell back to the backend's max_context_len once the per-step seq_lens.sum() sync was gone, and DeepseekV4HipRadixBackend had none. It now builds a QLEN_ONLY verify mask like the CUDA V4 backend.
    • Cookbook: the MI350X cells export AITER_FLYDSL_FORCE_REDUCE=1 and AITER_BF16_FP8_MOE_BOUND=0 (the published cells could not start with the pinned aiter), keep DSpark in both cells, cap decode graphs at 128 (low-latency) / 256 (high-throughput), and enable --enable-decoder-swa-bounded-replay.
    • --enable-encoder-swa-bounded-replay crashed on HIP while capturing graphs (window_layout() got a stale replay= argument); the HIP backend now passes the per-request floor like the CUDA backend.

The ROCm code lives in models/deepseek_common/amd/ and the HIP backend files. deepseek_v4.py and deepseek_v2.py call into it only on HIP.

Changes visible off ROCm

Each of these is a no-op for CUDA / NPU:

  • deepseek_v4.py: q=, inv_rope= and router_logits_partials= are passed only when set. The hc_mix gate keeps CUDA's conditions. The three input-norm sites keep their gfx95-only fp8 quant, so gfx1250 is unchanged.
  • dspark_draft_model.py: the stacked-dequant path requires a 2-D weight.
  • deepseek_v4_backend.py: the split index-K store is taken only when the pool reports the split layout, which is HIP only.

Tests

  • Tests. Runtime tests sit with their subsystem, as in dsv4.1: remaining model and runtime integration #38798: the HIP backend, fused-compress and aiter_sparse backend tests in attention/unittests/dsv4/; the wo_a, MoE, fused-mHC and TP4 torchrun model tests in unit/models/; kernel cases live in the kernel PRs. All pass on MI350X on this branch with the kernel PRs' tests; the TP4 test compares fused and unfused mHC outputs eagerly (registered-buffer copy-in) and under graph replay.

  • End to end. DeepSeek-V4.1-Flash, 4x MI350X, TP4 / EP4, DSpark, --attention-backend dsv4 --kv-cache-dtype fp8_e4m3 --page-size 256 --disable-radix-cache, AITER_BF16_FP8_MOE_BOUND=0. The comparison is back to back on one node against this series' previous integration head (3e8187f, kept as dsv41-amd-4-model-old-stack), same flags, --cuda-graph-max-bs-decode 128. The old head aborts in aiter's _varctx_cta_info_kernel when it captures decode graphs above 128; dsv4.1-amd: KV cache layouts, FP4 indexer, compressor and router kernels #41019's in-tree schedule fixes that.

    This PR's numbers are from the current head (0a0c59e) in an environment built as the contribution guide describes: sglang-kernel built from python/sglang/kernels/aot/ with setup_rocm.py install and sglang installed from the checkout, as docker/rocm.Dockerfile and AMD CI do, keeping the Dockerfile's apache-tvm-ffi pin. GSM8K is five runs.

    previous head this PR
    GSM8K (200 questions) 0.895 0.890 (0.860-0.910)
    random 4096 in / 1024 out, concurrency 1 476.7 tok/s 508.5 tok/s
    concurrency 8 1,779.6 tok/s 1,863.6 tok/s
    concurrency 32 3,175.6 tok/s 3,265.2 tok/s
  • Fixes. V4.1-Flash, cookbook low-latency flags, 4x MI350X: random 32768 in / 256 out at concurrency 4 faults on every run at f84617215d and completes 8/8 with this branch; 4096 in at concurrency 4 and 32K at concurrency 1 pass on both. Concurrency 80 (1K in / 256 out) asserts on seq_lens_cpu at f84617215d; with this branch it completes 160/160 at 2,599 tok/s and GSM8K at --parallel 128 scores 0.915 / 0.915. test_hip_flash_mla_aiter_sparse.py::TestUniformIndptrGraphs fails on the old cache and passes now.

  • Cookbook. Same node, V4.1-Flash, random 4096 in / 1024 out. Low-latency cell: 524 / 2167 / 4072 tok/s at concurrency 1 / 8 / 32, GSM8K 0.910 / 0.915 / 0.890. High-throughput cell: 523 / 2180 / 4089 at 1 / 8 / 32 and 5186 / 7558 / 8976 at 64 / 128 / 256, GSM8K 0.890 / 0.885 / 0.870; plain decode (the previous high-throughput cell) reaches 2751 / 4641 / 6125 at 64 / 128 / 256. At concurrency 1 with 128K in (90% prefix hit) / 1K out, decoder SWA replay cuts TTFT from 860 to 576 ms and E2E from 2.53 to 2.25 s; encoder SWA replay is correct (GSM8K 0.88-0.895) but slows decode by 78%, so the cells leave it off.

  • DeepSeek-V4 on MI350X. V4-Flash (fp4), TP4 (the cookbook cells are TP8; this node has 6 GPUs), MI355X low-latency cookbook flags with EAGLE, against main at the merge base with main's sgl-kernel: 243 / 1265 / 3280 vs 227 / 1259 / 3274 tok/s at concurrency 1 / 8 / 32, GSM8K 0.97 vs 0.96. With SGLANG_HACK_FLASHMLA_BACKEND unset, the new auto default (aiter_sparse on gfx950) beats main's tilelang default: 252 / 1223 / 2815 vs 217 / 939 / 1720. Not run: TP8, V4-Pro (it does not start at TP4 on main either), MI300.

Deployment note

Set AITER_BF16_FP8_MOE_BOUND=0 until ROCm/aiter#5802 is in the aiter pin. At the default bound, small batches take aiter's BF16-activation MoE route, which does not apply swiglu_limit and, with the current pin, has no kernel for these experts: the server fails during decode-graph warmup. The MI350X cookbook cells export it.

Not in this PR

  • deepseek_v4_backend_hip_radix.py is over 3k lines. Splitting out the late-layer tail and breakable-prefill sections, and binding more CUDA backend methods instead of HIP copies, are follow-ups.

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ✅ Run #36673478589
Latest PR Test (Extra): ✅ Run #36673478176
Latest PR Test (AMD ROCm 10): ❌ Run #36673478517

Duyi-Wang added a commit to AMD-yanfeiwang/sglang that referenced this pull request Oct 12, 2026
…flicts with sgl-project#41308

sgl-project#41308 added an `inv_rope` argument next to this PR's `wo_a_quant_freqs`.
Conflict resolution only, no functional change:
- deepseek_v4_backend_hip_radix.py `_forward_attention`: keep both
  `inv_rope` (main) and `wo_a_quant_freqs` (this PR); keep main's docstring
  and this PR's `Union[Tensor, Tuple[Tensor, Tensor]]` return type.
- deepseek_v4.py `MQALayer.forward`: keep main's `inv_rope =
  _hip.attention_inv_rope(...)` followed by this PR's `wo_a_quant_freqs =
  None`; in the unified branch forward both `inv_rope` and
  `wo_a_quant_freqs` through rope_kwargs. `attention_inv_rope` returns None
  whenever `unified` is set, so the two never apply together.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amd bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) bypass-fastfail deepseek documentation Improvements or additions to documentation jit-kernel memory-pool quant LLM Quantization run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci) sgl-kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants