Repository navigation
[Feat] Support E+PD routing for encode pods - #3153
Conversation
Picking a roleset's encoders and running the stage no longer needs the PD router, so the gateway can run it for other routing strategies too. The PD router keeps its vLLM check and passes the target pod in. Signed-off-by: MinJun Choi <[email protected]>
When bucketing sends a request to a combined pod there is no prefill leg, so the encode stage was skipped. Run it on the combined pod's roleset before routing to it. Signed-off-by: MinJun Choi <[email protected]>
Encode pods are labeled with the model like any serving pod, so strategies other than pd could send a chat request to one. Drop them from the candidates, and when the chosen pod's roleset has encode pods, run the encode stage on them before returning the pod. Signed-off-by: MinJun Choi <[email protected]>
Describe encode pods in front of pods that serve the whole request, with the zh_CN translation, and add a vLLM sample with an encode role and a worker role that reads the encoder output from the shared EC cache. Signed-off-by: MinJun Choi <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces support for Encode + PD (E+PD) routing, allowing encode pods to sit in front of pods that serve the entire request without a prefill/decode split. It refactors the encode stage execution into a dedicated package, updates the gateway and PD router to handle combined pods, filters out encoders for non-PD routing strategies, and adds documentation, tests, and a sample configuration. The review feedback suggests adding nil guards and empty-string checks across several helper functions in the new encode package to prevent potential nil pointer dereferences and incorrect label matching.
An empty roleset would match encoders that have no roleset either. Signed-off-by: MinJun Choi <[email protected]>
googs1025
left a comment
There was a problem hiding this comment.
Could you please provide the logs from the actual test? If available, could you kindly attach them? 😄
|
@googs1025 Sure! I ran it on CPU with vLLM 0.31 and Qwen2-VL-2B: one encoder ( Green square: the gateway encodes it first, then the worker answers from the encoder output. Yellow square: after encoding it, I zeroed the saved encoder output and sent the request to the worker. The answer is wrong, so the worker does read the encoder output instead of encoding the image itself. Blue square: the encode hit the 30s timeout on CPU. The request still succeeds because the worker encodes the image itself, so a failed encode only adds latency. |
varungup90
left a comment
There was a problem hiding this comment.
Verdict: approve with nits. The design is sound (encoders can no longer be picked by other strategies, and the encode stage runs on the chosen pod's roleset), the diff stays small, and CI is green. The thing to fix before merge is the engine-label mismatch (inline); the rest are test gaps and notes.
What I checked
- Read
selectTargetPod(both newencodeMediacall sites: the single-candidate fast path and afterrouter.Route),encode.EncodeMedia/Executor.Execute, the PD router's combined-pod hook, and the timeout plumbing.RoutingOverrides().PD.PrefillRequestTimeoutis non-zero by default becauserouting.Init()folds the PD env defaults into the process table regardless of strategy, so the encode context isn't born expired. - Tests:
go test -count=1 ./pkg/plugins/gateway/ ./pkg/plugins/gateway/algorithms/pd/...and the same under-racepass;go vet ./pkg/plugins/gateway/...is clean. TheTest_jsonParseReason_OmitsBodyContentfailure in the description doesn't reproduce here (Go 1.24.7): everything under./pkg/plugins/gateway/...passed. - The new tests can't be run against the base commit (they use new symbols), so I used mutants (reverted after each):
- don't drop encoders for non-PD strategies →
Test_selectTargetPod_EPlusPDand...OnlyEncodersReadyfail - no encode after
Route→...EPlusPDfails (first subtest) - no encode on the single-candidate fast path →
...EPlusPDfails (third subtest) - remove the "no roleset" guard →
...EncodersNeedARolesetfails - PD router doesn't encode for a combined pod →
TestRouteEncodesMediaForACombinedPodfails - also drop encoders when the strategy is
pd→ survives - drop the vLLM-engine gate in the gateway → survives
- let encoders without an HTTP server (pod-group-index ≠ 0) through → survives
- don't drop encoders for non-PD strategies →
- The zh_CN catalog: I parsed the
.powithpoliband the newmsgidmatches the new.rstparagraph exactly, with a non-empty, non-fuzzy translation. I don't read Chinese well enough to review the wording beyond that. 1e1pd.yamlparses and has the same shape as1e1p1d.yaml(same spec keys, same label set on both roles). I did not apply it to a cluster.- CI on this head is green (25 checks, including Sphinx HTML, Go Unit/Race/Integration/Lint and the installation E2E).
Findings
- Engine default mismatch (inline). Without the
model.aibrix.ai/enginelabel the PD router assumes vLLM; the gateway path then skips the encode stage. I reproduced it. - A regression in
pdrouting wouldn't be caught. Nothing at the gateway level asserts thatpdstill hands encode pods to the PD router (the mutant that drops them forpdtoo survives); the existing PD tests run belowselectTargetPod. Since that would silently break the existing 1E1P1D setup, a test that routes with thepdstrategy and checks the encoder is still among the candidates would be worth adding. - The moved
hasHTTPServerfilter is a copy of the router'sisPodWithHTTPServer(androleLabel/rolesetLabel/podGroupIndexLabelduplicate the router's constants), and no test covers the multi-node-encoder case in either place. Reusing one helper would avoid drift. - Small PD-path behaviour change. The new
roleset == ""early return also applies to PD routing; before, encoders and a prefill/combined pod that both lacked a roleset label matched each other. That is a safer behaviour, but the description says encoder requests are unchanged, so it deserves a mention. - Latency on encoder trouble now reaches every strategy. An encode failure only costs latency, as designed, but that latency is spent in
selectTargetPodbefore the request is forwarded: the author's own run showsrouting+encode took 30.003swhen the encoder timed out. Because the timeout is the PD prefill knob (default 30 s), a hung encoder adds up to that per multimodal request for non-PD strategies too. A dedicated, shorter encode timeout or a note in the docs would help operators.
What I did not run
- No real vLLM or cluster; I relied on the author's comment (a CPU run with vLLM 0.31 through
selectTargetPodusing therandomstrategy) and did not reproduce it. - Envoy/ext_proc end to end, so the ordering of the encode stage relative to Envoy's request handling is unchecked.
Generated by Claude Code
The PD router reads a pod without model.aibrix.ai/engine as vLLM, but the gateway skipped the encode stage for it. Resolve the engine the same way and test both the missing label and a non-vLLM engine. Signed-off-by: MinJun Choi <[email protected]>
The PD router picks encoders from the roleset it routes to, so dropping them for pd too would break 1E1P1D without failing any test. Signed-off-by: MinJun Choi <[email protected]>
The encode stage had its own copies of the roleset, role and pod group labels and of isPodWithHTTPServer. Move them to the pd package so both use one, and test that a multi-node encoder only gets requests on the pod that runs the HTTP server. Signed-off-by: MinJun Choi <[email protected]>
The encode stage runs before the request is forwarded and uses the prefill request timeout, so say so in the E+PD paragraph. Signed-off-by: MinJun Choi <[email protected]>
|
Thanks a lot for the thorough review, @varungup90, and for running the mutants. That made the gaps easy to see.
With these changes, the three mutants that survived before now fail. |
Design simplification reviewVerdict: Approve Reviewed tip What works
Optional follow-ups (non-blocking)
No redesign needed — ship this shape. |
Code reviewVerdict: Approve (nits / follow-ups only) Reviewed tip What I checked
Nits (non-blocking)
What I did not run
Approve — no merge blockers on tip once required CI stays green. |
varungup90
left a comment
There was a problem hiding this comment.
Follow-up on the new commits (669f1050..5e80725c). Recommendation: approve. The finding from my earlier review is fixed and tested. What is left are two small notes. This is a review comment, not a formal GitHub approval.
What changed since my last review
62ce49b6— the gateway now decides the engine withValidateAndGetLLMEngine, the same helper the PD router uses, so a pod withoutmodel.aibrix.ai/enginecounts as vLLM here too. This fixes my earlier finding.e848d5dd— addsTest_selectTargetPod_EPlusPDEngine(missing label vssglang) andTest_selectTargetPod_PDKeepsEncoders. The second is thepdstrategy-keeps-encoders case I said was untested.adbf9731— moves the pod-label constants and the HTTP-server check intopd/pod_labels.go, shared by the PD router and the encode stage. The label strings are unchanged (roleset-name,role-name,stormservice.orchestration.aibrix.ai/pod-group-index). The oldhasHTTPServerinencode(!ok || index == "0") and the oldisPodWithHTTPServerin the router are the same logic as the newIsPodWithHTTPServer, so no behavior change. It also addsTest_selectTargetPod_EncodeSkipsNonHTTPEncoderPods.5e80725c— documents the latency a stuck encoder adds (English and zh_CN.po).
What I checked
- The docs claim is accurate.
Executor.Executesends all items in parallel, each with the sametimeout(encode.go:124-143). The delay is therefore bounded by one prefill request timeout, not by items × timeout. The timeout isrouteCtx.RoutingOverrides().PD.PrefillRequestTimeout, which comes fromAIBRIX_PREFILL_REQUEST_TIMEOUTand can be overridden per profile viapd.prefillRequestTimeout. - I confirmed the constants moved without a value change:
PDRoleSetIdentifier,PDRoleIdentifierandPodGroupIndexinrouter.goare now aliases of thepdconstants. Apd→encodeimport now exists and builds with no cycle.
What I ran
go test -race -count=1 ./pkg/plugins/gateway/ ./pkg/plugins/gateway/algorithms/...passed.- Mutants, each applied alone, all in the gateway or
pdpackages:- revert to the label-equality engine check: killed (
Test_selectTargetPod_EPlusPDEngine/a_pod_without_the_engine_label_counts_as_vLLM); - drop the engine comparison, keeping the error check: killed (
.../other_engines_skip_the_encode_stage); - drop the HTTP-server filter in
EncodeMedia: killed (Test_selectTargetPod_EncodeSkipsNonHTTPEncoderPods); - make
IsPodWithHTTPServeraccept every index except"1": killed (TestFilterPrefillDecodePodsedge cases); - also split encoders at the gateway for
pd(if !isPD || true): killed (Test_selectTargetPod_PDKeepsEncoders); - drop the same-roleset filter in
EncodeMedia(pod.Labels[pd.RoleSetLabel] == roleset): survives.
- revert to the label-equality engine check: killed (
- CI on this head is green: Go Lint, Go Unit Tests, Go Race Tests, Go Integration Tests, Verify Generated Code, Go Coverage, Installation E2E, both Installation Smoke jobs, Sphinx HTML and DCO. One older
triagerun showscancelled, which is a superseded run, andbuildwas skipped.
Not run: golangci-lint locally (CI Go Lint is green) and a real vLLM encoder or cluster. The Sphinx build I did not run; the CI Sphinx HTML job is green.
Notes (non-blocking)
- The same-roleset filter is untested. With that filter removed, an encoder in another roleset would receive the target's media, and every test stays green. The existing tests use a single roleset (
rs-a). One extra encoder pod inrs-bthat must receive 0 calls would pin it. - Encode runs before the in-flight cap is checked. From reading only, not tested:
selectTargetPodrunsencodeMediaright afterRoutesucceeds (and after the single-candidate fast path).enforceReplicaInflightruns later inHandleRequestBodyfor routers that don't callAdmitTarget. When the picked pod is atrequestsInflight, an E+PD request still pays for the encode HTTP calls and then gets a 429. That is the same waste #3127 removed for the PD prefill leg, and it happens under saturation. It is minor now. If it matters, the fix is to run the encode stage after the admission step, or to have it callrouteCtx.AdmitTargetfirst.
Verdict: approve. My earlier finding is resolved with a test, and the added tests kill the mutants I tried, except the roleset filter in note 1.
Generated by Claude Code
Pull Request Description
Follow-up to #3069 for E+PD, where encode pods sit in front of pods that serve the whole request, like vLLM's 1E1PD example.
Encode pods carry the same model labels as serving pods, so strategies other than
pdcan currently route a chat request to one. This PR drops encode pods from the candidates for those strategies. If the chosen pod's roleset has encode pods, the gateway runs the #3069 encode stage on them first. Inpdrouting, the stage now also runs when bucketing picks a combined pod, which it used to skip.pd/encodeso the gateway can call it. Encoder requests are unchanged. The stage now also skips a target without a roleset, which on the pd path only matters for aroleset-namelabel set to an empty value.pd-disaggregation.rst(with zh_CN), a note inpd_readme.md, and a1e1pd.yamlsample.Tested with new unit tests, which fail without the change, and
go test ./pkg/plugins/gateway/.... The one failure,Test_jsonParseReason_OmitsBodyContent, also fails on main locally because sonic doesn't support my Go version. I didn't rerun vLLM, since the encoder requests are the same ones I checked for #3069 with an encoder and a combined consumer on vLLM 0.31.Related Issues
Part of #2962