Repository navigation
[Feat] [AMD] linear-attn: Add FlyDSL GDN prefill backend - #39595
Conversation
Expose AITER's fused FlyDSL prepare and state-scan path as a safe gfx95 prefill-only backend with reusable metadata and Triton fallbacks. Co-authored-by: Cursor <[email protected]>
Resolve two conflicts against main: - gdn_backend.py: main added its own init_forward_metadata_out_graph override, so keeping both sides would have defined the method twice and silently shadowed main's target-verify QKV routing. Fold the FlyDSL prefill-metadata reset into main's override instead and keep main's routing helpers unchanged. - test_gdn_prefill_backend_policy.py: import-only conflict; keep main's single-line MambaAttnBackendBase import alongside the backend-choices import. Co-authored-by: Cursor <[email protected]>
Run AITER's FlyDSL stages directly so the adapter returns the per-chunk states that Mamba state tracking reads, instead of falling back to Triton for those batches (most AgentX prefill). Remap padding indices once per batch rather than once per layer. Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
|
test_kimi_k3_b300.py (exit code 1) known fail from #17050 |
This comment was marked as outdated.
This comment was marked as outdated.
|
@chuyeh heads-up — this PR now conflicts with Could you merge or rebase |
Co-authored-by: Cursor <[email protected]>
…__init__ Co-authored-by: Cursor <[email protected]>
|
/rerun-failed-ci |
|
[sglang-bot Review Agent] Could you merge the latest main into this branch? |
Done. @BBuf @sglang-bot PR Test needs a run-ci approval for the current head commit. Could a maintainer comment |
|
[sglang-bot Review Agent] This PR is queued for CI: the review bot starts CI on at most 30 PRs a day so the shared runners stay free. It is #1 in line, expected to start around 2026-11-26 08:55 UTC. |
|
/tag-and-rerun-ci |
…915-merge Co-authored-by: Cursor <[email protected]> # Conflicts: # python/sglang/srt/model_executor/runner/eager_runner.py
…state is set Main's TritonGDNKernel now sets _recurrent_kwargs in its constructor. FlyDSLGDNKernel subclasses it without calling the constructor, so the attribute was missing on FlyDSL instances. The dispatcher only calls extend() on the FlyDSL kernel today, so nothing read it yet. Co-authored-by: Cursor <[email protected]>
|
/rerun-failed-ci |
|
/approve-ci |
1 similar comment
|
/approve-ci |
sglang-bot
left a comment
There was a problem hiding this comment.
[sglang-bot Review Agent] LGTM. Let's wait for CI.
|
/approve-ci |
|
/rerun-failed-ci |
|
/approve-ci |
|
/tag-and-rerun-ci |
|
/rerun-failed-ci |
The FlyDSL GDN prefill dependency (sgl-project#39595) landed on main. Conflicts resolved by taking main's version of the dependency and re-applying only this PR's changes: - The decode/verify "prefill only" guard moved to attention_hook.py on main; extend it there to flydsl_fused instead of re-adding it to gdn_backend.py, and parametrize main's hook-level test over both. - Keep main's _validate_gdn_target_verify_layout next to _validate_fused_flydsl_state_dtype. - The padding-sink fix for padded rows is already on main; keep main's. Co-Authored-By: Claude <[email protected]>
…PI v3 and contract (#103) * [Fix] minimax_m31: Speak megakernel API version 3 and follow SGLang main's contract #66 merged after #81 moved the unit tests to SGLang main, but its last unit run was against the old pinned SGLang, where the MiniMax-M3.1 checks are skipped. On SGLang main the spec is refused at registration and four contract checks fail, so main's unit job has been red since #66. - Megakernel API 3 (sgl-project/sglang#52054 replaced the verify penalty tables with step_penalties): declare 3, as #81 did for the other specs. The package reads no verify sampling penalties (its slots are the verify forward and the DSpark draft proposal), so nothing else changes. - sgl-project/sglang#52870 moved minimax_sparse_nvfp4_backend.py to minimax_sparse/msa_v1_backend.py; msa_v1_decode_plan is the same field. Name the new file first and keep the old one as the alternative. - fused_experts_none_to_flashinfer_trtllm_fp4: sgl-project/sglang#50195 passes the ignored output buffer on the logits-routed path too; the routed-top-k path moe_nofill follows already passed it. Re-pin. - _draft_step and _markov_sample_partial_kernel: sgl-project/sglang#51298 adds a step softcap and vocab limit that only Inkling2's MTP head sets, and #52728 a folded-bias kernel path _draft_step never takes. The chain serves only VanillaMarkov, which leaves both None. Re-pin. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Fix] qwen3_5: Follow SGLang main's GDNAttnBackend.forward_extend sgl-project/sglang#39595 (FlyDSL GDN prefill on AMD) passes prefill_metadata=self.kernel_prefill_metadata to the extend kernel in the prefill arm of forward_extend, None for every kernel but FlyDSL, and adds kernel_prefill_metadata = None to GDNAttnBackend. - gdn/prefill.py serves only the Triton prefill kernel (view.kernel_id), and gdn/verify.py mirrors the target-verify arm, which the change does not touch. Re-pin both mirrors. - The runtime tests' fake GDN backend gains kernel_prefill_metadata=None, as SGLang's class now defines it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Fix] kimi_k31: Follow SGLang main's verify sampling stages in the DFlash runtime sgl-project/sglang#52406 deleted sampling_batch_info.adjusts_logits and speculative/target_verify.py (adjust_verify_logits). SGLang's DFlash round now reads VerifyRoute.adjusts_logits and calls VerifyStep.adjust from SamplingPipeline.plan_verify. The K3.1 DFlash runtime imported both old names, so it no longer imported on SGLang main. - _unserved: VerifyRoute.derive(...).adjusts_logits is the same predicate as adjusts_logits (grammar, watermark, penalties, logit bias or a custom logit processor), so the same rounds go back to SGLang. - _accept, greedy round on gathered logits: the target's sampling_pipeline.plan_verify(batch, watermark_full_mask=False).adjust() runs the same stages in the same order as adjust_verify_logits did: penalties along the chain, logit bias and the custom logit processor, each width rows per request, with no grammar mask. DFlash refuses the watermark, so none is bound. As before, _unserved already refuses every round these stages would change. - The test fakes gain the target's sampling_pipeline and need_min_p_sampling, which SGLang's SamplingBatchInfo defines. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Fix] qwen3_5: Re-pin GDNAttnBackend.forward_extend after sgl-project/sglang#44195 sgl-project/sglang#44195 gives the Triton GDN kernel an FP32 track snapshot and gates the snapshot in forward_extend's prefill arm on use_track_state_snapshot(): a snapshot-capable kernel in batch-invariant mode. - gdn/prefill.py: only --enable-deterministic-inference turns on batch-invariant mode, and it refuses the trtllm_mha attention backend this spec requires. The served prefill arm still writes checkpoints from the per-chunk states, as the slot does. Re-pin. - gdn/verify.py mirrors the target-verify arm, which the change does not touch. Re-pin. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…fused FlyDSL GDN prefill Mixed prefill/decode batches (--enable-mixed-chunk) carry no prefill metadata, so AITER's support check got max_seqlen=None and could still pick the fused kernel. Gate the fused path on the metadata so these batches take sgl-project#39595's Triton fallback, and add a regression test.
Motivation
AITER ships fused FlyDSL implementations of the GDN prepare stages and the K5 state scan for AMD gfx95. Qwen3.5-397B has 45 Gated DeltaNet layers, and at TP4 each rank runs them with 4 key heads, 16 value heads and K=V=128. On those shapes the FlyDSL path runs a prefill batch 1.4-1.74x faster than SGLang's Triton GDN prefill.
This PR exposes that path as an opt-in prefill backend:
Decode and speculative verification stay on Triton. The backend requires gfx95 and is rejected with deterministic inference or multi-item scoring. It also serves batches that track Mamba state for the radix cache, so it stays active with radix cache on (e.g. AgentX). It falls back to Triton for unsupported input/state shapes, mixed batches, and graph-planned paths.
Modifications
flydslin the linear-attention backend enum and CLI choices.FlyDSLGDNKernel, which runs AITER's FlyDSL prepare, FlyDSL K5 state scan, and output stages.chunk_gated_delta_rule_opt_vk, which only returns(o, final_state). Radix-cache Mamba tracking needs the per-chunk statesh, so the adapter keeps them.[N, H, V, K]state pool with indexed in-place updates, reuses the caller-provided output buffer, and remaps DP-attention padding indices to the pool's padding slot once per batch.use_exp2=True(FlyDSL's fused prepare owns the gate cumsum). Recurrent state follows--mamba-ssm-dtype; per-chunk snapshots are bf16.gated_delta_netmodule layout (cf89ffd76, 2026-09-29) or later, which covers main's pin and the-20261020ROCm image.init_forward_metadata) and pass it throughforward_extendso every GDN layer reuses it.SGLANG_USE_AITERand gfx95; reject FlyDSL for decode and verify.GDNAttnBackend.__init__), dispatch, schedule flow into the kernel, padding-index remap, and Triton fallback (test_gdn_prefill_backend_policy.py, 27 passed).Accuracy Tests
Qwen3.5-397B-A17B-MXFP4, TP4, real EAGLE MTP, 200 GSM8K questions, five-shot chat template with thinking disabled:
One answer apart in both modes, which is within sampling resolution at 200 questions. Both arms move together between modes. The radix-off row predates the switch to calling AITER's stages directly; kernel numerics are unchanged by it.
Kernel-level comparison of
FlyDSLGDNKernel.extendagainstTritonGDNKernel.extendon MI355X, TP4 (Hq=4, Hv=16) and TP2 (Hq=8, Hv=32) shapes, K=V=128, BF16 Q/K/V, BF16 and FP32 state, mixed-length batches up to 16K tokens and a padding row:h<= 1.56e-2 (same shape and chunk order as Triton's; about one bf16 step)Qwen3.8-Flash-Next, TP1, same image and tree as the AgentX runs below. FlyDSL vs Triton on Qwen3.8-Flash-Next TP1 shapes (Hq=16, Hv=48): output max abs diff 4.9e-4, final state 7.8e-3, other state slots untouched.
GSM8K with InferenceX's lm-eval (all 1319 questions, five-shot, chat completions), strict match: Triton 0.9765 ± 0.0042, FlyDSL 0.9780 ± 0.0040. Two questions apart, well inside one standard error.
Benchmarking and Profiling
Common setup:
rocm/sgl-dev:v0.5.19-rocm720-mi35x-20260913with radix cache off and BF16 SSM; AgentX images are listed under AgentX benchmark.GDN prefill microbenchmark
One prefill batch through all 45 GDN layers, TP4 per-rank shapes, wall time including the per-batch schedule build:
Below ~4K tokens both are launch-bound, so a batch saves ~3-4 ms. A 70K prompt is five 16384-token chunks and saves about 57 ms.
Fixed-length serving
--disable-radix-cache).2b0f3e2992, the same backend before a main merge.Median TTFT and E2E drop 2.5-4.6% and throughput rises ~3% at every concurrency. The 63 ms TTFT saving at concurrency 1 matches the 57 ms predicted above. At concurrency 4 and 8 the P90 tail is set by prefill queueing and stays inside its 5-12% variance.
AgentX benchmark
semianalysis_cc_traces_weka_062126_256k, in the order Triton, FlyDSL, FlyDSL, Triton; each value is the mean of an arm's two runs. Within a point both arms use the same commit and differ only in--linear-attn-prefill-backend. Not official InferenceX results.amd/Qwen3.5-397B-A17B-MXFP4; upstream now uses the AttnFP8-V2 checkpoint, same GDN dimensions): recipeqwen3.5_fp4_mi355x_sglang_mtp.sh, clientaiperf profile --scenario inferencex-agentx-mvp, 0 failed requests. TP4 (c4 on67fc5b96, c16 on93f3073fe9) usesrocm/sgl-dev:v0.5.19-rocm720-mi35x-20260915with no KV offload. TP2 (fba97a0033) usesrocm/sgl-dev:v0.5.22-rocm724-mi35x-20261020with HiCache DRAM (--hicache-ratio 1.5, write-through).amd/Qwen3.8-Flash-Next-Quark-MXFP4-AttnFP8-PLEFP8), TP1: server and client args from InferenceX upstream (qwen3.8next/sglang/mi355x-fp4-mtp/agentic.yamlat1f8cf90a7), clientinfx.bench agentic(agentx-harness 1.0.14), imagelmsysorg/sglang-rocm:v0.5.23-rocm10-mi35x-20261110, treeb8b631c903(this PR's changes are unchanged since; the head now also merges main at7f8f1351b8). c48 runs with HiCache DRAM, c4 and c16 without offload.Qwen3.5, TP4, concurrency 16:
Qwen3.5, TP2, concurrency 40, with HiCache:
Qwen3.8-Flash-Next, TP1, concurrency 16, no KV offload:
Qwen3.8-Flash-Next, TP1, concurrency 48, with HiCache:
Neutral to slightly better at every point, and nothing regresses beyond the spread. Qwen3.5 gains the most at TP2 c40, the most loaded point: TPOT −2-3%, P90 E2E −4%, interactivity +2-3%. At TP4 c16 it's about 2% on P90 TPOT and interactivity. Qwen3.8-Flash-Next moves less: 1-2% on c16 median latency, 1% on c48 median E2E and total throughput. TPOT and interactivity move because decode waits while a prefill batch runs, and FlyDSL shortens those batches. TTFT mostly stays within the spread because 83-91% of prompt tokens hit the prefix cache, so a typical prefill batch has only a few thousand new tokens (Qwen3.8-Flash-Next computes only about 1.6K, 6.0K and 10.1K new prompt tokens/s at c4, c16 and c48).
Lower-load points: Qwen3.5 TP4 c4 and TP2 c36, Qwen3.8-Flash-Next c4
Qwen3.5, TP4, concurrency 4:
Qwen3.5, TP2, concurrency 36, with HiCache:
Qwen3.8-Flash-Next, TP1, concurrency 4, no KV offload:
Only P90 E2E at TP2 c36 (−3%) is beyond the spread in these tables. Every other change is within it.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ⏳ Run #45837557150
Latest PR Test (Extra): ⊘ Skipped -- add the
run-ci-nv-extralabel to opt in.Latest PR Test (AMD ROCm 10): ✅ Run #45837566220
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: