Skip to content

feat(plugins): serve Qwen3.5 GDN decode with unquantized projections on the BF16 op - #76

Merged
zhenhuang12 merged 1 commit into
mainfrom
feat/qwen35-gdn-decode-bf16-projections
Nov 9, 2026
Merged

zhenhuang12 merged 1 commit into
mainfrom
feat/qwen35-gdn-decode-bf16-projections

Conversation

@irvineoy

@irvineoy irvineoy commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Why

The GDN route on Qwen3_5GatedDeltaNet.forward serves only layers whose out_proj is block FP8. For the Qwen3.5 MXFP4 checkpoint (amd/Qwen3.5-397B-A17B-MXFP4), every GDN decode falls back to SGLang. Its Quark config excludes all 45 GDN layers' linear_attn.* projections, so SGLang 0.5.22 runs them with UnquantizedLinearMethod. This PR extends the same route: decode of such a layer goes to [email protected], whose BF16 output out_proj takes as SGLang's own decode hands it.

Scope

  • One route, unchanged target and signature (versions=("0.5.22",)).
    • When out_proj is not block FP8 on aiter's CK GEMM, decode runs on [email protected] alone, provided in_proj_qkvz, in_proj_ba and out_proj are all UnquantizedLinearMethod.
    • The rest stays as on main: SGLang's projections, then the op, _track_mamba_state_decode, and out_proj.
    • This also covers an unquantized BF16 checkpoint of the same model.
  • Left on SGLang: prefill of such layers (there is no BF16-output prefill contract), and projections quantized any other way. LoRA, ReplaySSM, other activations and other modes fall back as on main.
  • The FP8 checkpoint's path is unchanged: same checks in the same order, same ops, same calls with the same arguments.
  • What this PR serves on its own: the MXFP4 checkpoint at 64 rows only, through main's BF16 schema.

Tradeoffs

  • Contiguous projections. For decode batches of up to 64 rows, SGLang 0.5.22 packs the two BF16 input projections into one GEMM (finalize_fused_in_proj, SGLANG_QWEN35_PACKED_IN_PROJ on by default) and hands on column slices of its (rows, 5152) output. Those slices are not contiguous from 2 rows on, and [email protected] reads its inputs row-major, so dispatch would decline them.
    • The route therefore copies both slices contiguous on every call (stateless). At 1 row and above 64 rows they are already contiguous and nothing is copied.
    • The kernels cannot take the packed output: they index fixed 5120- and 32-wide rows.
  • The copies' cost is not measured here, and the bench does not time it (it times the op alone).
    • Estimate: two launch-bound copy kernels (640 KiB of BF16 at 64 rows), roughly 2–5 µs each in a graph replay on MI355X, so 4–10 µs per GDN layer and decode step at 2–64 rows.
    • For scale, main's 64-row BF16 kernel ran 27.3 µs against SGLang's 38.9 µs in an earlier MI355X run (not CI). The copies may take a third to most of that 11.6 µs gain.
    • Check the gain end to end before relying on 2–64 rows.
    • Alternatives: SGLANG_QWEN35_PACKED_IN_PROJ=0 makes SGLang run the two projections separately, so nothing is copied but one more GEMM runs. Or a [email protected] layout variant for strided projection rows plus kernels that take a row stride: a contract and kernel change, not made here.

Verification

Environment: head 5e5d0c6, Mac CPU only: Python 3.12.11, torch 2.8.0 (CPU), no Triton, SGLang or AITER. CI with ci:gpu runs the GPU unit tests on this head; no schema changes, so there is nothing to bench.
Gate overrides: none

Code

  • New tests/plugins/sglang/test_qwen3_5_gdn_route.py: 6 tests on stand-ins of SGLang 0.5.22's modules.

    • A block-FP8 layer decodes on the FP8 op, else the BF16 op, handed SGLang's projections as they are.
    • An unquantized layer decodes on the BF16 op alone, handed contiguous copies of packed column slices, and out_proj takes its (rows, 2048) BF16 output.
    • An unquantized layer's prefill, and other quantized projections, stay on SGLang before any op or projection runs.
    • Against main's api.py, only the unquantized-decode test fails, as expected.
  • FP8 path unchanged: an uncommitted stand-in harness traced every call the route makes into SGLang and the ops, with each argument's shape, dtype, contiguity and identity. On main and on this head it covered 11 FP8-checkpoint scenarios:

    • FP8 op served;
    • FP8 op without a workload, or declining at the call, so the BF16 op serves;
    • both declining;
    • ReplaySSM;
    • the fused AR+norm tuple;
    • LoRA;
    • out_proj on aiter's Triton GEMM;
    • prefill, target verify and idle.

    All 11 traces are identical. For MXFP4 layers, decode at 1, 32, 64 and 128 rows is now served (copies only at 32 and 64); prefill, LoRA and a Quark FP8 out_proj stay on SGLang.

  • python -m aklr export check: exit 0. python -m aklr validate --base origin/main --stages audit: no schema to validate, passed.

  • pytest -q tests/plugins/sglang tests/ops: 185 passed, 62 skipped (main: 179 passed, 62 skipped, plus the 6 new tests).

  • pytest -q tests: 55 failed, 605 passed, 161 skipped, 1 error; the FAILED/ERROR set is identical to main's, all environment-only.

  • pre-commit run --files <changed files>: passed.

Not run

  • This head's CI (ci:gpu): its GPU unit tests, including the new test with real SGLang installed.
  • Either checkpoint served with AKLR_SGLANG_PLUGIN=1. The new branch has not run inside a real SGLang graph capture, its outputs have not been compared with SGLang's in the model, and the copies' cost has not been measured.
  • Multi-GPU (TP4), model accuracy evals and serving throughput.

Risk

Affects:

  • Qwen3.5 GDN decode with unquantized projections on MI355X: the MXFP4 checkpoint (and a BF16 one), at the Points [email protected] serves (64 rows on main; 1–256 rows with the companion PR's schemas).
  • The FP8 checkpoint and every prefill are unchanged.

If wrong:

  • Wrong decode outputs or recurrent and convolution state for those checkpoints, which degrades generation, or an error at graph capture.
  • Slower decode at 2–64 rows if the copies cost more than the kernels gain.

Undo: [email protected] turns the BF16 op off for every checkpoint, main's FP8 fallback at 64 rows included; otherwise git revert.

🤖 Generated with Claude Code

…on the BF16 op

The GDN route on Qwen3_5GatedDeltaNet.forward served only layers whose
out_proj is block FP8, so the Qwen3.5 MXFP4 checkpoint, whose GDN projections
sglang runs unquantized, always fell back. When in_proj_qkvz, in_proj_ba and
out_proj are all UnquantizedLinearMethod, decode now runs [email protected] alone
and hands its BF16 output to out_proj, as sglang's own decode does; prefill of
such layers stays on sglang. The FP8 path keeps its checks, ops and calls.

Up to 64 rows, sglang packs the two BF16 projections into one GEMM and hands
on column slices of its output; the route copies them contiguous for the op,
which reads them row-major.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@zhenhuang12 zhenhuang12 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the latest successful CI run for this head and inspected the change scope. Unit tests and audit passed. No schema changes; benchmark validation is conditionally skipped. The new route tests passed. Approving for the requested squash merge; this does not claim additional end-to-end model validation.

Copilot AI max review requested due to automatic review settings November 9, 2026 01:24
@zhenhuang12
zhenhuang12 merged commit 69208d7 into main Nov 9, 2026
14 of 19 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The packed-projection route can select a slower decode path because its speedup qualification excludes the two .contiguous() copy launches.

1 open issue
What changed in this PR

Extends the Qwen3.5 GDN route to decode layers with unquantized projections, allowing MXFP4 checkpoints’ BF16 GDN layers to use existing AKLR kernels.

Changes:

  • Adds BF16-only decode routing while retaining the existing FP8 path and unsupported-case fallbacks.
  • Makes packed projection slices contiguous and adds six stand-in routing tests.
  • Reuses existing schemas; companion PR #75 expands supported batch sizes.
File Description
tests/​plugins/​sglang/​test_qwen3_5_gdn_route.py Tests FP8/BF16 routing, contiguous projections, and unsupported-case fallback.
aklr/​plugins/​sglang/​models/​qwen3_5/​api.py Adds unquantized-projection eligibility checks and BF16-only decode execution.

Review effort: Max

if not fp8_groups:
# up to 64 rows, sglang runs both BF16 projections as one GEMM and hands on
# column slices of its output; the ops read them row-major
qkvz, ba = qkvz.contiguous(), ba.contiguous()

This branch was previously deployed

1 inactive deployment
gpu-trusted — 5e5d0c69 Deployed Nov 5, 2026 by irvineoy via prepare-gpu / prepare #282
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants