Skip to content

[Perf] scheduler: Remove implicit CUDA syncs from Mamba extend scheduling - #43637

Closed
alphabetc1 wants to merge 1 commit into
sgl-project:mainfrom
alphabetc1:mamba-extend-no-sync
Closed

alphabetc1 wants to merge 1 commit into
sgl-project:mainfrom
alphabetc1:mamba-extend-no-sync

Conversation

@alphabetc1

@alphabetc1 alphabetc1 commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

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:

call site syncs per extend step
HybridReqToTokenPool.alloc: mapping[select_index] = ... with a Python-list index (twice) 2
_mamba_radix_cache_v2_req_prepare_for_extend: ping_pong_track_buffer[idx].item() 1 per request
prepare_for_extend: torch.tensor(list, device=cuda) for the track indices / mask / seqlens 3

A 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 existing async_h2d helper and use it for both mapping writes.
  • _mamba_radix_cache_v2_req_prepare_for_extend returns the track slot as a device view instead of .item(); prepare_for_extend stacks the views into mamba_track_indices (one kernel) and stages the mask / seqlens with async_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.

  • New test_alloc_writes_mappings_without_synchronizing (CUDA): allocates several requests under set_sync_debug_mode("error") and checks both mappings row by row. Fails on main with RuntimeError: called a synchronizing CUDA operation at the list-index setitem.
  • New 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.
  • Unit suites (mem_cache, managers, disaggregation, dllm) and the Rust-core unified suite: same failures as main (pre-existing, unrelated), nothing new.

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.

tok/s (3 rounds) mean
main 13155 / 13128 / 13129 13138
this PR 13249 / 13252 / 13261 13254 (+0.89%)

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_extend CPU 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

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