Repository navigation
[Perf] scheduler: Remove implicit CUDA syncs from Mamba extend scheduling - #43637
Closed
alphabetc1 wants to merge 1 commit into
Closed
alphabetc1 wants to merge 1 commit into
alphabetc1 wants to merge 1 commit into
Conversation
alphabetc1
requested review from
Ying1123,
hanming-lu,
hnyls2002,
huangtingwei9988,
hzh0425,
ispobock,
merrymercy,
xiezhq-hermann and
yizhang2077
as code owners
October 11, 2026 03:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
On hybrid Mamba models with
--mamba-radix-cache-strategy extra_buffer, every prefill scheduling step blocks the scheduler thread until the GPU has drained, so the overlap loop loses its lead and the GPU idles while the prefill is being prepared and launched.Running the scheduler with
torch.cuda.set_sync_debug_mode("warn")after warmup and counting call sites: decode steps have no implicit sync, but each extend step has about 15, all on the extend scheduling path:HybridReqToTokenPool.alloc:mapping[select_index] = ...with a Python-list index (twice)_mamba_radix_cache_v2_req_prepare_for_extend:ping_pong_track_buffer[idx].item()prepare_for_extend:torch.tensor(list, device=cuda)for the track indices / mask / seqlensA list index on a CUDA tensor is copied to the device from pageable memory, which waits for the stream; measured in isolation behind 20 queued 8192x8192 matmuls, the list-index setitem blocks the host for 314 ms, the pinned non-blocking index for 0.19 ms. The
.item()round trip exists only to build a CPU list that is immediately copied back to the device.Modifications
HybridReqToTokenPool.alloc: stage the row index once with the existingasync_h2dhelper and use it for both mapping writes._mamba_radix_cache_v2_req_prepare_for_extendreturns the track slot as a device view instead of.item();prepare_for_extendstacks the views intomamba_track_indices(one kernel) and stages the mask / seqlens withasync_h2d. The value read is the same: both read the slot in stream order before any later write.After the change the same sync audit reports no implicit sync in the scheduler loop.
Accuracy / correctness
No change to what is allocated, tracked or cached; hit rate unchanged in the benchmark below.
test_alloc_writes_mappings_without_synchronizing(CUDA): allocates several requests underset_sync_debug_mode("error")and checks both mappings row by row. Fails on main withRuntimeError: called a synchronizing CUDA operationat the list-index setitem.test_track_index_is_the_slot_before_the_flip_and_stays_on_device: the returned track index is the pre-flip slot, stays on the buffer's device, and (on CUDA) the tracker runs without a sync. Fails on main.Benchmark
Inkling-Small-NVFP4, TP4,
--kv-cache-dtype mxfp8,--max-total-tokens 2097152,--max-mamba-cache-size 1024, 4x GB300, 128 multi-turn lanes (each lane sends its next turn when the previous one returns), 16 timed turns, L1 only, rounds interleaved with main.With CUDA events on the forward stream around each launch (no torch profiler), the mean forward-stream idle before an extend launch drops from 2.5 ms to 0.9 ms (p50 1.8 ms to 2 us), and
prepare_for_extendCPU time per extend step from 25.5 ms to 3.4 ms.CI States
Latest PR Test (Base): ❌ Run #38107044906
Latest PR Test (Extra): ❌ Run #38107044965
Latest PR Test (AMD ROCm 10): ❌ Run #38107044816