Skip to content

Reduce repeated attention setup during speculative decoding - #38213

Open
ormandj wants to merge 2 commits into
sgl-project:mainfrom
ormandj:pr/kpool-metadata-fusion-main
Open

ormandj wants to merge 2 commits into
sgl-project:mainfrom
ormandj:pr/kpool-metadata-fusion-main

Conversation

@ormandj

@ormandj ormandj commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Motivation

GLM-5.3-Flash's compressed sparse attention repeatedly prepares sequence lengths, page tables and attention schedules during generation. The existing path performs separate GPU operations for this bookkeeping, and draft backends can rebuild metadata already produced for the same step. This PR combines those updates and reuses compatible fresh metadata, reducing repeated setup work around model forwards without changing the attention inputs.

This is an opt-in optimization, not a fix for incorrect model answers. It restores the active metadata-fusion option removed by #38071 as a separate change against main. No isolated end-to-end speedup has been measured.

Replaces #38162, which was closed when the base branch for #36507 was deleted after its merge as 97c6978369.

Modifications

  • Fuse KPool metadata updates for decode, target verification, draft extension and MTP precompute.
  • Preserve live-tail lengths, bound scans, and reuse compatible freshly generated draft metadata without replacing destination buffers.
  • Enable with SGLANG_EXPERIMENTAL_DSA_KPOOL_METADATA_FUSION=1 only for supported CUDA/page geometry. The option defaults off; removed in-graph and preallocated-plan experiments remain excluded.

Accuracy Tests

Author CPU validation at 2b7ca22a8b: 3 tests and 6 subtests passed, with CUDA hidden. Its Python runtime and test trees are unchanged at refreshed head 342fba81d1 on main afe90a8bc9. Earlier GPU and serving results retain their stated source scope.

The GPU tests feed the same sequence lengths and page mappings to the fused kernels and eager references, then compare their output tensors at pool, page and top-k boundaries, including partially filled live tails. This checks that combining the setup operations preserves the metadata consumed by attention. CPU tests cover the CUDA and page-geometry eligibility checks and verify that non-CUDA inputs decline the fused path.

PYTHONPATH=python compute-sanitizer --tool memcheck --error-exitcode 99 python -m pytest -q test/registered/kernels/ops/attention/test_dsa_metadata.py

Author run at efd2a02d03 on RTX PRO 6000 Blackwell (SM120), Transformers 5.12.1 / Tokenizers 0.22.2: 9 passed, 6 subtests passed; Compute Sanitizer reported ERROR SUMMARY: 0 errors. The CPU contract tests passed three tests and six subtests.

Speed Tests and Profiling

No isolated fusion-on/off benchmark. Full-integration results do not measure this option's contribution.

Checklist

  • Add CPU and GPU regression coverage.
  • Format changed files with upstream tools.
  • Resolve the rebase conflict while preserving the HIP KPool ratio <= 1 path and the opt-in CUDA fusion path.

Developed with AI assistance.


CI States

Latest PR Test (Base): ❌ Run #34282249711
Latest PR Test (Extra): ❌ Run #34282249510
Latest PR Test (AMD ROCm 7.2): ❌ Run #34282249790

@ormandj
ormandj force-pushed the pr/kpool-metadata-fusion-main branch from 1c16dd8 to 85a23ef Compare September 8, 2026 02:45
HanHan009527 added a commit that referenced this pull request Sep 8, 2026
Adapt metadata-only paths from upstream PR #38213 at 85a23ef. Preserve HIP fallback and exclude sibling-copy changes. Cover empty batches, boundary values, and long-context graph replay with changing inputs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant