Repository navigation
perf(bindings): read SelectionService token_ids lists without iterator overhead - #17337
Conversation
…r overhead pyo3's generic Vec<u32> extraction walks the list through the sequence iterator and takes and drops a reference to every element, which costs more than converting the ints. Read a plain list of ints by index with borrowed items, and fall back to the generic extraction for any other input so accepted values and errors are unchanged. On GB200 Grace with a 99k-token prompt, select_and_reserve CPU on the calling thread drops from 0.83 to 0.37 ms, and a Ray-style embedded ingress goes from 214.8 to 238.7 req/s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: jthomson04 <jwillthomson19@gmail.com>
|
/ok to test 1ff5678 |
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Token conversion and validation lib/bindings/python/rust/llm/kv.rs, lib/bindings/python/tests/test_kv_bindings.py |
depythonize_prompt_request attempts direct conversion for lists of exact integers that fit in u32. Other inputs use the existing generic extraction path. Tests cover tuple and boolean-containing inputs, and malformed token IDs that raise ValueError mentioning token_ids. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Merge Risk: 
Minimal · up to 1ff56
-
No merge-blocking issue is identified; the token-conversion change is ready for normal checks.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The pull request description includes all required sections: Overview, Details, reviewer starting point, and Related Issues. It identifies Relates to
#17238and provides clear implementation details, scope, safety considerations, benchmarks, and validation results.
-
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
A list subclass can override __iter__, which the generic conversion honors; reading its backing storage by index would select on different token ids. Restrict the borrowed-item read to exact lists, and fold it and the fallback into one extract_token_ids helper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: jthomson04 <jwillthomson19@gmail.com>
|
/ok to test 9c4b219 |
✅ Dynamo PR CI passed — run 40400231408 (attempt 1) on
|
Overview:
Every
SelectionServicecall that carries a prompt converts the wholetoken_idslist on the calling thread, under the GIL; in Ray Serve LLM'sKVAwareRouterthat isselect_and_reserveon every request. pyo3's genericVec<u32>extraction walks the list through the sequence iterator and takes and drops a reference to every element, which costs more than converting the ints. This PR reads a plainlistofints by index with borrowed items and falls back to the existing extraction for anything else.token_idsconversionselect_and_reservecall, CPU on the calling threadSetup:
KVAwareRouter/KVTokenTracker([serve][llm] Session pinning for KVAwareRouter ray-project/ray#67224) with 1,024 mocker workers publishing ZMQ KV events and 8,192 concurrent AgentX sessions (mean ISL 99k tokens).Details:
lib/bindings/python/rust/llm/kv.rs: what the fast path does.extract_token_idsreads an exactlistwithPyList_GetItem(borrowed) plusPyLong_AsUnsignedLongon exactints.booland objects with__index__), and on a value that is negative or aboveu32::MAX.listtakes the fast path. List subclasses (whose__iter__the generic conversion honors), tuples and other sequences use the existing conversion.extract::<Vec<u32>>()accepts the input or raises the sameValueErroras before.select,select_and_reserve,create_reservation,overlap_scoresandpotential_loads.Where should the reviewer start?
extract_token_idsinlib/bindings/python/rust/llm/kv.rs.Related Issues
Validation
cargo clippy --features select-service -- -D warningsinlib/bindings/pythonpytest lib/bindings/python/tests/test_kv_bindings.py -k selection_service: 16 passed. The select test also sends a tuple (generic path). The malformed-payload test covers negative, out-of-range and non-intids, and a list subclass whose iterator yields an invalid id (it fails without the exact-list check).🤖 Generated with Claude Code
Summary by CodeRabbit
ValueErroridentifyingtoken_ids.