[AMD] Enable FP4 indexer for Deepseek V4 - #37353
Merged
HaiShaw merged 20 commits intoSep 2, 2026
Merged
Conversation
Add an AITER-based DeepSeek V4 FP4 indexer on gfx95: - Switch the C4 indexer K cache to a split payload/scale layout for FP4 data and UE8M0 scales. - Update indexer cache accounting from 132 to 68 bytes per C4 token and share the calculation between the pool and configurator. - Apply RoPE, Hadamard rotation, and FP4 quantization to projected Q through AITER. - Make compress_forward emit BF16 directly and dispatch the norm/RoPE/store stage to the AITER FP4 cache writer. - Use the AITER FP4 paged-MQA logits kernels for decode and prefill QK scoring while reusing the existing top-k path. - Reuse the model RoPE cos/sin cache instead of rebuilding it on every forward. The initial implementation supports regular prefill and decode only. MTP, TBO, HiCache, and PD disaggregation are not supported yet.
Target verify sized its page table from the accepted-prefix length, and each EAGLE draft step reused step 0's sequence lengths and KV write locations, so every step got the same compression boundary, RoPE position, and cache slot. Also hoist the FP4 page table, schedule, and logits into per-forward workspaces so the C4 layers share them instead of reallocating a half-gigabyte logits tensor per layer. The prefill schedule is built outside CUDA-graph capture because AITER frees the scratch its schedule kernel reads; decode keeps that build inside the graph and pins the scratch on the workspace instead.
add tests and co author Co-authored-by: AMD-yanfeiwang <256076023+AMD-yanfeiwang@users.noreply.github.com>
RolaoDenthu
requested review from
BBuf,
DarkSharpness,
Fridge003,
HaiShaw,
HydraQYH,
Qiaolin-Yu,
Ying1123,
alphabetc1,
celve,
hanming-lu,
hebiao064,
hnyls2002,
huangtingwei9988,
hzh0425,
ishandhanani,
ispobock,
merrymercy,
xiezhq-hermann,
yizhang2077 and
yuan-luo
as code owners
September 1, 2026 05:22
Collaborator
Collaborator
Collaborator
This was referenced Sep 2, 2026
5 tasks
StevenChenSE
pushed a commit
to StevenChenSE/sglang
that referenced
this pull request
Sep 6, 2026
Co-authored-by: 1am9trash <1am9trash@gmail.com> Co-authored-by: AMD-yanfeiwang <256076023+AMD-yanfeiwang@users.noreply.github.com> Co-authored-by: Thomas Wang <thomawan@amd.com>
This was referenced Sep 6, 2026
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.


Co-authored-by: @AMD-yanfeiwang @1am9trash
This PR is originally based on the work of @AMD-yanfeiwang.
Motivation
Enable the DeepSeek V4 FP4 indexer on gfx95x GPUs through AITER.
AITER’s FP4 paged-MQA kernels use a different K-cache layout from the existing fused SGLang path. The 64-byte FP4 payload and 4-byte UE8M0 scale for each compressed token are stored in separate preshuffled tensors:
[num_pages, 1, 4, 64, 16][num_pages, 1, 4, 64]Supporting this layout requires more than switching the kernel dispatch. This PR adds the corresponding device-pool representation, routes the Q/K RoPE, Hadamard rotation, FP4 quantization, cache writes, and paged-MQA logits through AITER, and introduces reusable scheduling metadata for prefill, decode, and EAGLE MTP.
The cache sizing is updated to reflect the 68-byte FP4 indexer entry. HiCache is also made aware of the split representation by mirroring the payload and scale as separate page-level regions, ensuring that host backup and restore preserve AITER’s physical layout.
Modifications
ROCm dependency
docker/rocm.DockerfileFP4 kernel adapters
python/sglang/kernels/ops/attention/dsv4/fp4_indexer_hip.pypython/sglang/kernels/ops/attention/dsv4/compress.pyAttention runtime
python/sglang/srt/layers/attention/dsv4/indexer.pypython/sglang/srt/layers/attention/deepseek_v4_backend_hip_radix.pypython/sglang/srt/layers/attention/dsv4/compressor.pypython/sglang/srt/layers/attention/dsv4/compressor_v2.pypython/sglang/srt/layers/attention/dsv4/metadata.pypython/sglang/srt/models/deepseek_v4.py_applyoperations.python/sglang/srt/arg_groups/serving_hook.py--enable-deepseek-v4-fp4-indexeron supported gfx95 GPUs.Device memory and sizing
python/sglang/srt/mem_cache/deepseek_v4_memory_pool.pypython/sglang/srt/model_executor/pool_configurator.pyHiCache integration
python/sglang/srt/mem_cache/hicache_storage.pypython/sglang/srt/mem_cache/hybrid_cache/hybrid_pool_assembler.pypython/sglang/srt/mem_cache/hybrid_cache/linker_pool_assembler.pypython/sglang/srt/mem_cache/memory_pool_host.pypython/sglang/srt/mem_cache/storage/mooncake_store/mooncake_store.pyTests
test/registered/kernels/ops/attention/test_fp4_indexer_hip.pytest/registered/unit/mem_cache/test_mem_pool_host.pyAccuracy Tests
Speed Tests and Profiling
Fixed length benchmark:
InferenceX Agentic:
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ❌ Run #33563869960
Latest PR Test (Extra): ❌ Run #33563869631
Latest PR Test (AMD ROCm 7.2): 🚫 Run #33563869924