Repository navigation
fix(pd): honor routed_experts dtype in inline merge - #61
Merged
Merged
Conversation
faresobeid
force-pushed
the
fix/pd-routed-experts-dtype
branch
from
October 6, 2026 17:20
6522fdc to
d38288b
Compare
prime-rl keeps vLLM's per-model dtype (prime-rl#3965), so prefill and decode always send the same dtype and the uint8->uint16 widening is dead. Cut the decode rows that prefill already covers by position instead of by prefill's row count, so a decode instance can send rows from its first forward without zero-padding them to the prompt start.
faresobeid
marked this pull request as ready for review
October 13, 2026 17:49
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — This is a focused, one-file fix to the existing routed-experts P/D merge, adding dtype-aware byte handling and position-aware row stitching with validation and targeted tests. Its effects remain contained to the established merge path, with no new workflow or infrastructure introduced. You can add or adjust custom eligibility rules. Learn more. |
mikasenghaas
approved these changes
Oct 14, 2026
Merged
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.
Purpose
P/D router replay fails every request on models with more than 256 experts (Qwen3.5-397B, Kimi-K2, Nemotron Super/Ultra). Since PrimeIntellect-ai/prime-rl#3965, prime-rl sends vLLM's per-model routing dtype, which is
uint16for those models. The inline P/D merge assumed 1 byte per id and droppeddtypeon re-encode.This PR also changes how the merge cuts the decode rows, so prime-rl no longer has to zero-pad decode responses to the prompt start (PrimeIntellect-ai/prime-rl#3830).
Changes (
routed_experts_merge.rs)dtypeis required (uint8oruint16). Row bytes =itemsize(dtype) * layers * topk.dtypeis kept on re-encode.decode.suffix_rows((prompt.start + prompt.seq_len).saturating_sub(decode.start)). Prefill rows are followed by the decode rows from the prefill end on; a gap is an error.prompt_len - 1) works without padding.Release
Ships as router v0.2.3. The version bump is on branch
release/v0.2.3(this PR +release: v0.2.3). After this PR merges, rebase that branch onto main and open therelease/v0.2.3PR; merging it tags v0.2.3 (.github/workflows/release.yml). prime-rl then bumps its router pin.Test Plan
cargo test --lib routed_experts,cargo fmt --check.GPU validation with router v0.2.3 (2026-10-14)
1x 8xH200, vLLM 0.31.0, Qwen3-30B-A3B TP1,
VLLM_BATCH_INVARIANT=1, router replay + sampling masks. prime-rl = PrimeIntellect-ai/prime-rl#3830 (978146cf5) merged with PrimeIntellect-ai/prime-rl#3900 (20a322525); router =release/v0.2.3(ff818da, this PR + the version bump), wheel built locally. 1P1D (NIXL) through the router vs a colocated server. Identical means: same tokens, same routing rows for prompt and completion (100%, rows = prompt + completion - 1, mergedstart= 0), same sampling masks, same logprobs.cache_salton the colocated side: 20/20 identical.sitecustomizeforced vLLM's capturer touint16on P, D and the colocated server. The responses carrydtype: uint16. Concurrency 1: 10/10 identical; concurrency 10: 20/20 identical.num_gpu_blocks_override=1300, 1000-4000 token prompts, up to 1024 tokens, concurrency 10): 6 preemptions on D, 20/20 identical.Using V2 Model Runner, noBlockObjectStoreError.decode routed_experts has 128 rows, expected at least <prompt_len>). The 2 prompts of 64 tokens return 128 rows instead of 191, and the completion rows are wrong.Note
Honor
routed_expertsdtype in inline merge row slicing and concatdtypefield (uint8 or uint16) to routed-experts payloads, used to compute row byte widths inrow_bytes,suffix_rows, andconcat_rowsin routed_experts_merge.rsdtypeor with a data length not matching itemsize × shape, so existing uint8-only payloads must includedtypeMacroscope summarized 09aebbc.
Note
Medium Risk
Changes P/D response stitching for routed_experts with stricter dtype and row-range validation; wrong overlap logic would corrupt routing metadata for replay.
Overview
Fixes inline routed_experts merge for P/D replay when expert IDs use
uint16(models with >256 experts). Payloads now require adtype(uint8oruint16); byte length checks and row slicing useitemsize × layers × topk, and merged JSON preservesdtype.Merge no longer always drops the first
prefill.seq_lendecode rows. It strips only rows already covered by prefill usingprompt.end() - decode.start, andconcat_rowserrors on dtype mismatch or a gap between prefill end and decodestart(so decode can start at first-forward without zero-padding).Tests cover padded
uint8merge,uint16merge with non-zerostart, and overflow/invalid metadata rejection.Reviewed by Cursor Bugbot for commit 09aebbc. Bugbot is set up for automated code reviews on this repo. Configure here.