Skip to content

[Bugfix] Content-aware routing should work with token ids - #237

Open
simondanielsson wants to merge 8 commits into
vllm-project:mainfrom
simondanielsson:bugfix/cache-aware-with-tokenids
Open

[Bugfix] Content-aware routing should work with token ids#237
simondanielsson wants to merge 8 commits into
vllm-project:mainfrom
simondanielsson:bugfix/cache-aware-with-tokenids

Conversation

@simondanielsson

@simondanielsson simondanielsson commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Purpose

For purposes of routing, previously token ids were (strangely) encoded as token_ids:{num_tokens}. For cache aware routing, that meant prompts of equal length were routed to the same vLLM instance. The actual content of the prompt was ignored.

This PR fixes this to by encoding the token ids and not just length of the prompt.

Extra care is taken so we only match on full tokens during cache aware routing, to avoid token 1234 is a partial match to token 12345 (because they are in fact distinct tokens and are unlikely prefixes when detokenized).

Test Plan

Tests pass

Test Result

OK

Related work

#242 unifies routing logic for PD and DP, so it will also get this benefit of correctly routing when token ids are passed.


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results

Signed-off-by: simondanielsson <simon.danielsson99@hotmail.com>
Signed-off-by: simondanielsson <simon.danielsson99@hotmail.com>
Signed-off-by: simondanielsson <simon.danielsson99@hotmail.com>
@simondanielsson

simondanielsson commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@simondanielsson simondanielsson changed the title fix: cache aware routing with token ids [Bugfix] Cache aware routing works with token ids Sep 7, 2026
@simondanielsson
simondanielsson marked this pull request as ready for review September 7, 2026 11:36

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 171ddf4532

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/protocols/spec.rs Outdated
Signed-off-by: simondanielsson <simon.danielsson99@hotmail.com>
Signed-off-by: simondanielsson <simon.danielsson99@hotmail.com>
Signed-off-by: simondanielsson <simon.danielsson99@hotmail.com>
@simondanielsson simondanielsson changed the title [Bugfix] Cache aware routing works with token ids [Bugfix] Routing works with token ids Sep 7, 2026
@simondanielsson simondanielsson changed the title [Bugfix] Routing works with token ids [Bugfix] Content-aware routing should work with token ids Sep 7, 2026
…with-tokenids

Signed-off-by: simondanielsson <simon.danielsson99@hotmail.com>
@simondanielsson

simondanielsson commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

@hsliuustc0106 @wuhang2014 could you please take a look? Thanks 🙏

Copilot AI 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.

🟡 Changes recommended

Token-key detection collides with valid text inputs, and one token-ID request path still uses character-based matching.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Updates cache-aware routing to use actual token IDs and count only complete-token prefix matches.

Changes:

  • Encodes token IDs with unit separators.
  • Adds token-aware cache match-rate calculation.
  • Updates routing-key and match-rate tests.
File summaries
File Description
src/protocols/spec.rs Encodes token-based prompts for routing.
src/policies/cache_aware.rs Calculates complete-token cache matches.
tests/test_prompt_input.rs Updates expected token routing keys.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 3
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/policies/cache_aware.rs Outdated
if input_char_count == 0 {
return 0.0;
}
if text.contains(TOKEN_ID_SEPARATOR) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, added a prefix token to discern between token ids and regular text

Comment thread src/protocols/spec.rs Outdated
Comment thread src/protocols/spec.rs Outdated
Signed-off-by: simondanielsson <simon.danielsson99@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants