Repository navigation
feat(pd): stitch by-handle routed_experts payload segments - #60
Open
faresobeid wants to merge 5 commits into
Open
faresobeid wants to merge 5 commits into
faresobeid wants to merge 5 commits into
Conversation
This was referenced Oct 3, 2026
faresobeid
force-pushed
the
feat/pd-merge-payload-segments
branch
from
October 6, 2026 17:24
629e72d to
7d22041
Compare
faresobeid
marked this pull request as ready for review
October 13, 2026 17:49
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This adds a new production integration for file-backed routed-experts payloads, including segment clipping, offset rewriting, and altered streaming/error behavior in P/D responses. Existing paths are preserved, but the external payload contract and customer-visible response assembly warrant human review. Notes:
No code changes detected at You can add or adjust custom eligibility rules. Learn more. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Under disaggregated P/D, stitch by-handle
payloadsegments the same way the router stitches inlinerouted_experts.prime-rl's
/inference/v1/generatecan return per-choicepayload: [{field, file, offset, pos, rows, dtype, shape}, ...]instead of inlinerouted_experts/sampling_mask. The segments point at rows in a shared file. Without this PR, the P/D merge leaves them unchanged, so the response has no prefill routing for the prompt.Merge rule (
merge_routed_payload_in_json, called frommerge_routed_experts_for_pdnext to the inline merge)A routed_experts segment covers the absolute positions
[pos, pos + rows). The prime-rl writer anchors segments at the end:pos = prompt_len + len(completion_token_ids) - 1 - rows. On vLLM 0.31 P/D a decode instance emits rows from its first forward (prompt_len - 1), so its rows overlap the end of prefill's.field == "routed_experts"segments are touched. Other fields, such assampling_mask, keep the decode response's segments, as the inline path does.choices[0]and are kept as-is. Every decode choice gets them.cut = max(pos + rows)over the prefill routed segments.>= cut:pos + rows <= cutis dropped;pos < cutis clipped:offset += (cut - pos) * row_bytes,rows -= cut - pos,pos = cut, whererow_bytes = itemsize(dtype) * prod(shape).payload= prefill routed segments, then the decode segments in their original order.prefill_has_routed_expertsalso counts routed payload segments, so a streaming P/D request with them is refused, as for inline routing.Dependencies
vllm-routerpin bump.Tests
routed_experts_merge.rs: prepend + drop of decode rows beforecut+sampling_maskpass-through, and the no-op case.cargo test,cargo +1.95.0 clippy --all-targets -- -D warnings,cargo +1.95.0 fmt --check.Note
Add payload-segment merging for by-handle routed_experts in PD router
merge_routed_payload_in_jsonin routed_experts_merge.rs. It copies prefill routed_experts payload segments into every decode choice, drops decode rows already covered by prefill, and trims and re-offsets partially overlapping decode segments using dtype and shape metadata.prefill_has_routed_expertsto detect routed_experts entries in the first choice's payload segment list, not just inline data.VllmPDRouter::merge_routed_experts_for_pdin vllm_pd_router.rs now runs both the inline and payload-segment merges, combining their results and propagating either error.pos/rows/offset, unsupported dtypes, overflow insegment_endorsegment_row_bytes) now returns an error frommerge_routed_experts_for_pdinstead of being ignored.Macroscope summarized 38b7135.
Note
Medium Risk
Changes P/D response assembly for inference generate payloads; bad or mismatched segment metadata now fails the merge instead of returning an unmerged decode body.
Overview
Adds by-handle P/D stitching for
routed_expertswhen responses usechoices[].payloadfile segments instead of inlinerouted_experts.New
merge_routed_payload_in_jsonprepends prefillrouted_expertssegments onto each decode choice, computes a cut from prefill coverage, and drops or trims overlapping decode segments (adjustingoffset,pos, androwsfrom dtype/shape). Non-routed_expertspayload fields stay on the decode side.prefill_has_routed_expertsnow treats routed payload segments like inline data (including streaming refusal).VllmPDRouter::merge_routed_experts_for_pdruns the existing inline merge and this payload merge, OR-ing success and surfacing errors from either path.Unit tests cover overlap trimming, no-op when no routed segments, and overflow on segment metadata.
Reviewed by Cursor Bugbot for commit 38b7135. Bugbot is set up for automated code reviews on this repo. Configure here.