Skip to content

Apply optimizations in DeepSeek forward_absorb to forward_normal - #6144

Closed
Fridge003 wants to merge 4 commits into
sgl-project:mainfrom
Fridge003:deepseek
Closed

Fridge003 wants to merge 4 commits into
sgl-project:mainfrom
Fridge003:deepseek

Conversation

@Fridge003

@Fridge003 Fridge003 commented May 9, 2025 •

Copy link
Copy Markdown
Collaborator

Motivation

In the past few weeks, there have been a lot of optimization PRs targeting at DeepSeek decoding with absorption, but they are still not applied to forward_normal/forward_normal_chunked_kv with MHA.

This PR applies these methods to forward_normal, so the performance of prefilling should increase a little bit. What's more, the PR adds a new kernel fusion method that fuses the concat of q_nope/q_pe and k_nope/k_pe before mha.

No more than 1% increase in prefill throughput, so not urgent for merging.

Modifications

Accuracy Test

Launch

python3 -m sglang.launch_server --model /dev/shm/DeepSeek-V3 --tp 8 --trust-remote-code --disable-radix

GSM8K

python3 benchmark/gsm8k/bench_sglang.py --num-shots 8 --num-questions 1319 --parallel 1319
Accuracy: 0.944
Invalid: 0.000
Latency: 114.813 s
Output throughput: 1251.989 token/s

MMLU

bash benchmark/mmlu/download_data.sh
python3 benchmark/mmlu/bench_sglang.py --nsub 100 --ntrain 5 --parallel 2000
Total latency: 377.314
Average accuracy: 0.876

Benchmark

python3 -m sglang.bench_one_batch --model-path /dev/shm/DeepSeek-V3 --tp 8 --batch 1 --input-len 8192  --output-len 10 --disable-radix

# Main Branch
Prefill. latency: 0.38455 s, throughput:  21303.07 token/s
Decode 0. Batch size: 1, latency: 0.01322 s, throughput:     75.64 token/s
Decode 1. Batch size: 1, latency: 0.01263 s, throughput:     79.18 token/s
Decode 2. Batch size: 1, latency: 0.01263 s, throughput:     79.18 token/s
Decode 3. Batch size: 1, latency: 0.01259 s, throughput:     79.43 token/s
Decode 4. Batch size: 1, latency: 0.01261 s, throughput:     79.32 token/s
Decode.  median latency: 0.01263 s, median throughput:     79.21 token/s
Total. latency:  0.499 s, throughput:  16446.57 token/s

# PR
Prefill. latency: 0.38151 s, throughput:  21472.68 token/s
Decode 0. Batch size: 1, latency: 0.01345 s, throughput:     74.35 token/s
Decode 1. Batch size: 1, latency: 0.01267 s, throughput:     78.95 token/s
Decode 2. Batch size: 1, latency: 0.01267 s, throughput:     78.90 token/s
Decode 3. Batch size: 1, latency: 0.01270 s, throughput:     78.71 token/s
Decode 4. Batch size: 1, latency: 0.01266 s, throughput:     78.97 token/s
Decode.  median latency: 0.01267 s, median throughput:     78.95 token/s
Total. latency:  0.496 s, throughput:  16526.78 token/s
python3 -m sglang.bench_one_batch --model-path /dev/shm/DeepSeek-V3 --tp 8 --batch 16 --input-len 1024   --output-len 10 --disable-radix

# Main Branch
Prefill. latency: 0.60104 s, throughput:  27259.42 token/s
Decode 0. Batch size: 16, latency: 0.01834 s, throughput:    872.63 token/s
Decode 1. Batch size: 16, latency: 0.01765 s, throughput:    906.67 token/s
Decode 2. Batch size: 16, latency: 0.01769 s, throughput:    904.27 token/s
Decode 3. Batch size: 16, latency: 0.01761 s, throughput:    908.52 token/s
Decode 4. Batch size: 16, latency: 0.01750 s, throughput:    914.05 token/s
Decode.  median latency: 0.01765 s, median throughput:    906.31 token/s
Total. latency:  0.761 s, throughput:  21740.68 token/s

# PR
Prefill. latency: 0.59599 s, throughput:  27490.20 token/s
Decode 0. Batch size: 16, latency: 0.01805 s, throughput:    886.44 token/s
Decode 1. Batch size: 16, latency: 0.01764 s, throughput:    907.18 token/s
Decode 2. Batch size: 16, latency: 0.01812 s, throughput:    882.83 token/s
Decode 3. Batch size: 16, latency: 0.01813 s, throughput:    882.45 token/s
Decode 4. Batch size: 16, latency: 0.01806 s, throughput:    885.70 token/s
Decode.  median latency: 0.01780 s, median throughput:    899.05 token/s
Total. latency:  0.757 s, throughput:  21860.25 token/s

Profile Result

python3 -m sglang.bench_one_batch --model-path /dev/shm/DeepSeek-V3 --tp 8 --cuda-graph-max-bs 32 --disable-radix --batch 16 --input-len 1024  --output-len 2 --profile

Main branch:
截屏2025-05-10 14 21 17

This PR:
截屏2025-05-10 14 22 12

Checklist

@Fridge003 Fridge003 changed the title [WIP] Apply forward_absorb optimizations to forward_normal [WIP] Apply optimizations in DeepSeek forward_absorb to forward_normal May 9, 2025
@Fridge003
Fridge003 marked this pull request as ready for review May 10, 2025 21:39
@Fridge003 Fridge003 changed the title [WIP] Apply optimizations in DeepSeek forward_absorb to forward_normal Apply optimizations in DeepSeek forward_absorb to forward_normal May 10, 2025
@Fridge003
Fridge003 marked this pull request as draft May 11, 2025 00:07
@Fridge003
Fridge003 marked this pull request as ready for review May 11, 2025 23:15
@zhyncs

zhyncs commented May 11, 2025

Copy link
Copy Markdown
Contributor

QQ why decoding is slower

@Fridge003

Copy link
Copy Markdown
Collaborator Author

QQ why decoding is slower

I didn't change any code for decoding. The difference is really small, so it might be related to logic in bench_one_batch.py.
I will change for bench_serving.py and do more benchmarks later.

@Fridge003 Fridge003 closed this May 12, 2025
@Fridge003
Fridge003 deleted the deepseek branch June 2, 2025 03:04
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.

2 participants