Skip to content

[Feat] Support E+PD routing for encode pods - #3153

Merged
varungup90 merged 9 commits into
vllm-project:mainfrom
theminjunchoi:feat/epd-e-pd
Oct 18, 2026
Merged

varungup90 merged 9 commits into
vllm-project:mainfrom
theminjunchoi:feat/epd-e-pd

Conversation

@theminjunchoi

@theminjunchoi theminjunchoi commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

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 pd can 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. In pd routing, the stage now also runs when bucketing picks a combined pod, which it used to skip.

  • Moved the encode stage into pd/encode so 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 a roleset-name label set to an empty value.
  • Added a paragraph to pd-disaggregation.rst (with zh_CN), a note in pd_readme.md, and a 1e1pd.yaml sample.

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

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]>

@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 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

This comment was marked as duplicate.

@googs1025 googs1025 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.

Could you please provide the logs from the actual test? If available, could you kindly attach them? 😄

@theminjunchoi

Copy link
Copy Markdown
Contributor Author

@googs1025 Sure! I ran it on CPU with vLLM 0.31 and Qwen2-VL-2B: one encoder (--mm-encoder-only, ec_producer) and one worker (ec_consumer) sharing an ECExampleConnector directory. The gateway side is this branch's selectTargetPod with the random strategy, without Envoy or Kubernetes. Each request has one image, a colored square, and asks "What color is the square? Answer in one word."

Green square: the gateway encodes it first, then the worker answers from the encoder output.

I1018 12:11:39.347605 stage.go:94] "encode_request_end" request_id="epd-e2e-green" roleset="vllm-1e1pd-roleset-0" media_items=1
gateway: routing-strategy=random target=vllm-1e1pd-worker-0 (127.0.0.1:8002) routing+encode took 1m13.613s
worker: HTTP 200, answer="Green", prompt_tokens=288

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.

worker with zeroed cache: 'The color of the answer is "blue".'

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.

I1018 12:08:11.567257 stage.go:90] "encode_request_failed" error="encode item 0 on pod vllm-1e1pd-encode-0: Post \"http://127.0.0.1:8001/v1/chat/completions\": context deadline exceeded" request_id="epd-e2e-blue" roleset="vllm-1e1pd-roleset-0" media_items=1
gateway: routing-strategy=random target=vllm-1e1pd-worker-0 (127.0.0.1:8002) routing+encode took 30.003s
worker: HTTP 200, answer="Blue", prompt_tokens=288

@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 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 new encodeMedia call sites: the single-candidate fast path and after router.Route), encode.EncodeMedia/Executor.Execute, the PD router's combined-pod hook, and the timeout plumbing. RoutingOverrides().PD.PrefillRequestTimeout is non-zero by default because routing.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 -race pass; go vet ./pkg/plugins/gateway/... is clean. The Test_jsonParseReason_OmitsBodyContent failure 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_EPlusPD and ...OnlyEncodersReady fail
    • no encode after Route → ...EPlusPD fails (first subtest)
    • no encode on the single-candidate fast path → ...EPlusPD fails (third subtest)
    • remove the "no roleset" guard → ...EncodersNeedARoleset fails
    • PD router doesn't encode for a combined pod → TestRouteEncodesMediaForACombinedPod fails
    • 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
  • The zh_CN catalog: I parsed the .po with polib and the new msgid matches the new .rst paragraph exactly, with a non-empty, non-fuzzy translation. I don't read Chinese well enough to review the wording beyond that.
  • 1e1pd.yaml parses and has the same shape as 1e1p1d.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

  1. Engine default mismatch (inline). Without the model.aibrix.ai/engine label the PD router assumes vLLM; the gateway path then skips the encode stage. I reproduced it.
  2. A regression in pd routing wouldn't be caught. Nothing at the gateway level asserts that pd still hands encode pods to the PD router (the mutant that drops them for pd too survives); the existing PD tests run below selectTargetPod. Since that would silently break the existing 1E1P1D setup, a test that routes with the pd strategy and checks the encoder is still among the candidates would be worth adding.
  3. The moved hasHTTPServer filter is a copy of the router's isPodWithHTTPServer (and roleLabel/rolesetLabel/podGroupIndexLabel duplicate the router's constants), and no test covers the multi-node-encoder case in either place. Reusing one helper would avoid drift.
  4. 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.
  5. Latency on encoder trouble now reaches every strategy. An encode failure only costs latency, as designed, but that latency is spent in selectTargetPod before the request is forwarded: the author's own run shows routing+encode took 30.003s when 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 selectTargetPod using the random strategy) 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

Comment thread pkg/plugins/gateway/gateway.go Resolved
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]>
@theminjunchoi

Copy link
Copy Markdown
Contributor Author

Thanks a lot for the thorough review, @varungup90, and for running the mutants. That made the gaps easy to see.

  1. Engine label: fixed, see the inline reply.
  2. Added a gateway test that routes with pd and checks the encode pod still reaches the PD router and the gateway doesn't run the stage again.
  3. Moved the roleset, role and pod group labels and IsPodWithHTTPServer into the pd package, so the router and the encode stage share them. A new test covers a multi-node encoder, where only the pod with the HTTP server gets requests.
  4. You're right, the roleset check also applies to pd. Prefill and combined pods already need the roleset-name label to be candidates there, so it only changes things when the label is set to an empty value. I'll mention it in the description.
  5. Added a sentence to the E+PD docs about the delay a stuck encoder can add. A separate, shorter encode timeout was on my follow-up list from [Feat] Send multimodal requests through EPD encode pods in PD routing #3069, so I'd like to do it in the next PR, if that works for you.

With these changes, the three mutants that survived before now fail.

@cursor

cursor Bot commented Oct 18, 2026

Copy link
Copy Markdown

Design simplification review

Verdict: Approve

Reviewed tip 5e80725c2f0800207ed995a14fe45edc1571d961. Required CI green on tip (Installation E2E still running at post time; non-required). DCO pass.

What works

  • Right-sized follow-up to [Feat] Send multimodal requests through EPD encode pods in PD routing #3069. Encode pods share model labels with serving pods, so non-pd strategies could route chat to them. Dropping them via encode.SplitEncoders for every non-PD path, and running the same encode stage on the chosen pod’s roleset, is the smallest correct fix for E+PD without inventing a new router.
  • Shared EncodeMedia is the right extract. Moving the stage into pd/encode so the gateway and the PD router both call it avoids duplicating the media/roleset/HTTP-server filter logic. Sharing pd.RoleSetLabel / RoleLabel / IsPodWithHTTPServer closes the copy-drift gap from the earlier review.
  • Combined-pod hook is a one-liner where it belongs. When bucketing returns no prefill, encoding on the combined (decode) pod’s roleset before SetTargetPod matches how E+PD treats the single consumer — no new policy surface.
  • Soft-fail + no body rewrite stays intact. Encode failure still costs latency only; docs now say a stuck encoder can delay multimodal requests by up to AIBRIX_PREFILL_REQUEST_TIMEOUT. Deferring a dedicated shorter timeout to a follow-up is fine.
  • Sample + docs match the code. 1e1pd.yaml mirrors 1e1p1d.yaml shape; zh_CN catalog covers the new paragraph.

Optional follow-ups (non-blocking)

  • Dedicated encode timeout (author already flagged for a next PR).
  • Comparing engine != "vllm" without importing pdrouter only for VLLMEngine would shave a tiny dependency edge; not worth churn here.

No redesign needed — ship this shape.

@cursor

cursor Bot commented Oct 18, 2026

Copy link
Copy Markdown

Code review

Verdict: Approve (nits / follow-ups only)

Reviewed tip 5e80725c2f0800207ed995a14fe45edc1571d961. Required CI green (0 failed / 0 pending required); Installation E2E still in progress (non-required). DCO pass. Local: go test -count=1 ./pkg/plugins/gateway/ -run 'EPlusPD|OnlyEncoders|EncodersNeed|PDKeeps|EncodeSkips' and ./pkg/plugins/gateway/algorithms/pd/... -run 'Encode|Encoder|EncodesMedia|Combined' pass.

What I checked

  • selectTargetPod: encoders stripped only when !isPD (via ResolveExclusiveStrategy); both the single-candidate fast path and post-Route call encodeMedia; PD path keeps encoders for the router and gateway encodeMedia is a no-op (len(encoders)==0).
  • Engine default: gateway now uses ValidateAndGetLLMEngine so a missing model.aibrix.ai/engine counts as vLLM, matching the PD router (covered by Test_selectTargetPod_EPlusPDEngine).
  • Empty roleset: EncodeMedia returns when roleset == "", so encoders without a roleset never match a worker without one (Test_selectTargetPod_EncodersNeedARoleset).
  • PD combined pods: prefillPod == nil → encodeMedia(..., decodePod) (TestRouteEncodesMediaForACombinedPod).
  • Multi-node encoders: only pod-group-index=0 (or unlabeled) gets encode traffic (Test_selectTargetPod_EncodeSkipsNonHTTPEncoderPods).
  • Regression guard: Test_selectTargetPod_PDKeepsEncoders asserts encode pods still reach the PD router and the gateway does not double-run the stage.
  • Prior varungup90 findings (engine mismatch, PD-keeps-encoders mutant, shared labels, timeout docs) are addressed on this tip.

Nits (non-blocking)

  1. Test_selectTargetPod_PDKeepsEncoders re-registers RouterPD without restoring the real factory — same pattern as existing gateway_test.go PD mocks; fine for serial package tests, but a t.Cleanup restore would be safer if anything later expects the real PD router in-process.
  2. Gemini nil-pod guards on IsEncoder / SplitEncoders — call sites already use filtered ready pods; optional defense-in-depth only.
  3. Encode timeout still equals prefill timeout — documented; a shorter dedicated knob remains a good follow-up so a hung encoder does not add 30s to every non-PD multimodal request.

What I did not run

  • No cluster / Envoy ext_proc E2E; relied on author’s CPU vLLM 0.31 selectTargetPod + random logs in the PR thread.

Approve — no merge blockers on tip once required CI stays green.

@varungup90
varungup90 merged commit 8faba17 into vllm-project:main Oct 18, 2026
26 of 27 checks passed

@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.

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 with ValidateAndGetLLMEngine, the same helper the PD router uses, so a pod without model.aibrix.ai/engine counts as vLLM here too. This fixes my earlier finding.
  • e848d5dd — adds Test_selectTargetPod_EPlusPDEngine (missing label vs sglang) and Test_selectTargetPod_PDKeepsEncoders. The second is the pd strategy-keeps-encoders case I said was untested.
  • adbf9731 — moves the pod-label constants and the HTTP-server check into pd/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 old hasHTTPServer in encode (!ok || index == "0") and the old isPodWithHTTPServer in the router are the same logic as the new IsPodWithHTTPServer, so no behavior change. It also adds Test_selectTargetPod_EncodeSkipsNonHTTPEncoderPods.
  • 5e80725c — documents the latency a stuck encoder adds (English and zh_CN .po).

What I checked

  • The docs claim is accurate. Executor.Execute sends all items in parallel, each with the same timeout (encode.go:124-143). The delay is therefore bounded by one prefill request timeout, not by items × timeout. The timeout is routeCtx.RoutingOverrides().PD.PrefillRequestTimeout, which comes from AIBRIX_PREFILL_REQUEST_TIMEOUT and can be overridden per profile via pd.prefillRequestTimeout.
  • I confirmed the constants moved without a value change: PDRoleSetIdentifier, PDRoleIdentifier and PodGroupIndex in router.go are now aliases of the pd constants. A pd → encode import 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 pd packages:
    • 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 IsPodWithHTTPServer accept every index except "1": killed (TestFilterPrefillDecodePods edge 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.
  • 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 triage run shows cancelled, which is a superseded run, and build was 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)

  1. 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 in rs-b that must receive 0 calls would pin it.
  2. Encode runs before the in-flight cap is checked. From reading only, not tested: selectTargetPod runs encodeMedia right after Route succeeds (and after the single-candidate fast path). enforceReplicaInflight runs later in HandleRequestBody for routers that don't call AdmitTarget. When the picked pod is at requestsInflight, 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 call routeCtx.AdmitTarget first.

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

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.

3 participants