<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Vllm源码 on moyutianzun 的博客</title><link>https://moyutianzun.com/tags/vllm%E6%BA%90%E7%A0%81/</link><description>Recent content in Vllm源码 on moyutianzun 的博客</description><generator>Hugo</generator><language>zh-cn</language><copyright>moyutianzun</copyright><lastBuildDate>Mon, 29 Sep 2025 09:53:22 +0800</lastBuildDate><atom:link href="https://moyutianzun.com/tags/vllm%E6%BA%90%E7%A0%81/index.xml" rel="self" type="application/rss+xml"/><item><title>PD分离 —— Prefix Cache和Chunk Prefills</title><link>https://moyutianzun.com/blog/pdfen-chi------prefix-cachehe-chunk-prefills/</link><pubDate>Mon, 29 Sep 2025 09:53:22 +0800</pubDate><guid>https://moyutianzun.com/blog/pdfen-chi------prefix-cachehe-chunk-prefills/</guid><description>&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;目前推理框架基本上都需要用到多轮对话的场景，自然产生了&lt;code&gt;kv cache&lt;/code&gt;的存储和索引算法。如果能把&lt;code&gt;prompt&lt;/code&gt;和后续产生的&lt;code&gt;KV Cache&lt;/code&gt;保存下来，会极大地降低首&lt;code&gt;Token&lt;/code&gt;的耗时。&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;目前使用最多的就是两个技术方案，一个是&lt;code&gt;SGLang&lt;/code&gt;推出的&lt;code&gt;RadixAttention&lt;/code&gt;&lt;span style="font-size: mediumpx; color: rgb(25, 27, 31)"&gt;的&lt;/span&gt;&lt;code&gt;Prefix Cache&lt;/code&gt;&lt;span fontsize="" color="rgb(25, 27, 31)" style="color: rgb(25, 27, 31)"&gt;，另一个是&lt;/span&gt;&lt;code&gt;vllm&lt;/code&gt;&lt;span fontsize="" color="rgb(25, 27, 31)" style="color: rgb(25, 27, 31)"&gt;原生的&lt;/span&gt;&lt;code&gt;Chunk Prefills&lt;/code&gt;&lt;span fontsize="" color="rgb(25, 27, 31)" style="color: rgb(25, 27, 31)"&gt;。当然&lt;/span&gt;&lt;code&gt;vllm&lt;/code&gt;&lt;span fontsize="" color="rgb(25, 27, 31)" style="color: rgb(25, 27, 31)"&gt;也兼容了&lt;/span&gt;&lt;code&gt;Prefix Cache&lt;/code&gt;&lt;span fontsize="" color="rgb(25, 27, 31)" style="color: rgb(25, 27, 31)"&gt;，这两个技术只能用一个，vllm默认是Chunk Prefills，可以通过加入参数&lt;/span&gt;&lt;code&gt;--enable-prefix-caching&lt;/code&gt;&lt;span fontsize="" color="rgb(25, 27, 31)" style="color: rgb(25, 27, 31)"&gt;来开启，这里不谈&lt;/span&gt;&lt;code&gt;TensorRT-LLM&lt;/code&gt;&lt;span fontsize="" color="rgb(25, 27, 31)" style="color: rgb(25, 27, 31)"&gt;是因为其不完全开源。&lt;/span&gt;&lt;/p&gt;</description></item><item><title>vllm v1 源码解析 —— 单机八卡推理</title><link>https://moyutianzun.com/blog/vllm-v1-yuan-ma-jie-xi------dan-ji-ba-qia/</link><pubDate>Fri, 26 Sep 2025 09:10:35 +0800</pubDate><guid>https://moyutianzun.com/blog/vllm-v1-yuan-ma-jie-xi------dan-ji-ba-qia/</guid><description>&lt;p style=""&gt;单机八卡，我们按照PP + TP的方式来进行方案说明，使用的是vllm框架，主要命令和函数如下：&lt;/p&gt;&lt;pre&gt;&lt;code&gt;python single_node_multi_gpu_demo.py --mode pipeline_parallel --tensor-parallel 4 --pipeline-parallel 2 --model facebook/opt-13b
&lt;p&gt;def pipeline_parallel_inference(self, model_name: str, tensor_parallel_size: int, pipeline_parallel_size: int):
&amp;ldquo;&amp;ldquo;&amp;ldquo;流水线并行推理 - 将模型层分布到多个GPU上&amp;rdquo;&amp;rdquo;&amp;rdquo;
print(f&amp;quot;🚀 启动流水线并行推理 - 模型: {model_name}&amp;quot;)
print(f&amp;quot; 张量并行: {tensor_parallel_size}, 流水线并行: {pipeline_parallel_size}&amp;quot;)&lt;/p&gt;</description></item><item><title>vllm v1 源码解析 —— Core</title><link>https://moyutianzun.com/blog/vllm-v1-yuan-ma-jie-xi------core/</link><pubDate>Tue, 23 Sep 2025 03:56:10 +0800</pubDate><guid>https://moyutianzun.com/blog/vllm-v1-yuan-ma-jie-xi------core/</guid><description>&lt;p style=""&gt;一个client建立之后就会建立一个core engine，这些配置会通过QMZ IPC发送给core engine。&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;h1 style="" id="core-engine-architecture"&gt;Core engine Architecture&lt;/h1&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;h2 style="" id="worker-and-executor"&gt;Worker and Executor&lt;/h2&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;h2 style="" id="multiprocexecutor"&gt;MultiprocExecutor&lt;/h2&gt;&lt;p style=""&gt;在MultiprocExecutor类中，可以清晰的找到三部曲：&lt;/p&gt;&lt;p style=""&gt;&lt;/p&gt;&lt;p style=""&gt;1、创建RPC消息队列&lt;/p&gt;&lt;pre&gt;&lt;code class="language-python"&gt;# Initialize worker and set up message queues for SchedulerOutputs
# and ModelRunnerOutputs
max_chunk_bytes = envs.VLLM_MQ_MAX_CHUNK_BYTES_MB * 1024 * 1024
self.rpc_broadcast_mq = MessageQueue(self.world_size,
self.world_size,
max_chunk_bytes=max_chunk_bytes)
scheduler_output_handle = self.rpc_broadcast_mq.export_handle()&lt;/code&gt;&lt;/pre&gt;&lt;p style=""&gt;&lt;/p&gt;</description></item></channel></rss>