Skip to content

[DSv4 Perf] Adaptive topk width, 1.0% E2E throughput improvement - #50004

Merged
yewentao256 merged 1 commit into
mainfrom
wentao-adaptive-topk-width
Jul 27, 2026
Merged

[DSv4 Perf] Adaptive topk width, 1.0% E2E throughput improvement#50004
yewentao256 merged 1 commit into
mainfrom
wentao-adaptive-topk-width

Conversation

@yewentao256

@yewentao256 yewentao256 commented Jul 27, 2026

Copy link
Copy Markdown
Member

Purpose

Let's assume token num = 2

Originally: Always use maximum length

c128a_max_compressed
→ 1,048,576 / 128
→ 8,192

So buffer

global_decode_buffer[:2]
→ shape = [2, 8192]
→ stride = 8192

kernel loop for 8192 times

Now based on current context

32,768 / 128
→ 256
→ active_topk_width = 256

buffer.view(-1)[: 2 × 256]
→ view(2, 256)
→ shape = [2, 256]
→ stride = 256

Kernel only loops for 256 times

Test

cd /home/yewentao256/vllm-source
source /home/yewentao256/wt_env.sh
export MODEL=deepseek-ai/DeepSeek-V4-Pro

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 \
/home/yewentao256/.venv/bin/python -m vllm.entrypoints.cli.main serve "$MODEL" \
  --served-model-name dsv4-pro \
  --tensor-parallel-size 8 \
  --enable-expert-parallel \
  --max-model-len 1048576 \
  --max-num-batched-tokens 8192 \
  --max-num-seqs 512 \
  --gpu-memory-utilization 0.95 \
  --kv-cache-dtype fp8_ds_mla \
  --no-enable-prefix-caching \
  --trust-remote-code \
  --port 8000 \
  2>&1 | tee /home/yewentao256/dsv4-c128a-prefill-results/diff-server.log

Acc

lm_eval run \
  --model local-completions \
  --model_args model="$MODEL",base_url=http://127.0.0.1:8000/v1/completions,num_concurrent=100,tokenized_requests=False \
  --tasks gsm8k \
  --num_fewshot 5 \
  --output_path /home/yewentao256/dsv4-c128a-lm-eval-results/results \
  --log_samples \
  --seed 0 \
  2>&1 | tee /home/yewentao256/dsv4-c128a-lm-eval-results/lm-eval.log

|Tasks|Version|     Filter     |n-shot|  Metric   |   |Value |   |Stderr|
|-----|------:|----------------|-----:|-----------|---|-----:|---|-----:|
|gsm8k|      3|flexible-extract|     5|exact_match||0.9492|±  |0.0060|
|     |       |strict-match    |     5|exact_match||0.9484|±  |0.0061|

Perf

vllm bench serve \
  --backend openai \
  --base-url http://127.0.0.1:8000 \
  --endpoint /v1/completions \
  --model "$MODEL" \
  --served-model-name dsv4-pro \
  --dataset-name random \
  --random-input-len 8192 \
  --random-output-len 1 \
  --random-range-ratio 0 \
  --num-prompts 32 \
  --num-warmups 4 \
  --request-rate inf \
  --max-concurrency 1 \
  --ignore-eos \
# now
============ Serving Benchmark Result ============
Successful requests:                     32        
Failed requests:                         0         
Maximum request concurrency:             1         
Benchmark duration (s):                  11.84     
Total input tokens:                      262144    
Total generated tokens:                  32        
Request throughput (req/s):              2.70      
Output token throughput (tok/s):         2.70      
Peak output token throughput (tok/s):    3.00      
Peak concurrent requests:                4.00      
Total token throughput (tok/s):          22151.38  
---------------Time to First Token----------------
Mean TTFT (ms):                          369.74    
Median TTFT (ms):                        369.99    
P99 TTFT (ms):                           374.28    
----------------End-to-end Latency----------------
Mean E2EL (ms):                          369.74    
Median E2EL (ms):                        369.99    
P99 E2EL (ms):                           374.28    
==================================================

============ Serving Benchmark Result ============
Successful requests:                     32        
Failed requests:                         0         
Maximum request concurrency:             1         
Benchmark duration (s):                  11.82     
Total input tokens:                      262144    
Total generated tokens:                  32        
Request throughput (req/s):              2.71      
Output token throughput (tok/s):         2.71      
Peak output token throughput (tok/s):    3.00      
Peak concurrent requests:                4.00      
Total token throughput (tok/s):          22186.10  
---------------Time to First Token----------------
Mean TTFT (ms):                          369.17    
Median TTFT (ms):                        369.42    
P99 TTFT (ms):                           372.82    
----------------End-to-end Latency----------------
Mean E2EL (ms):                          369.17    
Median E2EL (ms):                        369.42    
P99 E2EL (ms):                           372.82    
==================================================

# main
============ Serving Benchmark Result ============
Successful requests:                     32        
Failed requests:                         0         
Maximum request concurrency:             1         
Benchmark duration (s):                  11.94     
Total input tokens:                      262144    
Total generated tokens:                  32        
Request throughput (req/s):              2.68      
Output token throughput (tok/s):         2.68      
Peak output token throughput (tok/s):    3.00      
Peak concurrent requests:                4.00      
Total token throughput (tok/s):          21959.34  
---------------Time to First Token----------------
Mean TTFT (ms):                          372.97    
Median TTFT (ms):                        373.45    
P99 TTFT (ms):                           377.40    
----------------End-to-end Latency----------------
Mean E2EL (ms):                          372.97    
Median E2EL (ms):                        373.45    
P99 E2EL (ms):                           377.40    
==================================================
============ Serving Benchmark Result ============
Successful requests:                     32        
Failed requests:                         0         
Maximum request concurrency:             1         
Benchmark duration (s):                  11.95     
Total input tokens:                      262144    
Total generated tokens:                  32        
Request throughput (req/s):              2.68      
Output token throughput (tok/s):         2.68      
Peak output token throughput (tok/s):    3.00      
Peak concurrent requests:                4.00      
Total token throughput (tok/s):          21945.26  
---------------Time to First Token----------------
Mean TTFT (ms):                          373.21    
Median TTFT (ms):                        373.45    
P99 TTFT (ms):                           377.10    
----------------End-to-end Latency----------------
Mean E2EL (ms):                          373.21    
Median E2EL (ms):                        373.45    
P99 E2EL (ms):                           377.10    
==================================================

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 27, 2026
@yewentao256
yewentao256 merged commit b2f9e4c into main Jul 27, 2026
70 checks passed
@yewentao256
yewentao256 deleted the wentao-adaptive-topk-width branch July 27, 2026 19:56
allenh1 pushed a commit to allenh1/vllm that referenced this pull request Aug 5, 2026
Conflicts in 13 files. Substantive resolutions:

- sparse_mla C128A metadata: adopt upstream's adaptive topk width (vllm-project#50004,
  next_power_of_2 + tightly packed views) and drop our 128-aligned
  _c128a_effective_topk_width and its test. Upstream already avoids the
  device sync we were guarding against, and packed views make our fill_(-1)
  pre-init unnecessary. PR jasl#27's shared decode/prefill buffer is orthogonal
  and kept, so upstream's new packed-buffer test is adapted to the single
  buffer and gains a non-aliasing assertion.

- _mtp_hidden_buffer: keep our narrow predicate, not upstream's
  use_eagle() or uses_draft_model(). Both readers of
  get_mtp_target_hidden_states() are gated on method == "mtp", and the
  DFlash speculator consumes aux hidden states instead, so upstream's
  predicate reserves ~470 MiB for drafters that never read it.

- combine_topk_swa_indices: adopt upstream's out=(indices, lens) signature,
  keep our validation and fill_(-1). Upstream's own no-out path uses
  torch.full(-1) precisely because the kernel does not write every column,
  so its out path leaks stale rows into a caller-supplied buffer.

- DSpark naming: adopt upstream's rename wholesale
  (DeepSeekV4DSparkModel -> DSparkDraftModel, DeepSeekV4DSpark ->
  DSparkDeepseekV4ForCausalLM) across registry, package __init__ and
  speculative config. The merge had silently left AMD/XPU on upstream's new
  class name and NVIDIA on ours, with __init__ importing only the latter --
  no conflict markers, still broken on ROCm/XPU. Our only retained delta is
  defaulting dspark num_speculative_tokens from dspark_block_size.

- config/vllm: take upstream's PCP-implies-V2 rule; do NOT take its
  force-routing of DSpark to V2 (V1 has correct long-context recall on our
  stack, V2 collapses under concurrency) and keep DeepSeek-V4 out of the
  breakable-cudagraph auto-enable set (measured 1.5-3.8x slower MTP decode).
  Upstream's new KimiK3/KimiLinear architectures are added to that set so
  they are not collaterally excluded.

- warmup: rebase kernel_warmup.py onto upstream's per-concern module split
  and move our 11 DSv4 passes into a new deepseek_v4_sm12x_warmup module.
  Retires our _attention_backend_name / _clamp_warmup_tokens /
  _has_deepseek_v4_sparse_mla_backend in favour of upstream's now-identical
  ones. Our sparse-MLA pass is a superset of upstream's (adds prefill and
  MTP uniform-decode shapes), so both run.

- kv_offload spec/config and flashmla: keep our compact-offload and Triton
  indexed-D512 prefill paths, adopt upstream's cache_policy_module_path,
  SharedOffloadRegion mmap path and AttentionSpec dcp guard.

837 changed .py files compile; all 11 fork mechanisms present. Not yet built
or gated.
zyongye pushed a commit that referenced this pull request Aug 21, 2026
Signed-off-by: yewentao256 <zhyanwentao@126.com>
khushali9 pushed a commit to khushali9/vllm that referenced this pull request Aug 29, 2026
…ack (vllm-project#52823)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
Signed-off-by: khushali9 <khushali.desai9@gmail.com>
am-cohere pushed a commit to am-cohere/vllm that referenced this pull request Sep 1, 2026
…ack (vllm-project#52823)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
mikeshawcode pushed a commit to mikeshawcode/vllm that referenced this pull request Sep 1, 2026
…ack (vllm-project#52823)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
Signed-off-by: mikeshawcode <michaelwshaw2@gmail.com>
mikeshawcode pushed a commit to mikeshawcode/vllm that referenced this pull request Sep 1, 2026
…ack (vllm-project#52823)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
Signed-off-by: mikeshawcode <michaelwshaw2@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants