Skip to content

[Feat] Send multimodal requests through EPD encode pods in PD routing - #3069

Merged
varungup90 merged 6 commits into
vllm-project:mainfrom
theminjunchoi:feat/epd-encode-stage
Oct 16, 2026
Merged

varungup90 merged 6 commits into
vllm-project:mainfrom
theminjunchoi:feat/epd-encode-stage

Conversation

@theminjunchoi

@theminjunchoi theminjunchoi commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request Description

This covers the initial scope of #2962: PD rolesets can now run the multimodal encoder on its own pods.

Give pods role-name: encode and the same roleset-name as the prefill and decode pods. When a vLLM /v1/chat/completions request carries images, audio or video, the gateway first sends each media item to one of that roleset's encode pods. Once they're done, prefill and decode run as usual. Text-only requests, other endpoints and other engines, and rolesets without encode pods take exactly the same path as today, and encode pods never end up as prefill, decode or combined candidates.

The request body stays as it is. vLLM's prefill instance finds the encoder's output by hashing the media item, the same hash the encoder stored it under, and if the output isn't there it encodes the item itself. vLLM's reference proxy has the same mode (--no-rewrite), and its 1E1P1D example doesn't give the decode instance an EC connector at all. Two things follow from this. The PD handlers' rule of only touching top-level keys still holds. And a failed encode only costs latency, so the gateway logs and counts it instead of failing the request.

What changed

  • Encode role. Pods labeled role-name: encode are picked straight from the prefill pod's roleset, and they never count as prefill, decode or combined candidates. A roleset without them works as before.
  • Encode stage (new pd/encode package). Each media item goes out as its own chat request, copied byte for byte, the same way vLLM's proxy sends it. The calls run in parallel, round-robin over the roleset's encode pods, with the prefill request timeout. Each request is capped at max_tokens: 1, so an encoder that isn't started with --mm-encoder-only doesn't generate.
  • Metric. gateway_pd_encode_request_total{status,status_code} counts one sample per item.
  • Docs and sample. A new section in pd-disaggregation.rst with its zh_CN translation, pd_readme.md, and a 1E1P1D sample in samples/disaggregation/vllm/1e1p1d.yaml.

What's left for follow-ups

  • EC connectors that need transfer handles carried in the request, like NIXL and Mooncake EC, which vLLM's proxy supports by rewriting items into *_embeds.
  • E+PD deployments, where the encoder sits in front of combined pods instead of a prefill/decode pair.
  • Load-aware encoder selection.
  • A shorter timeout of its own for encode calls, so a hung encoder can't hold a request for the full prefill timeout.
  • A cap on how many encode calls run at once.

SGLang doesn't need anything here, because its language server calls the encoders itself (--encoder-urls).

Testing

TestRouteEncodesMediaOnTheRolesetEncoders runs Route against httptest encode, prefill and decode pods. It covers three cases: each image reaching an encoder on its own, a text-only request skipping the encoders, and a 500 from an encoder still routing the request. It also makes sure encoders from another roleset are left alone and prefill gets the original messages. It fails if the encode call is removed. TestEncoderRequestCarriesOneItemVerbatim covers item extraction and the shape of the encoder request.

I also ran the encode stage against real vLLM 0.31 on CPU (Qwen2-VL-2B, ECExampleConnector, encoder plus a combined prefill/decode consumer), with requests in exactly the shape the gateway sends. The consumer loaded the encoder output for the unmodified request (Success load encoder cache for hash …), and when I overwrote the cached tensor with zeros its answer broke, so it really skipped its own encoder. Without the encode step it encoded the image itself and answered correctly. A two-image request loaded both outputs. The prefill-to-decode NIXL hop needs GPUs and isn't covered, but this PR doesn't change it.

go test -race ./pkg/plugins/gateway/... ./pkg/metrics/... passes and golangci-lint reports no issues. make html-all builds both languages, msgfmt -c passes on the updated catalog, and the sample validates against the StormService CRD schema.

Related Issues

Part of #2962

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for the Encode stage in the Encode/Prefill/Decode (EPD) disaggregated serving architecture for multimodal requests in vLLM. It adds a new encode package to parse media items and dispatch them in parallel to dedicated encode pods, updates the PD router to coordinate this stage, and includes metrics and documentation. The feedback suggests optimizing routing performance by directly filtering pods instead of grouping all of them, avoiding unnecessary memory allocations when reading successful encode response bodies, and making a switch statement more explicit to prevent future bugs.

Pods labeled role-name=encode now get the media items of vLLM chat
requests before prefill. The body is left alone, so prefill finds the
encoder output by content hash or encodes the item itself.

Signed-off-by: MinJun Choi <[email protected]>
Add an EPD section to pd-disaggregation.rst with the zh_CN translation
and describe the encode stage in pd_readme.md.

Signed-off-by: MinJun Choi <[email protected]>
Pick the roleset's encode pods straight from readyPods, drain successful
responses instead of reading them, and cap the error body at 1KB.

Signed-off-by: MinJun Choi <[email protected]>
@theminjunchoi

Copy link
Copy Markdown
Contributor Author

Hi @varungup90, this is meant as the first step for #2962. If the PR and the overall approach look reasonable to you, I'd be glad to take on the follow-ups listed above once it's merged, starting with E+PD support. Of course, if you already have plans for those pieces or would like them done differently, I'm happy to follow your lead.

@github-actions github-actions Bot added kind/documentation Improvements or additions to documentation area/gateway area/website labels Oct 14, 2026
@varungup90

Copy link
Copy Markdown
Collaborator

@theminjunchoi Thank you for the PR, I will review it. Can you add a sample yaml file, you used for testing.

@varungup90 varungup90 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: approve the code with nits, but hold the merge until the sample YAML @varungup90 already asked for is added and there is one real vLLM EPD run. I found no blocking code defects. The caveat is that the central behavioural claims depend on vLLM semantics that nothing here exercises. The PR says it hasn't been run on GPUs.

I read the full diff and the surrounding PD router code (Route, collectAndBucketPods, groupPDPodsByRoleset, the prefill executor) and ran this in a scratch worktree at this head:

  • gofmt -l and go vet ./pkg/plugins/gateway/algorithms/pd/... ./pkg/metrics/ are clean.
  • go test -race -count=1 ./pkg/plugins/gateway/algorithms/pd/... passes in all packages, including the new encode package and TestRouteEncodesMediaOnTheRolesetEncoders.
  • CI on this head is still running: Go Unit Tests and Sphinx HTML have passed, and lint, race, integration and coverage are still queued. Please re-check before merging.
  • I did not run it against vLLM. I did not run golangci-lint or the Sphinx build myself.

What I verified

  • Opt-in isolation: encodeMedia returns immediately unless the executor exists, the engine is vLLM, the path is /v1/chat/completions (query-stripped), the body has media items, and the prefill pod's roleset has ready encode pods. Everything else follows today's path.
  • Encode pods can't become candidates:
    • groupPDPodsByRoleset only admits prefill and decode in its switch, with no default, so encode pods never enter a bucket.
    • collectAndBucketPods now skips the encode role, so they aren't treated as combined pods either.
  • Roleset scoping: encoders are filtered by the prefill pod's roleset-name, and the test checks that another roleset's encoders get no traffic.
  • Request shape:
    • Items are copied raw via gjson, so bytes are preserved. mm_processor_kwargs and media_io_kwargs are passed through, and stream is forced to false.
    • Headers are forwarded the same way the prefill executor does, with pseudo-headers dropped.
    • The go 1.22.5 module gives per-iteration loop variables, so the goroutine closure is safe.
  • Failure handling: failures are joined and counted per item, and prefill still receives the original messages, which the test confirms with an encoder returning 500.

Inline notes

  1. Is max_tokens really meant to be absent? My recollection is that vLLM's proxy sets max_tokens: 1. I'm going from memory and could not verify it, so please check against the version you tested.
  2. Execute waits up to the full prefill timeout (30s by default) for a hung encoder, and has no concurrency cap.
  3. klog.ErrorS per failed encode could be noisy.

Other points

  • Sample YAML: it is still missing. It should show encode, prefill and decode pods with the shared EC storage.
  • Stale PR description: the text says "Roleset grouping picks up encode pods", but the final commit dropped that change and filters the pods directly in encodeMedia. Please update the description so it matches the code.
  • Docs example: it uses ECExampleConnector with shared_storage_path. Please state explicitly that encode and prefill pods must mount the same volume, and ideally name what kind (RWX PVC, hostPath on one node). Otherwise the stage silently degrades to prefill-side encoding and the user pays double.

Generated by Claude Code

if out, err = sjson.SetRawBytes(out, "messages", []byte(messages)); err != nil {
return nil, err
}
if out, err = sjson.SetBytes(out, "stream", false); err != nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question that needs a real-engine answer: the PR text and the comment on requestBody say this is "the same shape vLLM's reference EPD proxy sends", and TestEncoderRequestCarriesOneItemVerbatim asserts that max_tokens is absent. My recollection of vLLM's disagg_epd_proxy.py is that its per-item encoder request also sets max_tokens: 1 (with a comment that the server only needs to run the encoder path) and possibly add_special_tokens. I'm going from memory and could not check it here, so please verify against the vLLM version you tested.

If an encode instance that isn't launched with --mm-encoder-only treats a missing max_tokens as "generate up to the context limit", every media item would trigger a full generation on the encoder pod. If it is always encoder-only, omitting it is harmless. Either way, please say which it is in the comment, or add max_tokens: 1 if that is what the reference proxy does. This is also the main reason I want one real run on GPUs before merge, since the PR says it hasn't been run on GPUs.


Generated by Claude Code


// Execute sends each item to one of encoders, all at once, and waits for every
// response. It returns the failures joined, or nil when every item was encoded.
func (e *Executor) Execute(routingCtx *types.RoutingContext, encoders []*v1.Pod, items []string, timeout time.Duration) error {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking design notes on Execute, since "a failed encode only costs latency" is the central claim:

  1. Worst-case latency. wg.Wait() blocks until every item returns or hits timeout, which is the prefill request timeout (30s by default via AIBRIX_PREFILL_REQUEST_TIMEOUT). A hung (not crashed) encoder therefore adds up to 30s before the prefill call even starts, per request, and round-robin keeps sending 1/N of the items there. Prefill then gets its own full timeout. A separate and shorter encode timeout, or a hedge or skip after a first failure, would bound that. A shorter timeout is cheap, as the prefill pod falls back to encoding itself.
  2. No concurrency cap. One goroutine and one HTTP request per item, with no limit. A request with dozens of images fans out dozens of simultaneous calls to a handful of encoders from every in-flight request. vLLM's own proxy does the same, so this is acceptable for a first cut, but a small semaphore would be safer, and the metric would show it if it ever hurt.

Both fit your follow-ups list ("load-aware encoder selection"). I'd just record them there.


Generated by Claude Code

return
}
if err := r.encodeExecutor.Execute(ctx, encoders, items, ctx.PDOverrides().PrefillRequestTimeout); err != nil {
klog.ErrorS(err, "encode_request_failed", "request_id", ctx.RequestID,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: because an encode failure is expected to be survivable, logging each one with klog.ErrorS can flood the gateway log if the encoders are down or misconfigured. Every multimodal request would emit an error line plus one joined error per item. The counter already carries the signal. Consider klog.V(2).InfoS or WarningS, or rate-limit it. That is a style call, not a correctness issue.


Generated by Claude Code

A StormService with encode, prefill and decode roles for a VL model, with
the EC cache shared between encode and prefill, plus a README section.

Signed-off-by: MinJun Choi <[email protected]>
Encoders started without --mm-encoder-only, or on vLLM before 0.29, would
otherwise generate a full answer per item. Failures are already counted.

Signed-off-by: MinJun Choi <[email protected]>
Point to the 1E1P1D sample, and note that a missing shared volume makes
prefill encode every item itself.

Signed-off-by: MinJun Choi <[email protected]>
@theminjunchoi

Copy link
Copy Markdown
Contributor Author

Thanks a lot for the thorough review, @varungup90. I've pushed changes for all of it.

The sample is in samples/disaggregation/vllm/1e1p1d.yaml, with a short section in the vLLM samples README. Since I don't have GPUs, I ran the encode stage against real vLLM 0.31 on CPU instead (Qwen2-VL-2B, ECExampleConnector, an encoder plus a combined prefill/decode consumer, with requests built exactly the way the gateway builds them). The consumer loaded the encoder output for the unchanged request, and when I zeroed the cached tensor its answer broke, so it really does skip its own encoder. Without the encode step it encoded the image itself and still answered correctly, and a two-image request loaded both outputs. The prefill-to-decode NIXL hop isn't covered since that needs GPUs, but this PR doesn't change it. One thing I ran into: vLLM's CPU backend needs VLLM_USE_V2_MODEL_RUNNER=0 on an encoder-only instance, which is a vLLM CPU issue rather than anything on our side.

You were right about max_tokens. vLLM's proxy dropped it in 0.29 because an --mm-encoder-only instance stops after the prompt, but a full-model producer kept generating until EOS in my run. The request now always sets max_tokens: 1, which made no difference on the encoder-only instance.

I also moved the failure log to V(2) since the metric already counts failures, updated the PR description to match the code, and spelled out in the docs that encode and prefill pods need the same volume (an RWX PVC or a hostPath on one node). I've added the shorter encode timeout and the concurrency cap to the follow-ups, as you suggested.

@cursor

cursor Bot commented Oct 14, 2026

Copy link
Copy Markdown

Design simplification review

Verdict: approved — right-sized first slice of #2962; no redesign needed.

What works

  • Opt-in EPD on top of existing PD. Encode runs only for vLLM /v1/chat/completions with media items and a roleset that already has ready role-name: encode pods. Text-only, other engines/endpoints, and plain PD rolesets keep today’s path.
  • No body rewrite. Leaving messages untouched and relying on vLLM’s content-hash EC lookup matches the RFC (“transfer outside the Gateway”) and preserves the PD handlers’ top-level-only rule. Deferring *_embeds / NIXL-EC rewrite is the right cut.
  • Isolation without bigger roleset APIs. Filtering encode pods directly in encodeMedia, leaving groupPDPodsByRoleset as prefill/decode-only, and skipping encode in collectAndBucketPods is simpler than stuffing encode into the PD bucket type.
  • pd/encode package. Small, testable surface (MediaItems, requestBody, Executor) without inventing a general stage framework.
  • Failure model. Soft-fail + metric + prefill self-encode matches vLLM’s fallback and avoids failing multimodal traffic when encoders are down or misconfigured.
  • Docs / sample. Shared EC volume callout and 1e1p1d.yaml close the ops gap from the earlier review.

Optional follow-ups (already listed; not merge blockers)

  1. Dedicated encode timeout + concurrency cap (full prefill timeout × N parallel items can dominate latency).
  2. Encode time currently sits after AddPrefillRequest, so outstanding prefill load is inflated while encoding — fine for v1, worth revisiting with load-aware encode selection.
  3. E+PD and connector rewrite paths can stay out of this PR.

Design recommendation: Approve — ship this shape; harden timeouts/selection in follow-ups.

@cursor

cursor Bot commented Oct 14, 2026

Copy link
Copy Markdown

Code review

Verdict: nits only — no merge-blocking correctness issues found on head 28759ee62280dd4dfee4bb7be121bbc1a672c041.

Verified

  • Encode pods never become PD/combined candidates: groupPDPodsByRoleset only admits prefill/decode; collectAndBucketPods skips encode for combined collection.
  • Roleset scoping: encoders filtered by the selected prefill pod’s roleset-name; TestRouteEncodesMediaOnTheRolesetEncoders asserts another roleset’s encoders get no traffic and prefill still receives original messages.
  • Request shape: per-item verbatim gjson copy, stream: false, max_tokens: 1, passthrough of mm_processor_kwargs / media_io_kwargs; matches the author’s vLLM 0.31 note that full-model producers otherwise generate to EOS.
  • Headers: same Envoy pseudo-header drop as prefill (: / empty). Explicit Content-Length from the original request is overridden by net/http from the new body (checked locally).
  • Failure path: per-item metrics; joined errors logged at V(2); HTTP 500 from encoder still routes — covered by the Route table test.
  • Go 1.22 loop vars: goroutine closure over i/item/pod is safe under go 1.22.5.
  • Local checks: go test -race -count=1 ./pkg/plugins/gateway/algorithms/pd/encode/... ./pkg/plugins/gateway/algorithms/pd/router/ -run 'Encode|Encoder|EncodesMedia' → pass.

Prior review items (resolved on this head)

  • Sample YAML (samples/disaggregation/vllm/1e1p1d.yaml) + README section added.
  • max_tokens: 1 always set.
  • Failure log demoted to V(2).
  • Docs state encode/prefill must share the EC volume (RWX / same-node hostPath).

Nits / non-blockers

  1. Timeout stacking: each encode item uses PrefillRequestTimeout, then prefill uses it again under the same parent context — worst case ~2× when the client deadline is long. Follow-up already noted.
  2. Unbounded fan-out: one goroutine per media item with no semaphore; large multi-image requests can stampede encode pods.
  3. Prefill outstanding inflation: AddPrefillRequest runs in Select before encodeMedia, so encode latency counts as prefill load.
  4. Reuse forwardablePrefillHeader: encode inlines the same :-prefix filter; sharing the helper would keep the two outbound paths in sync.
  5. CI on this head: DCO + ReadTheDocs green; Go lint/unit/race/integration and smoke were still queued/pending at review time. An earlier push had Go Unit/Race/Lint/Integration/Verify success before cancel-on-push — please confirm the latest run is green before merge.

Code recommendation: Approve (nits / follow-ups only).

@varungup90
varungup90 merged commit 2f8a517 into vllm-project:main Oct 16, 2026
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants