Skip to content

[Speculative] Avoid blocking DFlash prefill length copies - #40091

Open
shenxiul wants to merge 1 commit into
sgl-project:mainfrom
shenxiul:shenxiu/dflash-prefill-async-lengths-20260918
Open

shenxiul wants to merge 1 commit into
sgl-project:mainfrom
shenxiul:shenxiu/dflash-prefill-async-lengths-20260918

Conversation

@shenxiul

@shenxiul shenxiul commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Why is this change needed?

After each target prefill chunk, DFlash constructs two device tensors from CPU lists: extension lengths and cached-prefix lengths. Each CUDA copy waits on the host before draft KV projection can be queued.

Stage the lengths in pinned CPU memory where supported and transfer them with non_blocking=True. The existing device-aware pinning helper handles other backends. Int32 values, position construction and cache destinations stay the same: extension lengths [3, 4] with prefixes [10, 20] still produce positions [10, 11, 12, 20, 21, 22, 23].

Test Plan

  • Upstream test/registered/unit/spec/test_dflash_overlap_hostsync.py: 6 passed, 1 CUDA-only test skipped on the CPU test host.
  • Direct prefill smoke check on this checkout: verified the example positions above, cache destinations, captured-state handoff and returned sequence lengths.
  • Upstream pre-commit run --files python/sglang/srt/speculative/dflash_worker_v2.py: passed.

GPU evidence below was measured with the identical runtime patch in a vendored SGLang deployment; this upstream checkout was validated locally on CPU. The paired runs used the public Inkling NVFP4 target and Modal DFlash draft, TP4 on GB300, six draft tokens, batch 16, ShareGPT, six repetitions, temperature 1, top-p 1, 128 output tokens, and EXTEND autotuning in both arms. Only this patch differed.

Prefill tokens/second/GPU:

Context Before After Change Accepted length before → after
2,048 9,547.9 10,340.4 +8.30% 2.774 → 2.774
8,192 10,482.1 11,193.5 +6.79% 2.353 → 2.353
32,768 10,169.9 10,759.7 +5.80% 2.262 → 2.262

All points had zero failed requests and zero retractions; acceptance was unchanged within floating-point aggregation precision. At 8K, paired traces each contained 18 target prefill chunks: blocking pageable H2D copies inside the scheduler fell 36 → 0, and gaps between target spans fell 364.21 → 128.15 ms. The asynchronous transfers remain.


CI States

Latest PR Test (Base): ❌ Run #35309676869
Latest PR Test (Extra): ❌ Run #35309676697
Latest PR Test (AMD ROCm 10): ❌ Run #35309676721

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant