Skip to content

[DSv4 Perf] Optimize workspace reuse for eager break - #49236

Merged
vllm-bot merged 7 commits into
mainfrom
wentao-optimize-workspace-reuse
Jul 31, 2026
Merged

[DSv4 Perf] Optimize workspace reuse for eager break#49236
vllm-bot merged 7 commits into
mainfrom
wentao-optimize-workspace-reuse

Conversation

@yewentao256

Copy link
Copy Markdown
Member

Purpose

Part of #45861

Optimize workspace reuse for eager break

Test

vllm serve deepseek-ai/DeepSeek-V4-Flash --tensor-parallel-size 4 --enable-expert-parallel --attention-backend FLASHMLA_SPARSE_DSV4 --attention-config '{"use_fp4_indexer_cache":true}' --kv-cache-dtype fp8 --tokenizer-mode deepseek_v4 --all2all-backend allgather_reducescatter --port 8003

Acc

lm_eval --model  local-completions --model_args "base_url=http://127.0.0.1:8003/v1/completions,model=deepseek-ai/DeepSeek-V4-Flash,num_concurrent=1024" --tasks gsm8k
|Tasks|Version|     Filter     |n-shot|  Metric   |   |Value |   |Stderr|
|-----|------:|----------------|-----:|-----------|---|-----:|---|-----:|
|gsm8k|      3|flexible-extract|     5|exact_match||0.9507|±  |0.0060|
|     |       |strict-match    |     5|exact_match||0.9515|±  |0.0059|

Perf

vllm bench serve   --model deepseek-ai/DeepSeek-V4-Flash   --dataset-name random   --host 127.0.0.1   --port 8003   --random-input-len 2   --random-output-len 2048   --request-rate inf   --max-concurrency 1   --num-prompts 4   --num-warmups 2   --ignore-eos   --temperature 0   --seed 0

# now

============ Serving Benchmark Result ============
Successful requests:                     4         
Failed requests:                         0         
Maximum request concurrency:             1         
Benchmark duration (s):                  46.96     
Total input tokens:                      8         
Total generated tokens:                  8192      
Request throughput (req/s):              0.09      
Output token throughput (tok/s):         174.45    
Peak output token throughput (tok/s):    176.00    
Peak concurrent requests:                2.00      
Total token throughput (tok/s):          174.62    
---------------Time to First Token----------------
Mean TTFT (ms):                          44.65     
Median TTFT (ms):                        44.44     
P99 TTFT (ms):                           46.31     
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          5.71      
Median TPOT (ms):                        5.71      
P99 TPOT (ms):                           5.72      
---------------Inter-token Latency----------------
Mean ITL (ms):                           5.71      
Median ITL (ms):                         5.69      
P99 ITL (ms):                            5.90      
==================================================

# main
============ Serving Benchmark Result ============
Successful requests:                     4         
Failed requests:                         0         
Maximum request concurrency:             1         
Benchmark duration (s):                  47.20     
Total input tokens:                      8         
Total generated tokens:                  8192      
Request throughput (req/s):              0.08      
Output token throughput (tok/s):         173.58    
Peak output token throughput (tok/s):    176.00    
Peak concurrent requests:                2.00      
Total token throughput (tok/s):          173.74    
---------------Time to First Token----------------
Mean TTFT (ms):                          46.41     
Median TTFT (ms):                        46.79     
P99 TTFT (ms):                           47.81     
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          5.74      
Median TPOT (ms):                        5.74      
P99 TPOT (ms):                           5.74      
---------------Inter-token Latency----------------
Mean ITL (ms):                           5.74      
Median ITL (ms):                         5.71      
P99 ITL (ms):                            5.95      
==================================================

Signed-off-by: yewentao256 <zhyanwentao@126.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@yewentao256 yewentao256 added the ready ONLY add when PR is ready to merge/full CI is needed label Jul 20, 2026
@mergify mergify Bot added deepseek Related to DeepSeek models nvidia labels Jul 20, 2026
Comment thread tests/kernels/test_fused_indexer_q_rope_quant.py Outdated
Comment on lines +336 to +339
if output_buffers is None:
index_weights_out = torch.empty_like(index_weights, dtype=torch.float32)
else:
assert use_fp4

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Here we have a "output_buffers implies use_fp4", which could make for a "bumpy" user interface for this function - the function would have a nicer interface without this restriction. Either document this in the docstring or extend support

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, we extend the support

Comment thread vllm/models/deepseek_v4/nvidia/model.py Outdated
@github-project-automation github-project-automation Bot moved this to Ready in NVIDIA Jul 23, 2026
@vllm-bot
vllm-bot merged commit df71917 into main Jul 31, 2026
250 of 252 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to Done in NVIDIA Jul 31, 2026
@vllm-bot
vllm-bot deleted the wentao-optimize-workspace-reuse branch July 31, 2026 15:46

@yewentao256 yewentao256 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In previous commit of this PR, the test passes https://buildkite.com/vllm/ci/builds/80503#019fa437-a168-432a-b60e-05bc623b2090

So the failed unit test is not related

jasl added a commit to jasl/vllm that referenced this pull request Aug 1, 2026
Two upstream commits drive every one of the 20 conflict hunks:

  38a466e  [DSV4] Sequence Parallelism (vllm-project#46789)
  df71917  [DSv4 Perf] Optimize workspace reuse for eager break (vllm-project#49236)

Sequence parallelism (dspark.py, model.py)
------------------------------------------
_use_sequence_parallel requires expert-parallel AND (deep_gemm_mega_moe or
DP>1), so it is inert on the SM12x config (Marlin MXFP4 MoE, DP=1) even at
4-node TP=4 + EP. It is still wired correctly, because this branch serves
multi-node users whose configs can reach it, and a half-applied SP is worse
than none.

nvidia/dspark.py resolves to ours byte-for-byte. PR #27 replaced the two-kernel
mhc_post + hc_head sequence with the fused mhc_post_hc_head_tilelang, which
never materializes the [T, hc_mult, H] intermediate -- and that intermediate is
exactly what upstream's sp_all_gather needs between the two kernels. Upstream's
DeepseekV4DecoderLayer/ModuleList shape is also incompatible with our
DSparkLayer, and sp_shard on dim 0 would split DSpark blocks across ranks,
breaking the batch_size = num_input_rows // block_size geometry.

nvidia/model.py combines both sides, plus three SP correctness edits the merge
did not produce on its own: the auto-merged sp_all_gather of hidden_states sits
ahead of tail consumers that still take a sharded residual, so the deferred
mhc_post path is now disabled under SP and materialization is forced before the
gather. Upstream's `if layer is not None:` is not adopted; it is an unbound
local when a PP rank owns no layers.

Workspace reuse (csrc, attention.py, cache_utils.py)
----------------------------------------------------
Upstream split the fused qnorm-rope-kv-insert op into an allocating `..._insert`
and a caller-buffered `..._insert_out` with an explicit q_head_padded argument.
We adopt that shape wholesale and retire our local 53b6d11 variant: it solved
the same problem, upstream's split is a strict superset, and the merged tree was
already half-way there (ops.impl registered both, attention.py auto-merged to
call `_out`). Keeping ours would mean reverting an upstream change on a file
upstream actively develops -- the same reason we retired vllm-project#48304/vllm-project#48911/vllm-project#48959.

ops.h had auto-merged into a broken hybrid, carrying our void/q_out declaration
of the base name alongside upstream's `_out`; taking upstream's .cu without
fixing it is an ODR mismatch at link time. torch_bindings.cpp's base schema had
likewise auto-merged to our `Tensor! q_out` text.

attention.py keeps PR #27's value: q is written in place whenever
padded_heads == n_local_heads (true on SM12x TP=2), falling back to upstream's
eager-scratch pool and then to our class scratch. All three satisfy the op's
q_out.size(1) == q_head_padded contract.

Side effect: amd/dspark.py:243 already called the 9-argument allocating form,
which was broken against our out-form schema. Adopting upstream's shape fixes
that pre-existing ROCm break.

cache_utils.py takes upstream's `output_buffers` tuple and keeps our four
dtype/device asserts on top of its shape-only pair. The d64074e block-table
gather bound is untouched.

Also updated because the op split is a cross-file contract:
  - fix_functionalization.py registered only the old name, so our hot path
    (now `_out`) would have silently lost its copy elision. Both forms are
    registered with the correct mutated-args maps.
  - flashinfer_sm120_decode.py and the two kernel-test helpers move to the new
    signatures.
pranavthakur0-0 pushed a commit to pranavthakur0-0/vllm that referenced this pull request Aug 4, 2026
…mprovement. (vllm-project#49236)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
aditi-amd pushed a commit to aditi-amd/vllm that referenced this pull request Aug 4, 2026
…mprovement. (vllm-project#49236)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Signed-off-by: root <root@smci355-ccs-aus-m02-09.cs-aus.dcgpu>
@yewentao256 yewentao256 changed the title [DSv4 Perf] Optimize workspace reuse for eager break, 3.9% E2E TTFT improvement. [DSv4 Perf] Optimize workspace reuse for eager break Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek Related to DeepSeek models nvidia ready ONLY add when PR is ready to merge/full CI is needed

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants