Repository navigation
Conversation
|
Fork PR — CI jobs were skipped by default. Could a maintainer please help |
This comment has been minimized.
This comment has been minimized.
… NPUs Allow the NGRAM speculative-decoding path on Ascend NPUs with three platform-scoped changes: - speculative_hook: add "npu" to the _handle_ngram device allowlist - kernels/ops/speculative/reconstruct_tree: add a host fallback for reconstruct_indices_from_tree_mask (sgl_kernel ships CUDA-only binaries) and route it from reconstruct_indices_from_tree_mask_func next to the XPU Triton branch - hardware_backend/npu/memory_pool_npu: add an NPU-native move_kv_cache (the base tiled-copy path requires _kv_copy_config, which the NPU paged layout never builds) Verified on Ascend 910C (Atlas 800 A3, CANN 9.0.0): Qwen3-0.6B bf16 serves end-to-end with NGRAM (chain verify, --page-size 128). Benchmark (sglang.bench_serving, random 128/64, 32 prompts, concurrency 8, request-rate 4; 3 runs per config, first on-run as warm-up): Median TPOT drops from ~28.0 ms to ~13.7 ms (-51%) with NGRAM on; output throughput unchanged within run-to-run variance; TTFT +21-30 ms across paired runs (per-request n-gram state init).
3c61156 to
9b7a06d
Compare
|
Your PR does not meet the requirements of the issue. Please verify it promptly. |
|
Hi @gjsheu, thanks for the review. To clarify: the skill deliverables required by this issue (SKILL.md, prompt/invocation templates, baseline-collection scripts, report generation, and recommended launch commands) are submitted to a dedicated skills repository as guided in the task discussion group — see LinyuanLi0046/Ascend-SGLang-Skills#23 This PR covers the code-level part: it upstreams the NGRAM switch from this task's feature evaluation (speculative decoding on Ascend NPU). A full status update covering both PRs is posted on the issue: Ascend#1109 (comment) Happy to adjust if anything specific is missing. |
Motivation
NGRAM speculative decoding is currently restricted to a platform allowlist
(
_handle_ngramrejects non-CUDA/CPU/XPU devices). The restriction is anallowlist check rather than a fundamental dependency: with three
platform-scoped changes, the full NGRAM path (draft lookup → chain build →
target verify → accept-path KV relocation) runs end-to-end on Ascend 910C
(task: Ascend#1109).
This extends speculative-decoding coverage on NPUs, complementing the DFlash2
NPU enablement (#35629, merged) and the NGRAM roadmap (#21052). It is opt-in
and changes nothing for CUDA/CPU/XPU users.
Modifications
srt/arg_groups/speculative_hook.py— allow"npu"in the_handle_ngramdevice allowlist.kernels/ops/speculative/reconstruct_tree.py— the NPU path has nodevice kernel for
reconstruct_indices_from_tree_mask(sgl_kernelshipsCUDA-only binaries, and the module-level import would fail on NPU), so this
adds a host fallback and routes it in
reconstruct_indices_from_tree_mask_funcnext to the existing XPU Triton branch, following the same dispatch pattern
as the HIP routing in [ROCm][Spec] Route NGRAM tree reconstruction to the JIT kernel on HIP #43328 (device kernel there, host fallback here). The fallback reproduces the kernel contract into
the caller's preallocated device tensors (slot identity, tree depth +
seq_len positions, and the tree links); CUDA/CPU/XPU dispatch is unchanged.
srt/hardware_backend/npu/memory_pool_npu.py— the speculative acceptpath calls
move_kv_cache(tgt_loc, src_loc), but the base tiled-copyimplementation requires
_kv_copy_config, which the NPU paged buffer layoutnever builds (see
_init_kv_copy_and_warmup). Add an NPU-nativemove_kv_cachethat relocates slots with plain indexing, viewing each layeras flat
[num_slots, head_num, head_dim](V usesv_head_dim) — the sameconvention
get_cpu_copy/load_cpu_copyalready use for both bufferlayouts.
Accuracy Tests
bf16 served with NGRAM enabled returns coherent greedy chat completions,
with the server stable across repeated requests and the NPU-native
move_kv_cacheinvoked on every accept step.(same four outputs, in-place mutation), mirroring the host tree-link
derivation used by the grammar path (kept as a local copy to avoid a
circular import).
the target model, so accepted tokens come from the target distribution and
output is expected to be token-identical to non-speculative greedy
decoding. A dedicated accuracy benchmark (e.g. GSM8K) was not run in this
setup.
Speed Tests and Profiling
sglang.bench_serving, random 128/64, 32 prompts, concurrency 8,request-rate 4; 3 runs per config, the first on-run serving as warm-up):
decode latency (3-run Median TPOT) drops from ~28.0 ms to ~13.7 ms (−51%)
with NGRAM on.
host-bound 0.6B setup (per-run values ranged ~119–141 tok/s across on/off
runs). TTFT +21–30 ms across paired runs (per-request n-gram state init).
The host-fallback overhead is included in all reported numbers.
Known limitations (pre-existing, not introduced by this PR)
max_bfs_breadth > 1) requirespage_size == 1, which the FIA kernel rejects (blockSizemust be amultiple of 16 in [16, 1024]; see [Bug] [NPU] Ascend FIA attention should reject page_size=1 or document block_size alignment requirement #25169). With
--speculative-ngram-max-bfs-breadth 1the feature works end-to-end;lifting the kernel constraint is follow-up work.
--page-size 128: page_size 16 silently corrupts output on theascend backend — pre-existing, tracked in [Bug] [NPU] ascend attention backend silently corrupts output with page_size 16 (128 OK, 1 rejected per #25169) #38196 (independent of
speculative decoding);
--page-size 128is the correct setting, as on main.sgl_kernel_npu.norm.split_qkv_rmsnorm_rope(hit by any Qwen3 NPU run onthis stack) was worked around locally with the non-fused path; unrelated to
NGRAM, and will be filed as a separate upstream issue.
Environment (hardware verification, 2026-09)
kernels/ops speculative-dispatch refactor ([Refactor] spec: Move platform dispatch and Triton kernels into
kernels/ops#45504). The host-fallbacklogic is unchanged from the originally hardware-verified implementation
(module moved, logic identical); the numbers above were measured with that
logic, and no hardware re-run was done after the rebase.
triton-ascend 3.2.1.dev; sglang source build
--attention-backend ascend --disable-overlap-schedule --disable-cuda-graph --speculative-algorithm NGRAM --speculative-num-draft-tokens 4 --speculative-ngram-max-bfs-breadth 1 --page-size 128on any Qwen3 NPU deployment.CI States
Latest PR Test (Base): ❌ Run #40914727809
Latest PR Test (Extra): ❌ Run #40914727795
Latest PR Test (AMD ROCm 10): ❌ Run #40914727849