Repository navigation
[Feat] Send multimodal requests through EPD encode pods in PD routing - #3069
Conversation
There was a problem hiding this comment.
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]>
01b5a0f to
4908976
Compare
|
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. |
|
@theminjunchoi Thank you for the PR, I will review it. Can you add a sample yaml file, you used for testing. |
varungup90
left a comment
There was a problem hiding this comment.
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 -landgo 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 newencodepackage andTestRouteEncodesMediaOnTheRolesetEncoders.- 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-lintor the Sphinx build myself.
What I verified
- Opt-in isolation:
encodeMediareturns 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:
groupPDPodsByRolesetonly admitsprefillanddecodein itsswitch, with nodefault, soencodepods never enter a bucket.collectAndBucketPodsnow skips theencoderole, 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_kwargsandmedia_io_kwargsare passed through, andstreamis forced to false. - Headers are forwarded the same way the prefill executor does, with pseudo-headers dropped.
- The
go 1.22.5module gives per-iteration loop variables, so the goroutine closure is safe.
- Items are copied raw via gjson, so bytes are preserved.
- 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
- Is
max_tokensreally meant to be absent? My recollection is that vLLM's proxy setsmax_tokens: 1. I'm going from memory and could not verify it, so please check against the version you tested. Executewaits up to the full prefill timeout (30s by default) for a hung encoder, and has no concurrency cap.klog.ErrorSper 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
encodepods", but the final commit dropped that change and filters the pods directly inencodeMedia. Please update the description so it matches the code. - Docs example: it uses
ECExampleConnectorwithshared_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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Non-blocking design notes on Execute, since "a failed encode only costs latency" is the central claim:
- Worst-case latency.
wg.Wait()blocks until every item returns or hitstimeout, which is the prefill request timeout (30s by default viaAIBRIX_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. - 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, |
There was a problem hiding this comment.
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]>
|
Thanks a lot for the thorough review, @varungup90. I've pushed changes for all of it. The sample is in You were right about I also moved the failure log to |
Design simplification reviewVerdict: approved — right-sized first slice of #2962; no redesign needed. What works
Optional follow-ups (already listed; not merge blockers)
Design recommendation: Approve — ship this shape; harden timeouts/selection in follow-ups. |
Code reviewVerdict: nits only — no merge-blocking correctness issues found on head Verified
Prior review items (resolved on this head)
Nits / non-blockers
Code recommendation: Approve (nits / follow-ups only). |
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: encodeand the sameroleset-nameas the prefill and decode pods. When a vLLM/v1/chat/completionsrequest 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
role-name: encodeare 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.pd/encodepackage). 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 atmax_tokens: 1, so an encoder that isn't started with--mm-encoder-onlydoesn't generate.gateway_pd_encode_request_total{status,status_code}counts one sample per item.pd-disaggregation.rstwith its zh_CN translation,pd_readme.md, and a 1E1P1D sample insamples/disaggregation/vllm/1e1p1d.yaml.What's left for follow-ups
*_embeds.SGLang doesn't need anything here, because its language server calls the encoders itself (
--encoder-urls).Testing
TestRouteEncodesMediaOnTheRolesetEncodersrunsRouteagainst 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.TestEncoderRequestCarriesOneItemVerbatimcovers 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-allbuilds both languages,msgfmt -cpasses on the updated catalog, and the sample validates against the StormService CRD schema.Related Issues
Part of #2962