Skip to content

[feat] Reuse GDN prefill metadata - #4694

Merged
yixionghuo merged 1 commit into
ROCm:Qwen3.5_devfrom
IzacharyI:reuse_metadata
Aug 12, 2026
Merged

yixionghuo merged 1 commit into
ROCm:Qwen3.5_devfrom
IzacharyI:reuse_metadata

Conversation

@IzacharyI

@IzacharyI IzacharyI commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

GDN variable-length prefill kernels repeatedly derived identical scheduling metadata from cu_seqlens for every layer and kernel stage.

This introduced redundant metadata copies and device-to-host synchronization. This PR adds reusable prefill metadata that can be constructed once per batch and shared across all GDN layers and K1-K6 stages.

Modifications

  • Cherry-pick and adapt the reusable GDR prefill metadata changes from #4532.
  • Preserve the Qwen3.5_dev indexed-state and in-place update behavior.
  • Cache chunk schedules containing:
    • rebased sequence lengths
    • sequence and chunk IDs
    • chunk offsets
    • prefill sequence and token counts
  • Thread optional reusable metadata through:
    • fused cumsum/KKT
    • triangular solve and recompute
    • HIP and Triton hidden-state kernels
    • output kernels
  • Eliminate repeated .tolist() device readbacks and CatArrayBatchedCopy_contig.
  • Preserve the legacy path when metadata is not supplied.
  • Preserve indexed state pools, in-place final-state updates, and decode-prefix handling.

Accuracy Tests

  • Compared legacy and reusable-metadata paths using BF16 inputs and indexed FP32 state.

  • Output and final state matched with:

    • rtol=1e-3
    • atol=2e-3
  • Companion SGLang GDN suite:

    28 passed

Speed Tests and Profiling

Configuration:

  • Model: Qwen3.5-397B-A17B-PTPC
  • Tensor parallelism: TP8
  • Input length: 8000
  • Output length: 1
  • Concurrency: 32

Profiling results with the companion SGLang integration:

  • CatArrayBatchedCopy_contig: 4 -> 0
  • D2H copies before GDN cumsum: 4 -> 0
  • No residual first-layer GDN bubble with a warm allocator:
    • cumsum gap: at most 0.001 us
    • recompute gap: at most 0.001 us
    • chunk-h gap: at most 0.001 us
  • Measured input throughput: 25,463 tokens/s

Checklist

  • Format code with pre-commit.
  • Add permanent unit tests.
  • Update documentation where required.
  • Provide accuracy and profiling results.
  • Follow the project code-style guidance.

@IzacharyI IzacharyI changed the title [PERF] Reuse GDN prefill metadata [feat] Reuse GDN prefill metadata Aug 11, 2026
@zufayu
zufayu requested a review from vgokhale August 12, 2026 02:00
@apinge apinge mentioned this pull request Aug 12, 2026
5 tasks done
@zufayu
zufayu requested review from Dewei-Wang-sh and removed request for vgokhale August 12, 2026 05:01
@yixionghuo
yixionghuo merged commit 779709c into ROCm:Qwen3.5_dev Aug 12, 2026
yicyang added a commit to yicyang/aiter that referenced this pull request Oct 20, 2026
…q_lens_cpu)

chunk_gated_delta_rule_opt_vk derived its chunk indices/offsets from the
device cu_seqlens: prepare_chunk_indices (.tolist()), prepare_num_chunks
(int()) and prepare_chunk_offsets (new_tensor([0]) H2D) each forced a
device->host sync on the first GDN layer of every step. In a serving engine
with async scheduling this stalls mixed prefill/decode steps: measured in
vLLM on MI355X (Qwen3.8-27B), a 4K prefill arriving while 15 requests decode
took +3.9% TTFT with this backend.

Add optional seq_lens_cpu (same name/semantics as ROCm#4694 on Qwen3.5_dev):
register_host_seq_lens() attaches the host lengths to cu_seqlens, and the
three helpers build their results on the host and copy them with pinned
non_blocking H2D. Without seq_lens_cpu behaviour is unchanged, except that
prepare_chunk_offsets uses new_zeros(1) instead of new_tensor([0]).

Verified on gfx950 (torch sync debug mode "error"): with seq_lens_cpu the
Triton-K5 and FlyDSL-K5 paths issue 0 syncs (before: 2 and 3); output and
final state are bit-identical to the original path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants