Skip to main content

Why and What is EPD Disaggregation?

In modern Vision-Language Model (VLM) inference, request execution naturally decomposes into three distinct stages: Encoder, Prefill, and Decode. The Encoder stage performs vision preprocessing and ViT-based image encoding, which is highly compute-intensive but only required during request initialization. The Prefill stage processes the full multimodal input sequence to initialize the language model’s Key-Value (KV) cache, while the Decode stage is dominated by memory bandwidth and KV cache access for autoregressive token generation. Existing deployments typically colocate these stages within a unified execution engine, or at best apply Prefill–Decode (PD) disaggregation. However, such designs still tightly couple vision encoding with language prefill, leading to inefficient resource utilization, limited scalability for image-heavy workloads, and suboptimal scheduling under load. To address these challenges, we introduce Encoder–Prefill–Decode (EPD) Disaggregation in SGLang. EPD further separates vision encoding from language processing, enabling independent horizontal scaling of encoder servers, improved load balancing for multimodal requests, and seamless integration with existing PD disaggregation to form a fully decoupled three-tier inference architecture.

Usage

You can launch a language-only model using --language-only, or an encoder-only model using --encoder-only. When launching a language-only model, you must additionally specify the encoder service endpoints via --encoder-urls. We support multiple encoder transfer backends, including zmq_to_scheduler, zmq_to_tokenizer, and mooncake. The default is auto, which selects a backend based on the model and the TP size. The backend can be selected using --encoder-transfer-backend.

External encoder selection

By default the language worker chooses the encoder. An external router, such as Dynamo, can choose it instead when the language worker runs the Rust server. Start the encoder as usual. Start the language worker with SGLANG_RUST_SERVER=1, SGLANG_ENABLE_EXTERNAL_ENCODER_HANDOFF=1, --language-only and --encoder-transfer-backend zmq_to_scheduler. It needs PP=1 and one DP rank. For each request with media, the router does two things:
  1. It sends the encoder its native /encode request, one per modality, with req_id set to {rid}_local_part_{index} and num_parts set to the number of modalities. /encode returns after the embedding has been delivered, so the router keeps the call open.
  2. It sends the language worker a tokenized /generate request that carries the same rid, one placeholder token per media item, no raw media, and an encoder_handoff field naming the encoder:
parts lists the modalities in the order of their part indices. The language worker registers its receive address with that encoder and receives the embeddings over the existing ZMQ path. The router must use a unique rid per request, because the encoder keys its work by it. If --encoder-urls is set on the language worker, encoder_handoff may only name an encoder from that list. Without it, any address is accepted, so expose this listener to the router only. Requests with raw media are rejected with 400. A request whose prompt holds media placeholders but no encoder_handoff is treated as text.

Encoder transfer with Mooncake

--encoder-transfer-backend mooncake controls how encoder outputs are transferred between encoder and language/prefill services. It is an encoder transfer option and can be used independently of the global multimodal embedding cache. Example:
Command

Intel XPU

On Intel XPU, the Mooncake encoder transfer runs on Mooncake’s TENT engine, which copies the embedding card to card through Level Zero IPC, so no RDMA NIC is needed. This needs a Mooncake transfer engine built with -DUSE_XPU=ON -DUSE_TENT=ON (docker/xpu.Dockerfile installs one). Both servers must see both cards: list them in ZE_AFFINITY_MASK and pick each server’s card with --base-gpu-id. A server that sees only its own card cannot map the other card’s buffer, and the transfer falls back to TCP. Inside a container, also run with --cap-add SYS_PTRACE (or --privileged): TENT maps the peer’s buffer through pidfd_getfd(), which Docker blocks by default, and without it the copy quietly takes another route. See the Mooncake backend note for P/D on Intel XPU. Run each server in its own terminal, and set the export line in both: without it, the language server does not use TENT and cannot see the encoder’s card.
Command
TORCHINDUCTOR_USE_STATIC_CUDA_LAUNCHER=0 works around an inductor static Triton launcher issue on torch 2.14+xpu that crashes the encoder on its first image. Drop it once your torch build includes the fix (likely pytorch/pytorch#199511).
The encoder preprocesses images on CPU by default, while a colocated server runs the image processor on the device, so the two produce slightly different image embeddings. Set SGLANG_ENCODER_IMAGE_PROCESSOR_USE_GPU=1 on the encoder to preprocess on the device and get the same embeddings as colocated serving.

Global multimodal embedding cache with Mooncake

SGLang also supports a Mooncake-backed global multimodal embedding cache for EPD workloads. When enabled on encoder servers, repeated image inputs can reuse previously computed ViT embeddings across instances instead of running the vision encoder again. This feature is useful when:
  • the deployment serves repeated or overlapping image inputs,
  • encoder compute is the bottleneck, and
  • Mooncake is already available in the cluster.
At a high level, the encoder checks whether the image embedding already exists in Mooncake. Cache hits are prefetched from the global store, while misses are encoded normally and inserted into the cache in the background. To enable it:
  • install and configure Mooncake in the same way as other SGLang Mooncake integrations,
  • add --enable-mm-global-cache on the encoder server.
--enable-mm-global-cache controls whether multimodal embeddings are looked up and stored in the global Mooncake cache. It is separate from --encoder-transfer-backend, which only controls encoder output transport. For Mooncake deployment and configuration details, see HiCache best practices and the Mooncake backend README. Example:
Command
Notes:
  • This cache is for multimodal encoder embeddings, not the language model KV cache.
  • The feature currently uses Mooncake as the shared backing store.
  • It works on NVIDIA CUDA and Ascend NPU. The host staging path resolves the device module (torch.cuda or torch.npu) for its copy streams and events, so no CUDA-specific setup is required on Ascend.
  • It can be enabled regardless of which --encoder-transfer-backend you use.
  • It is most relevant for EPD or encoder-disaggregated VLM deployments where the same images are likely to appear across requests or instances.

Qwen VL

  • EP Disaggregation
Command
  • EPD Disaggregation
Command

gRPC Encoder (EPD)

You can run the encoder as a gRPC server while keeping prefill/decode as HTTP. When using gRPC encoders, set SGLANG_ENCODER_MM_RECEIVER_MODE=grpc for the prefill process so it uses the gRPC receiver.
Command