Repository navigation
fix(kv-router): fold SGLang wide image pad token ids in KV events - #17046
KrishnanPrash wants to merge 1 commit into
Conversation
Signed-off-by: Krishnan Prashanth <kprashanth@nvidia.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe change accepts 64-bit token IDs in the ZMQ wire types and folds IDs larger than ChangesToken ID normalization
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to
|
| Check name | Status | Explanation |
|---|---|---|
| Description check | The description explains the problem, implementation, validation results, and related issue. It does not include a separate “Where should the reviewer start?” section, and DIS-3202 is not written as a… | |
| Title check | The title clearly and concisely describes the main change: folding wide SGLang image pad token IDs in KV events. | |
| Docstring Coverage | Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 4 files. | |
| Linked Issues check | Check skipped because no linked issues were found for this pull request. | |
| Out of Scope Changes check | Check skipped because no linked issues were found for this pull request. |
Full details: Description check
-
Explanation
The description explains the problem, implementation, validation results, and related issue. It does not include a separate “Where should the reviewer start?” section, and DIS-3202 is not written as an explicit issue reference, but the description is otherwise complete and relevant.
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
| fn normalize_token_ids(token_ids: KvTokenIds) -> (Vec<u32>, bool) { | ||
| match token_ids { | ||
| KvTokenIds::Single(tids) => (tids, false), | ||
| KvTokenIds::Single(tids) => (tids.into_iter().map(fold_token_id).collect(), false), |
There was a problem hiding this comment.
This removes the zero-copy path for every ordinary single-form KV event: deserialization now first allocates a Vec<u64>, then this collect() allocates and copies a second Vec<u32>. All live and replayed ZMQ BlockStored batches pass through here, so vLLM, TensorRT-LLM, mocker, and text-only SGLang traffic pay the extra per-event allocation even when every ID fits in u32. Keep a direct u32 decoding path and use folding only for inputs that actually contain wide IDs (for example with a custom visitor or separate untagged wide variants).
🤖 AI Fix
Deserialize fitting token IDs directly into the final Vec<u32> and allocate a folded replacement only for token sequences that contain values above u32::MAX.
| ); | ||
| } | ||
|
|
||
| #[test] |
There was a problem hiding this comment.
This test duplicates pass-through coverage already retained by test_decode_batch_folds_sglang_wide_pad_token_ids: that test exercises the same batch decoder with ordinary single-form IDs, u32::MAX, and an ordinary bigram element while also detecting the wide-ID regression. The existing test_deserialize_bigram_block_stored_sequence additionally preserves an all-u32 bigram. The extra values here traverse no distinct normalization boundary; the supported behavior remains fully protected without this case.
🤖 AI Fix
Remove test_decode_batch_keeps_u32_token_ids and retain the wide-pad and existing bigram tests.
✅ Dynamo PR CI passed — run 39679335695 (attempt 1) on
|
|
Closing in favor of the DEP #17044 work in #17126, #17082 and sgl-project/sglang#45737. |
Summary
SGLang main writes four image pad tokens of about 62 bits for each image (sgl-project/sglang#43043). Dynamo reads KV-event token ids as u32, so one wide id fails the whole event batch, and the router also loses the text blocks in that batch. This change reads event token ids as u64 and folds each id above u32 into the existing image pad range,
1_000_000 + (id & (2^30 - 1)). Ids that fit in u32 pass through unchanged, so block hashes for vLLM, TensorRT-LLM and the mocker keep their exact bytes. Repeated images still miss until the request side writes the same pads, which the next PR in this stack does.Tokenis u32 in every block hash, in KVBM and in the mocker, so a widerTokenwould change the hashes of every engine to fix one.normalize_token_ids, so the fold sits there and no code after it changes.fold_token_idsits next topad_value_for_mm_hash, so the request side can fold with the same function.Validation
Two SGLang workers (Qwen3-VL-2B) behind the KV router on SGLang main
5e79333c95, same client script before and after:The new wire tests decode an SGLang-shaped batch with wide pads, ids on both sides of the u32 boundary, a text event and a bigram event. On main they fail with
data did not match any variant of untagged enum KvTokenIds. kv-router: 1107 passed. mocker: 272 passed. dynamo-llm kv_router: 441 passed.Related Issues
Summary by CodeRabbit