Skip to content

Commit 1415003

Browse files
authored
Merge pull request #455 from windsonsea/figures
update figure names in inside-vllm.md
2 parents db00181 + e5c64c8 commit 1415003

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

docs/zh/docs/blogs/2025/inside-vllm.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ V1 调度器可以在同一步中混合处理两类请求,这得益于更智
273273

274274
![分块预填充- pt 1](https://www.aleksagordic.com/blog/vllm/chunked_pt1.png)
275275

276+
<div style="text-align: center;">
277+
图 5. 分块预填充示例
278+
</div>
279+
276280
实现方法很简单:限制每步的新 Token 数量。如果请求的数量超过 `long_prefill_token_threshold`,则重置为该阈值。底层索引逻辑(前文描述)会处理剩余部分。
277281

278282
在 vLLM V1 中,可以通过将 `long_prefill_token_threshold` 设置为正整数来启用分块预填充。(技术上,即使未设置该值,如果 Prompt 长度超过 Token 预算,也会截断并执行分块预填充。)
@@ -336,6 +340,10 @@ if __name__ == "__main__":
336340

337341
![前缀缓存逻辑 - pt 1](https://www.aleksagordic.com/blog/vllm/prefix_pt1.png)
338342

343+
<div style="text-align: center;">
344+
图 6. 前缀缓存逻辑 1
345+
</div>
346+
339347
然后我们调用 `allocate_slots`,它进一步调用 `coordinator.cache_blocks`,将新的 `BlockHash` 条目与分配的 KV block 关联,并记录到 `cached_block_hash_to_block` 中。
340348

341349
随后,前向计算会在分页 KV-cache 内存中填充与上述 KV-cache block 对应的 KV。
@@ -346,10 +354,18 @@ if __name__ == "__main__":
346354

347355
![前缀缓存逻辑 - pt 2](https://www.aleksagordic.com/blog/vllm/prefix_pt2.png)
348356

357+
<div style="text-align: center;">
358+
图 7. 前缀缓存逻辑 2
359+
</div>
360+
349361
在第二次带相同前缀的 `generate` 调用中,步骤 1-3 重复执行,但这次 `find_longest_cache_hit` 通过线性搜索找到所有 `n` 个 block 的匹配。引擎可以直接重用这些 KV block。
350362

351363
![前缀缓存逻辑 - pt 3](https://www.aleksagordic.com/blog/vllm/prefix_pt3.png)
352364

365+
<div style="text-align: center;">
366+
图 8. 前缀缓存逻辑 3
367+
</div>
368+
353369
如果原始请求仍然存在,这些 block 的引用计数会增加(例如为 2)。在本例中,第一个请求已经完成,因此这些 block 已释放回池,其引用计数恢复为 0。由于我们可以从 `cached_block_hash_to_block` 中检索它们,说明它们有效(KV-cache 管理器的逻辑确保了这一点),因此我们再次将它们从 `free_block_queue` 中移除。
354370

355371
!!! note "高级说明:"
@@ -398,7 +414,7 @@ if __name__ == "__main__":
398414
![FSM](https://www.aleksagordic.com/blog/vllm/fsm.png)
399415

400416
<div style="text-align: center;">
401-
5. 玩具示例 FSM
417+
9. 玩具示例 FSM
402418
</div>
403419

404420
在 vLLM 中的实现方式:
@@ -424,7 +440,7 @@ if __name__ == "__main__":
424440
![FSM](https://www.aleksagordic.com/blog/vllm/fsm2.png)
425441

426442
<div style="text-align: center;">
427-
6. 玩具示例
443+
10. 玩具示例
428444
</div>
429445

430446
你可以通过传入所需的 `guided_decoding` 配置在 vLLM 中启用此特性。
@@ -519,8 +535,16 @@ if __name__ == "__main__":
519535

520536
![Drafting stage](https://www.aleksagordic.com/blog/vllm/specdec_pt1.png)
521537

538+
<div style="text-align: center;">
539+
图 11. 草稿阶段
540+
</div>
541+
522542
![Verify stage & rejection sampling stage](https://www.aleksagordic.com/blog/vllm/specdec_pt2.png)
523543

544+
<div style="text-align: center;">
545+
图 12. 验证阶段和拒绝采样阶段
546+
</div>
547+
524548
### P/D 分离
525549

526550
上文提到了 P/D 分离的动机。
@@ -639,7 +663,7 @@ if __name__ == "__main__":
639663
![P/D 分离](https://www.aleksagordic.com/blog/vllm/pd.png)
640664

641665
<div style="text-align: center;">
642-
7. P/D 分离
666+
13. P/D 分离
643667
</div>
644668

645669
!!! note "附加说明:"
@@ -666,7 +690,7 @@ if __name__ == "__main__":
666690
![MultiProcExecutor](https://www.aleksagordic.com/blog/vllm/multiprocexecutor.png)
667691

668692
<div style="text-align: center;">
669-
8. TP=8 设置下的 MultiProcExecutor(驱动 Worker 为 rank 0)
693+
14. TP=8 设置下的 MultiProcExecutor(驱动 Worker 为 rank 0)
670694
</div>
671695

672696
在 vLLM 中的实现方式:
@@ -702,7 +726,7 @@ if __name__ == "__main__":
702726
![2 台 8xH100 节点的服务器配置](https://www.aleksagordic.com/blog/vllm/server_setup.png)
703727

704728
<div style="text-align: center;">
705-
9. 2 台 8xH100 节点的服务器配置(1 台 headless,1 台 API 服务器)
729+
15. 2 台 8xH100 节点的服务器配置(1 台 headless,1 台 API 服务器)
706730
</div>
707731

708732
在第一台节点上,以 headless 模式运行引擎(无 API 服务器),并使用以下参数:
@@ -760,7 +784,7 @@ vLLM 中的实现方式:
760784
![分布式系统中运行 4 个 DPEngineCoreProc 的 4 个 DP 副本](https://www.aleksagordic.com/blog/vllm/dpenginecoreproc.png)
761785

762786
<div style="text-align: center;">
763-
10. 分布式系统中运行 4 个 DP 副本的 4 个 DPEngineCoreProc
787+
16. 分布式系统中运行 4 个 DP 副本的 4 个 DPEngineCoreProc
764788
</div>
765789

766790
**当前稳定状态:**
@@ -886,7 +910,7 @@ curl -X POST http://localhost:8000/v1/completions -H "Content-Type: application/
886910
![ttft, itl, e2e latency](https://www.aleksagordic.com/blog/vllm/latency_diagram.png)
887911

888912
<div style="text-align: center;">
889-
11. TTFT、ITL 与端到端延迟
913+
17. TTFT、ITL 与端到端延迟
890914
</div>
891915

892916
下面是一个简化模型,用于说明这两个指标的竞争关系。
@@ -910,7 +934,7 @@ curl -X POST http://localhost:8000/v1/completions -H "Content-Type: application/
910934
![roofline perf model](https://www.aleksagordic.com/blog/vllm/roofline.png)
911935

912936
<div style="text-align: center;">
913-
12. 屋顶线性能模型
937+
18. 屋顶线性能模型
914938
</div>
915939

916940
!!! note

0 commit comments

Comments
 (0)