跳转至

分离式编码器

分离式编码器是指将大语言模型(LLM)的视觉(多模态)编码器阶段,在与语言模型的预填充和解码阶段分离的独立 vLLM 进程/实例中运行。

类似地,分离式预填充将提示处理(KV 缓存计算)与自回归 Token 生成(解码阶段)隔离到不同的 vLLM 实例中。

这种分离允许针对每个阶段进行有针对性的硬件和资源优化,从而能够精确地调整首 Token 时间(TTFT)与 Token 间延迟(ITL)。因此,它提高了高负载服务期间的整体吞吐量和资源利用率。

预填充-解码(PD)分离作为此机制的总体架构。在此设置中,专用的预填充实例计算 KV 缓存,并通过专门的连接器(如 MooncakeLayerwise)将其传输到解码实例以进行 Token 生成。

在 vLLM(包括 Ascend 硬件插件)等框架中,PD 分离通常与多模态模型的编码器-预填充-解码(EPD)架构集成,同时支持具有分布式负载均衡的多节点配置。

最终,这些架构模式通过解决每个阶段不同的计算特征来最大化推理效率:编码和预填充是计算密集型和突发性的,而解码是内存密集型和持续性的。

为什么需要分离式编码器?

**分离式编码器**将多模态大语言模型的视觉编码器阶段运行在与预填充/解码阶段分离的进程中。将这两个阶段部署在独立的 vLLM 实例中会带来三个实际好处:

  1. 独立的细粒度扩展

  2. 视觉编码器是轻量级的,而语言模型要大几个数量级。

  3. 语言模型可以并行化,而不会影响编码器集群。
  4. 编码器节点可以独立地添加或移除。

  5. 更低的首 Token 时间(TTFT)

  6. 纯文本请求完全绕过视觉编码器。

  7. 编码器输出仅在需要的注意力层注入,缩短了预填充关键路径。

  8. 编码器输出的跨进程复用和缓存

  9. 进程内编码器将复用限制在单个工作进程内。

  10. 远程共享缓存允许任何工作进程检索现有的嵌入,消除冗余计算。

设计文档:https://docs.google.com/document/d/1aed8KtC6XkXtdoV87pWT0a8OJlZ-CpnuLLzmR8l9BAE/edit


使用方法

The current reference pathway is ExampleConnector. The ready-to-run scripts below show the workflow:

1 Encoder instance + 1 PD instance: examples/online_serving/disaggregated_encoder/disagg_1e1pd/

1 Encoder instance + 1 Prefill instance + 1 Decode instance: examples/online_serving/disaggregated_encoder/disagg_1e1p1d/


开发

示意图

分离式编码通过运行两个部分来实现:

  • 编码器实例 – 执行视觉编码的 vLLM 实例。
  • 预填充/解码(PD)实例 – 运行语言的预填充和解码。
    • PD 可以是单一的普通实例(E + PD),也可以是分离式实例(E + P + D)

A connector transfers encoder-cache (EC) embeddings from the encoder instance to the PD instance.
All related code is under vllm/distributed/ec_transfer.

关键抽象

  • ECConnector – 用于检索编码器生成的 EC 缓存的接口。

    • 调度器角色 – 检查缓存是否存在并调度加载。
    • 工作器角色 – 将嵌入加载到内存中。
  • EPD 负载均衡代理 -

    • 多路径调度策略 - 动态地将多模态请求或文本请求分流到相应的推理路径
    • 实例级动态负载均衡 - 基于最少负载策略分发多模态请求,使用优先级队列来平衡各实例间的活跃 Token 工作负载。

We create the example setup with the MooncakeLayerwiseConnector from vllm_ascend/distributed/kv_transfer/kv_p2p/mooncake_layerwise_connector.py and refer to the examples/disaggregated_prefill_v1/load_balance_proxy_layerwise_server_example.py to facilitate the kv transfer between P and D. For step-by-step deployment and configuration of Mooncake, refer to the following guide:
https://docs.vllm.ai/projects/ascend/en/latest/tutorials/features/pd_disaggregation_mooncake_multi_node.html

For the PD disaggregation part, when using MooncakeLayerwiseConnector: The request first enters the Decoder instance, the Decoder triggers a remote prefill task in reverse via the Metaserver. The Prefill node then executes inference and pushes KV Cache layer-wise to the Decoder, overlapping computation with transmission. Once the transfer is complete, the Decoder seamlessly continues with the subsequent token generation. docs/source/developer_guide/Design_Documents/disaggregated_prefill.md shows the brief idea about the disaggregated prefill.

限制

  • 如果要使用跨进程缓存,请禁用 --mm-processor-cache-gb 0

  • 关于 PD 分离部分,请参考 PD 分解的限制说明