Repository navigation
dsv4.1-amd: serve DeepSeek-V4.1 on gfx950 - #41308
Merged
Merged
Conversation
kevin-mii
requested review from
Alisehen,
AniZpZ,
BBuf,
DarkSharpness,
Edwardf0t1,
FlamingoPg,
Fridge003,
HaiShaw,
HydraQYH,
OrangeRedeng,
Qiaolin-Yu,
Ying1123,
alphabetc1,
b8zhong,
celve,
ch-wan,
fzyzcjy,
hanming-lu,
hebiao064,
hnyls2002,
huangtingwei9988,
hzh0425,
ispobock,
merrymercy,
mmangkad,
wisclmy0611,
xiezhq-hermann,
yizhang2077,
yuan-luo and
zijiexia
as code owners
September 26, 2026 05:14
This was referenced Oct 5, 2026
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.
Open
4 of 5 tasks
This was referenced Oct 21, 2026
This was referenced Oct 27, 2026
Merged
This was referenced Oct 29, 2026
This was referenced Nov 7, 2026
This was referenced Nov 17, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
deepseek_v4_backend_hip_radix.pyserves V4.1: the compact V4.1 KV pages throughcompact_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.pyorchestrates the ratio-1 / 2 indexer, like main'sdsv4/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.pyroutes the HIP decode kernels (SGLANG_HACK_FLASHMLA_BACKEND=auto: aiter's sparse kernel on gfx950, tilelang elsewhere).fp8_hip.pyserves 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).deepseek_v4_fused_mhc.pyruns 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).SGLANG_OPT_USE_AITER_BATCHED_GEMMnow defaults to on for ROCm. The paths validated only on gfx950 are gated on gfx950, so MI300 (gfx942) keeps main's DeepSeek-V4 paths.torch.mm, and no diagnostic or cosmetic edits to main code; the fuller branch is kept onkevin-mii/sglang:dsv41-amd-5-integration-full-20260928.hip_flash_mla._uniform_indptrcaches only row pointers built outside graph capture. V4.1 DSpark captures acandidate_unfilteredand acandidate_filteredverify 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_sparsefaulted (HSA_STATUS_ERROR_MEMORY_FAULT) at 32K context with concurrent requests.--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 fromcandidate_max_seq_len_upper_bound, without a host sync.max_context_lenonce the per-stepseq_lens.sum()sync was gone, andDeepseekV4HipRadixBackendhad none. It now builds aQLEN_ONLYverify mask like the CUDA V4 backend.AITER_FLYDSL_FORCE_REDUCE=1andAITER_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-replaycrashed on HIP while capturing graphs (window_layout()got a stalereplay=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.pyanddeepseek_v2.pycall 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=androuter_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 inunit/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 asdsv41-amd-4-model-old-stack), same flags,--cuda-graph-max-bs-decode 128. The old head aborts in aiter's_varctx_cta_info_kernelwhen 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-kernelbuilt frompython/sglang/kernels/aot/withsetup_rocm.py installand sglang installed from the checkout, asdocker/rocm.Dockerfileand AMD CI do, keeping the Dockerfile'sapache-tvm-ffipin. GSM8K is five runs.Fixes. V4.1-Flash, cookbook low-latency flags, 4x MI350X: random 32768 in / 256 out at concurrency 4 faults on every run at
f84617215dand 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 onseq_lens_cpuatf84617215d; with this branch it completes 160/160 at 2,599 tok/s and GSM8K at--parallel 128scores 0.915 / 0.915.test_hip_flash_mla_aiter_sparse.py::TestUniformIndptrGraphsfails 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_BACKENDunset, the newautodefault (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=0until ROCm/aiter#5802 is in the aiter pin. At the default bound, small batches take aiter's BF16-activation MoE route, which does not applyswiglu_limitand, 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.pyis 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