Skip to content

feat(router): add token-aware virtual model routing - #5375

Merged
qinxuye merged 8 commits into
xorbitsai:mainfrom
m199369309:feat/token-aware-router-v2
Aug 20, 2026
Merged

feat(router): add token-aware virtual model routing#5375
qinxuye merged 8 commits into
xorbitsai:mainfrom
m199369309:feat/token-aware-router-v2

Conversation

@m199369309

Copy link
Copy Markdown
Collaborator

Summary

  • add a native xinference-router data-plane process with process-isolated tokenization, admission control, typed first-match routing rules, and HTTP/SSE proxying
  • add V1 short/long compatibility plus V2 dynamic 1-16 backend configuration for the llm_chat route profile
  • add Supervisor-backed Router configuration/runtime registries, virtual model discovery, OpenAI chat dispatch, internal runtime registration, heartbeat, config polling, and acknowledgement APIs
  • protect existing deployments with the opt-in XINFERENCE_TOKEN_ROUTER_ENABLED feature gate (disabled by default)
  • add Router management scopes, audit coverage, API/runtime/configuration tests, and CLI packaging

Validation

  • focused Router suite: 98 passed
  • pre-commit run --files <modified files>

Follow-ups

Tokenizer asset management, bundled assets, Web UI, Agent orchestration, and monitoring are intentionally split into dependent PRs.

@XprobeBot XprobeBot added this to the v3.x milestone Aug 18, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces an independent, token-aware router for DeepSeek-V4 on Xinference, adding a persistent SQLite-backed configuration store, an in-memory runtime registry, and new REST endpoints for router management and internal runtime coordination. It also integrates a proxy layer into the restful API to route chat completions dynamically based on token budgets or typed rules. The review feedback highlights critical improvement opportunities: avoiding resource leaks on early stream disconnects by using Starlette's BackgroundTask instead of generator finally blocks, reusing a shared httpx.AsyncClient to prevent connection overhead, replacing a slow copy.deepcopy with a shallow copy during message normalization, and fixing a string concatenation typo ("t" "e").

Comment thread xinference/router/app.py
Comment thread xinference/api/restful_api.py Outdated
Comment thread xinference/api/restful_api.py Outdated
Comment thread xinference/router/tokenizer.py Outdated

@qinxuye qinxuye 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.

Found several blocking correctness and lifecycle issues in the current head.

Comment thread xinference/router/tokenizer.py
Comment thread xinference/api/restful_api.py
Comment thread xinference/router/tokenization_worker.py
Comment thread xinference/api/restful_api.py Outdated
Comment thread xinference/api/tests/test_token_router_audit.py

@qinxuye qinxuye 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.

LGTM

@m199369309
m199369309 force-pushed the feat/token-aware-router-v2 branch from 3cdc7ee to e27f701 Compare August 20, 2026 04:00
@qinxuye
qinxuye merged commit efbbfee into xorbitsai:main Aug 20, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants