Repository navigation
feat(mesh): decode least_load by url@rank #3509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
MengqingCao
wants to merge
11
commits into
mengqing/agentic-cost-weights
from
mengqing/mesh-decode-least-load
Closed
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5b3b2ea
feat(mesh): count in-flight prefill tokens per worker (url@rank)
MengqingCao 051d134
fix(mesh): assert the prefill release on P/D cancel and error paths
b80fe89
feat(mesh): isolate agentic prefill cost and worker selection
Jasen2201 65d267e
style(mesh): apply rustfmt to agentic cost module
Jasen2201 f8b453c
ci(mesh): run agentic cost tests in the router harness job
Jasen2201 0495a6d
feat(mesh): make the agentic cost's request weight configurable
MengqingCao c75b088
feat(mesh): agentic routing policy on the KV event index
MengqingCao 51ace86
fix(mesh): drop removed workers from agentic's text tree
MengqingCao 06211f9
docs(mesh): name the requests agentic does not charge
383e34f
feat(mesh): charge decode least_load when the request is selected
6d9fb85
fix(mesh): keep least_load on PD decode and read usage frames
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # Agentic routing | ||
|
|
||
| `agentic` places each request on the worker (`url@rank`) with the lowest | ||
| prefill cost, so a long multi-turn prompt stays where its KV lives until that | ||
| worker's queue costs more than prefilling the prompt elsewhere: | ||
|
|
||
| ```text | ||
| uncached_tokens = max(prompt_tokens - cached_tokens, 0) | ||
| cost = inflight_prefill_tokens + uncached_tokens | ||
| + request_token_equivalent * inflight_requests | ||
| ``` | ||
|
|
||
| The minimum cost wins, ties at random. A hit saves only the prefill it covers, | ||
| with no extra bonus, as in the engine's `least_tokens` DP balancer. | ||
|
|
||
| | Input | Source | | ||
| | --- | --- | | ||
| | `prompt_tokens` | The request's tokens (`--model-path` or `--tokenizer-path`, prompts up to `--prepare-max-tokenize-bytes`); without them, its text bytes / 4. | | ||
| | `cached_tokens` | The KV event index (`--kv-events`): the leading prompt tokens each worker's GPU cache holds. A request the index cannot match (no tokens, media, or no candidate's events indexed) uses a text tree of past placements: the worker with the longest text match is credited its bytes / 4. The tree shares `--eviction-interval` and `--max-tree-size` (a per-worker cap) with `cache_aware`. | | ||
| | `inflight_prefill_tokens` | Tokens charged to the worker whose prefill has not finished, `mesh_worker_prefill_tokens{worker}`. | | ||
| | `inflight_requests` | `mesh_worker_requests_active{worker}`. | | ||
| | `request_token_equivalent` | `--agentic-request-token-equivalent` (512). Keep it equal to the engine's `ATOM_DP_LB_REQ_EQUIV`. | | ||
|
|
||
| The selected worker is charged its `uncached_tokens`, released when its P/D | ||
| prefill response completes or at a streaming response's first frame. | ||
| Non-streaming regular, gRPC and ext-proc single-worker requests are not | ||
| charged, so their prefills weigh only through `inflight_requests`. Under | ||
| idx2idx the planner selects decode first, so `agentic` chooses among the | ||
| prefill workers on its rank. For a request the index can match, `agentic` | ||
| predicts the selected worker's blocks (`on_routed`) and reports an estimated | ||
| hit ratio, reconciled with the cached tokens the engine reports. | ||
|
|
||
| ## Branches | ||
|
|
||
| | Branch | Meaning | | ||
| | --- | --- | | ||
| | `hit`, `relocate`, `miss` | By the index: the selected worker holds the longest prefix; another worker holds a longer one but its queue outweighs the reuse; no candidate holds any. | | ||
| | `text_hit`, `text_relocate`, `text_miss` | The same, by the text tree. | | ||
| | `unmatched` | Neither tokens nor text. | | ||
|
|
||
| ## Requirements and limits | ||
|
|
||
| - Prefill and regular pools only: configuration rejects `agentic` for decode, | ||
| including `--policy agentic` in P/D mode without `--decode-policy`. | ||
| - DP engines need `--dp-aware` for their KV events to be followed. Messages and | ||
| Responses requests carry `data_parallel_rank` only with the `mesh.apis` label; | ||
| otherwise the engine picks a rank and the router charges `agentic`'s choice. | ||
| - Token routing wants `--prepare-max-tokenize-bytes` around 4 MiB and | ||
| `--tokenizer-cache-enable-l1`; longer prompts use the text tree. | ||
| - Not covered: cache tiers below the GPU (Mooncake Store, LMCache), atomic | ||
| selection and charge, and a session-owner layer. | ||
|
|
||
| ```sh | ||
| atomesh launch --pd-disaggregation --prefill http://p:8000 --decode http://d:8000 \ | ||
| --model-path <model> --kv-events --prepare-max-tokenize-bytes 4194304 \ | ||
| --tokenizer-cache-enable-l1 --prefill-policy agentic --decode-policy dp_sticky | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
least_load outside PD just degrades to in-flight load silently? either reject it in validation or carry the reservation through PlacementPlan::Single..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rejected in validation.
least_loadis PD decode only: a regular router, or a prefill policy that falls back to it, now fails config validation instead of dropping the selection reservation and keeping just the in-flight count.--decode-policy least_loadwith another prefill policy still passes.6d9fb853c