Disaggregated Encoder¶
A disaggregated encoder runs the vision-encoder stage of a multimodal LLM in a process that is separate from the pre-fill / decoder stage. Deploying these two stages in independent vLLM instances brings three practical benefits:
- Independent, fine-grained scaling
- Lower time-to-first-token (TTFT)
- Cross-process reuse and caching of encoder outputs
Design doc: https://docs.google.com/document/d/1aed8KtC6XkXtdoV87pWT0a8OJlZ-CpnuLLzmR8l9BAE
1 Motivation¶
1. Independent, fine-grained scaling¶
- Vision encoders are lightweight, while language models are orders of magnitude larger.
- The language model can be parallelised without affecting the encoder fleet.
- Encoder nodes can be added or removed independently.
2. Lower time-to-first-token (TTFT)¶
- Language-only requests bypass the vision encoder entirely.
- Encoder output is injected only at required attention layers, shortening the pre-fill critical path.
3. Cross-process reuse and caching¶
- In-process encoders confine reuse to a single worker.
- A remote, shared cache lets any worker retrieve existing embeddings, eliminating redundant computation.
2 Usage Example¶
ExampleConnector¶
The following scripts demonstrate the workflow with ExampleConnector:
1 Encoder instance + 1 PD instance:
examples/disaggregated/disaggregated_encoder/disagg_1e1pd_example.sh
1 Encoder instance + 1 Prefill instance + 1 Decode instance:
examples/disaggregated/disaggregated_encoder/disagg_1e1p1d_example.sh
ECMooncakeConnector¶
ECMooncakeConnector transfers encoder outputs using the Mooncake TransferEngine.
See the ECMooncakeConnector Usage Guide for
producer/consumer --ec-transfer-config, proxy --ec-consumer-zmq-addrs, and
transport options. The Mooncake integration example
is a complete 1 Encoder instance + 1 PD instance setup.
With vLLM and Mooncake installed, run the example from the repository root:
GPU_E=0 GPU_PD=1 MOONCAKE_EC_PROTOCOL=tcp \
bash tests/v1/ec_connector/integration/run_epd_mooncake_ec_full_pipeline.sh
The script uses Qwen/Qwen2.5-VL-3B-Instruct by default, runs a single-GPU baseline,
and compares the disaggregated outputs against it. Set MODEL to use another model
or MOONCAKE_EC_PROTOCOL=rdma to use RDMA on supported hardware. See the script for
additional configuration options.
Audio inputs¶
The Python EPD proxy also rewrites audio in /v1/chat/completions into
metadata-only references for Qwen2-Audio, AudioFlamingo3, Ultravox,
Qwen2.5-Omni, and Qwen3-Omni. The encoder publishes audio_num_tokens
(the placeholder token count of each audio) together with any feature
lengths the model needs; the consumer uses them to reconstruct the audio
placeholders and receives the embeddings through its EC connector without
repeating audio preprocessing.
Qwen2.5-Omni and Qwen3-Omni also support videos with an embedded audio track
using mm_processor_kwargs={"use_audio_in_video": true} in the request. Start
both instances with --trust-request-mm-kwargs only for trusted clients.
The proxy keeps one
video_embeds content part per video, with an additional audio_embeds payload
for its audio track. Both features share the source UUID but retain their own
EC hashes and transfer handles. Audio lengths and video timing reconstruct the
interleaved placeholders and M-RoPE positions without decoding the media again.
If any item lacks metadata, the entire audio/video request falls back to raw
media rather than mixing raw and metadata-only inputs.
This does not add /v1/audio/transcriptions or realtime routes to the example
proxy.
3 Test Script¶
For optional cross-Encoder output reuse while retaining Mooncake P2P delivery, see Cross-encoder output reuse.
Please refer to the directories tests/v1/ec_connector
4 Encoder cache events¶
Encoder cache (EC) events mirror KV cache events so a
router or cache-aware orchestrator can tell which instances already hold the
encoder output for a given multimodal input. Events are keyed by the multimodal
hash (mm_hash) and use the same ZMQ publisher and replay buffer as KV events.
Enable them on the scheduler with --ec-events-config:
vllm serve <model> \
--ec-events-config '{"enable_ec_cache_events": true, "publisher": "zmq", "topic": "ec-events"}'
The default endpoint is tcp://*:6558. Like KV events, the port is shifted up
by the data-parallel rank; the block starts 1000 ports above the 5557/5558 KV
events block, so both streams can be enabled at once on hosts with up to 1000
DP ranks without an explicit endpoint.
The event types are ECStored(mm_hashes, medium), ECRemoved(mm_hashes,
medium) and AllECCleared(), delivered in an ECEventBatch. The GPUs of the
scheduler's own encoder cache report medium="GPU"; a connector that offloads
encoder outputs adds its own events through ECConnectorBase.take_events().
Local GPU cache events are published even when no EC connector is configured.
Events are off by default and use the null publisher when disabled. Subscribe
the same way as for KV events, decoding ECEventBatch from
vllm.distributed.ec_transfer.ec_events; see
kv_events_subscriber.py
for the ZMQ client loop.
5 Development¶
Disaggregated encoding is implemented by running two parts:
- Encoder instance – a vLLM instance to performs vision encoding.
- Prefill/Decode (PD) instance(s) – runs language pre-fill and decode.
- PD can be in either a single normal instance with
disagg_encoder_example.sh(E->PD) or in disaggregated instances withdisagg_epd_example.sh(E->P->D)
- PD can be in either a single normal instance with
A connector transfers encoder-cache (EC) embeddings from the encoder instance to the PD instance.
All related code is under vllm/distributed/ec_transfer.
Key abstractions¶
- ECConnector – interface for retrieving EC caches produced by the encoder.
- Scheduler role – checks cache existence and schedules loads.
- Worker role – loads the embeddings into memory.
Here is a figure illustrating disaggregate encoder flow:
For the PD disaggregation part, the Prefill instance receives cache exactly the same as the disaggregated encoder flow above. Prefill instance executes 1 step (prefill -> 1 token output) and then transfers KV cache to the Decode instance for the remaining execution. The KV transfer part purely happens after the execution of the PD instance.
docs/features/disagg_prefill.md shows the brief idea about the disaggregated prefill (v0)
We create the example setup with the NixlConnector from vllm/distributed/kv_transfer/kv_connector/v1/nixl/ and referred to the tests/v1/kv_connector/nixl_integration/toy_proxy_server.py to facilitate the kv transfer between P and D;
