Skip to content

[serve][llm] Add metric for prompt tokenization bypass outcomes - #68055

Merged
jeffreywang88 merged 1 commit into
ray-project:masterfrom
jeffreywang88:serve-llm-skip-tokenization-metrics
Nov 19, 2026
Merged

jeffreywang88 merged 1 commit into
ray-project:masterfrom
jeffreywang88:serve-llm-skip-tokenization-metrics

Conversation

@jeffreywang88

Copy link
Copy Markdown
Contributor

Why are these changes needed?

When KVAwareRouter is enabled, LLMRouter tokenizes the prompt and sends the token IDs to the chosen LLMServer replica, so the engine can skip tokenization (#65095). This is best effort: if the tokens don't arrive in time, the engine tokenizes the prompt itself. Nothing currently measures how often the bypass works.

This PR adds the counter ray_serve_llm_tokenization_bypass_requests_total. Serve adds the application, deployment and replica tags, and an outcome tag says what happened:

outcome Recorded by Meaning
success LLMServer The engine used the forwarded tokens
send_failed LLMRouter The router couldn't send the tokens
miss LLMServer No staged tokens for the request (arrived late, expired, or evicted)
invalid LLMServer The staged tokens couldn't be decoded, or the list was empty

Implementation details

  • Each request that tries the bypass is counted exactly once, by either the router or the server that receives it. Every outcome except success falls back to engine tokenization. Requests the router never tries (multimodal requests, bodies it can't parse) aren't counted.
  • Each replica exports every outcome at 0 when it starts. Without this, a series only appears on its first event, and prometheus rate() drops everything recorded before that series' first scrape. That undercounts rare outcomes and new replicas. Counter.inc rejects 0, so this uses Counter._record(0, ...).

Example query

Share of skipping tokenization attempts that didn't apply, over 1h:

sum by (application) (rate(ray_serve_llm_tokenization_bypass_requests_total{outcome!="success"}[1h]))
/
sum by (application) (rate(ray_serve_llm_tokenization_bypass_requests_total[1h]))

Filter by application, not deployment, because send_failed comes from the router deployment and the other outcomes come from the server deployment.

🤖 Generated with Claude Code. I reviewed every line of code.

@jeffreywang88
jeffreywang88 requested a review from a team as a code owner November 11, 2026 04:41
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@jeffreywang88 jeffreywang88 added the go add ONLY when ready to merge, run all tests label Nov 11, 2026
@ray-gardener ray-gardener Bot added the serve Ray Serve Related Issue label Nov 11, 2026
@jeffreywang88

Copy link
Copy Markdown
Contributor Author

I don't think this deserves its own Grafana dashboard in OSS, but we should enable production alerts when tokenization bypass doesn't take effect too frequently.

@jeffreywang88
jeffreywang88 merged commit 051c9db into ray-project:master Nov 19, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants