Repository navigation
[AMD] sgl-kernel: enable NGRAM speculative decoding on ROCm (build ngram_utils) - #29346
michaelzhang-ai wants to merge 2 commits into
Conversation
…coding NGRAM speculative decoding calls sgl_kernel reconstruct_indices_from_tree_mask (srt/speculative/ngram_worker.py:_prepare_for_speculative_decoding), but the op was CUDA-only: setup_rocm.py compiled only eagle_utils.cu (not ngram_utils.cu), and the op was registered only in common_extension.cc. On ROCm this raised "AttributeError: '_OpNamespace' 'sgl_kernel' object has no attribute reconstruct_indices_from_tree_mask", crashing the scheduler at the first speculative decode step. The kernel is plain CUDA (no CUDA-only intrinsics) and already carries a USE_ROCM include branch, so it hipifies cleanly. Add csrc/speculative/ ngram_utils.cu to the ROCm build sources and register the op in common_extension_rocm.cc. Verified on MI355X (gfx950): the op now dispatches, and an NGRAM + triton attention server (Qwen2.5-Coder-7B) launches and serves correct output.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Expanded this PR to also enable the triton NGRAM-spec test on AMD ( Dispatched both AMD extra lanes to verify: |
e524489 to
f332ef9
Compare
|
Scoped this PR back to kernel-only (reverted the Verification from the dispatched AMD extra lanes:
The triton NGRAM-spec test failed on gfx942 This PR stands alone as a correctness fix: NGRAM speculative decoding previously crashed at the first decode step on ROCm; it now runs. |
Summary
Enables NGRAM speculative decoding on ROCm by building the missing kernel op into the ROCm
sgl_kernel.Root cause
srt/speculative/ngram_worker.py:_prepare_for_speculative_decodingcallssgl_kernel'sreconstruct_indices_from_tree_mask, but that op was CUDA-only:sgl-kernel/setup_rocm.pycompiled onlycsrc/speculative/eagle_utils.cu— notcsrc/speculative/ngram_utils.cu, where the op is defined.csrc/common_extension.cc(CUDA); the ROCm registration filecsrc/common_extension_rocm.ccnever declared it.On ROCm this raised, at the first speculative-decode step:
which crashed the scheduler — so any NGRAM-spec run on ROCm dies immediately (independent of attention backend / model).
Fix
csrc/speculative/ngram_utils.cuto the ROCm build sources insetup_rocm.py.reconstruct_indices_from_tree_maskincommon_extension_rocm.cc(the decl already exists insgl_kernel_ops.h).The kernel is plain CUDA C++ (no warp intrinsics / tensor cores) and already carries a
#ifdef USE_ROCMinclude branch, so it hipifies cleanly.Test plan
Verified locally on MI355X (gfx950), ROCm 7.2:
sgl_kernelwith this change;torch.ops.sgl_kernel.reconstruct_indices_from_tree_masknow dispatches.python -m sglang.launch_server ... --speculative-algorithm NGRAM --attention-backend tritoncrashed with the AttributeError above.ready to roll) and serves correct output (Qwen2.5-Coder-7B-Instruct, e.g. "The capital of France is" → "Paris. Paris is located in the northern part of France...").Note: validated on gfx950; the AMD CI NGRAM-spec lanes (e.g.
test_spec_ngram*) run on gfx942/MI325 — this unblocks them there as well. A follow-up will enable the triton NGRAM-spec test for AMD CI on top of this.CI States
Latest PR Test (Base): ❌ Run #28258198996
Latest PR Test (Extra): ❌ Run #28258198792