[Performance] optimize NSA backend metadata computation for multi-step speculative decoding#14781
Conversation
Summary of ChangesHello @Johnsonms, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant performance optimization for the NSA backend's metadata computation, particularly beneficial for multi-step speculative decoding. By refactoring the metadata generation process to precompute common data once and then efficiently copy it to multiple attention backend instances, the system avoids redundant calculations. This change aims to reduce latency and improve the overall efficiency of speculative decoding operations by centralizing and streamlining metadata preparation. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a significant performance optimization for multi-step speculative decoding in the NSA backend. By precomputing shared metadata and reusing it across speculative steps, it avoids redundant computations. The implementation introduces a PrecomputedMetadata dataclass and helper functions to handle different forward modes, which is a clean approach. My review focuses on improving the clarity, consistency, and type correctness of the new code to enhance maintainability.
551fbff to
8eb590d
Compare
|
@Johnsonms Thanks for your codes~ Do you have any e2e performance data. Like what's the change of decode throughput of a bs=1 isl=osl=1024, before and after this pr with MTP |
|
Also can you post the accuracy result of GPQA/AIME benchmark? |
Added the test result, Thanks @Fridge003 |
|
Do you have data of acceptance length? Will it drop after this PR? |
|
eae9bc2 to
0ec0942
Compare
|
/tag-and-rerun-ci |
3c40dcf to
0f366a0
Compare
* 'main' of https://github.com/sgl-project/sglang: (136 commits) fix: unreachable error check in retraction (sgl-project#15433) [sgl-kernel] chore: update deepgemm version (sgl-project#13402) [diffusion] multi-platform: support diffusion on amd and fix encoder loading on MI325 (sgl-project#13760) [amd] Add deterministic all-reduce kernel for AMD (ROCm) (sgl-project#15340) [diffusion] refactor: refactor _build_req_from_sampling to use shallow_asdict (sgl-project#13782) Add customized sampler registration (sgl-project#15423) Update readme (sgl-project#15425) Fix Mindspore model import warning (sgl-project#15287) [Feature] Xiaomi `MiMo-V2-Flash` day0 support (sgl-project#15207) [diffusion] profiling: add bench_serving.py and VBench (sgl-project#15410) [DLLM] Fix dLLM regression (sgl-project#15371) [Deepseek V3.2] Fix Deepseek MTP in V1 mode (sgl-project#15429) chore: update CI_PERMISSIONS (sgl-project#15431) [DLLM] Add CI for diffusion LLMs (sgl-project#14723) Support using different attention backend for draft decoding. (sgl-project#14843) feat(dsv32): better error handling for DeepSeek-v3.2 encoder (sgl-project#14353) tiny fix lint on main (sgl-project#15424) multimodal: precompute hash for MultimodalDataItem (sgl-project#14354) [AMD] Clear pre-built AITER kernels and warmup to prevent segfaults and test timeouts (sgl-project#15318) [Performance] optimize NSA backend metadata computation for multi-step speculative decoding (sgl-project#14781) ...
…p speculative decoding (sgl-project#14781)
…p speculative decoding (sgl-project#14781)
…p speculative decoding (sgl-project#14781)








The NSA backend for multi-step speculative
decoding. The optimization implements a precompute-once-copy-many strategy:
Key Components Added:
method (~50μs vs ~75μs)
Performance improvements:
Opt: 437us per forwards in draft meta forward part, will lanuch 40 kernels