Repository navigation
Conversation
Woody-Hu
marked this pull request as ready for review
October 27, 2026 13:16
Woody-Hu
requested review from
hanming-lu,
hebiao064,
yizhang2077 and
yuan-luo
as code owners
October 27, 2026 13:16
This comment has been minimized.
This comment has been minimized.
When a donated prefill checkpoint is not on the 64-token FLA chunk grid, the radix track path restores the recurrent state from ``h``, which is allocated with the activation dtype (bf16) and is already rounded, while the aligned path copies the fp32 ``last_recurrent_state``. Forward ``track_state`` / ``track_chunk_idx`` through ``chunk_gated_delta_rule`` and declare ``supports_track_state_snapshot`` on ``TritonGDNKernel`` so the chunk kernel writes the fp32 chunk-boundary state into the buffer the backend already allocates.
Woody-Hu
force-pushed
the
hudi/a100-gdn-radix
branch
from
October 28, 2026 01:43
a04a039 to
7705f6c
Compare
detain
added a commit
to detain/sglang
that referenced
this pull request
Oct 29, 2026
When a donated prefill checkpoint is not on the 64-token FLA chunk grid, the radix track path restores the recurrent state from ``h``, which is allocated with the activation dtype (bf16) and is already rounded, while the aligned path copies the fp32 ``last_recurrent_state``. Forward ``track_state`` / ``track_chunk_idx`` through ``chunk_gated_delta_rule`` and declare ``supports_track_state_snapshot`` on ``TritonGDNKernel`` so the chunk kernel writes the fp32 chunk-boundary state into the buffer the backend already allocates. Successor to our entry-185 port of sgl-project#44195: the chunk.py plumbing and the declaration already landed; this retargets the consumer-side forwarding gate in TritonGDNKernel._extend from the supports flag to the presence of the buffer (head semantics), and carries the PR's snapshot test. The entry-185 fork case test_extend_without_snapshot_support_passes_nothing contradicted the new gate (the flag now only gates the backend's allocation, already pinned by the dispatch test) and is retargeted to test_extend_without_a_snapshot_forwards_nothing. (cherry picked from commit 7705f6c) PR: sgl-project#46839 (open, ported) (cherry picked from commit d24a46d6bd689c62ad1e64694931186cae7150a8)
5 tasks done
This branch has not been deployed
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
hybrid_linear_attn_backend._track_mamba_state_extendrestores a radix checkpoint whose depth is not on the FLA chunk grid (64 tokens) from the per-chunkhtensor.his allocated with the activation dtype and is "already rounded to the activation dtype" — bf16 for a BF16 checkpoint. Snapshot-capable kernels avoid that rounding by writing the chunk-boundary state in fp32 intotrack_state, andgdn_backendallocates that buffer only when the extend kernel declaressupports_track_state_snapshot.All KDA kernels declare it. GDN's Triton kernel declared
supports_packed_decodeandsupports_strided_target_verify_qkvbut not this flag, andfla/chunk.pydropped the two arguments on the way tochunk_gated_delta_rule_fwd_h— which already accepts them and asserts fp32. So for GDN with an fp32 state pool, a hit whose cached depth was not a multiple of 64 resumed from a bf16-rounded state.Measured on A100-SXM4-80GB, BF16
Qwen/Qwen3.5-4B, TP=1,--attention-backend triton --enable-deterministic-inference, prompt 2934 tokens hitting at 2880 (2934 % 64 = 54):| branch |
max|Δlogp|hit vs flushed cold, before | after | output ids ||---|---:|---:|---|
| A | 3.756e-2 | 0.0 | 32/32 equal |
| B | 1.802e-1 | 0.0 | 32/32 equal |
Controls: aligned donation (prompt 1408 = 22×64) was already bit-exact before the patch, and cold-vs-cold is 0.0 with and without it, so the change is confined to the hit path. Also bit-exact at 8k and 16k prefixes, TP=2, and with Qwen3.5-9B.
Change
python/sglang/kernels/ops/attention/fla/chunk.py: accepttrack_state/track_chunk_idxinchunk_gated_delta_ruleand itsautograd.Function, and pass them tochunk_gated_delta_rule_fwd_h.python/sglang/srt/layers/attention/linear/kernels/gdn_triton.py: declaresupports_track_state_snapshot, and forward the two kwargs fromextend.Both default to
None, so no other caller changes and the untracked path is untouched (covered by a test).Tests
test/registered/attention/unittests/gdn/test_gdn_track_state_snapshot.pychecks that the capability flag is set, that the buffer holds the fp32 chunk-boundary state bit-for-bit (against the state an aligned 128-token run writes back), and thatextendwithouttrack_statestill matches the plain chunk kernel.On the parent commit the new test fails with
TypeError: chunk_gated_delta_rule() got an unexpected keyword argument 'track_state'and with the capability assertion unmet.Scope
mamba_ssm_dtype=float32). With--mamba-ssm-dtype bfloat16both paths round once to bf16 and this divergence is masked.bmm_fp8batch-shape dependency. The state-precision path is orthogonal, and this PR does not claim to fix that report.(num_tracked_seqs, *state_shape)allocation per tracked prefill layer-forward, the same allocationkda_backendhas always made).Question for maintainers
If you would rather eliminate unaligned checkpoints altogether (keep chunked-prefill cuts on the mamba chunk grid) than make the unaligned restore exact, please say so and I will close this.
CI States
Latest PR Test (Base): ❌ Run #40616736653
Latest PR Test (Extra): ❌ Run #40616736503
Latest PR Test (AMD ROCm 10): ❌ Run #40616736604
Re-validated after rebasing onto latest
main(54be2010d3): A100-SXM4-80GB, BF16 Qwen3.5-4B, TP=1,n_prompt=2059withcached_tokens=2048on device —max|Δlogp|hit vs cold =0.0for both branches with the patch; the same probe against an unpatched build gives5.85e-2/6.03e-2(top-1 unchanged). Unit tests:Ran 3 tests in 13.008s — OK.