Repository navigation
feat(mesh): decode least_load by url@rank - #3509
MengqingCao wants to merge 11 commits into
Conversation
Each worker now carries a prefill-token counter next to its request count:
the prompt tokens placed on it whose prefill has not finished, exported as
mesh_worker_prefill_tokens{worker}. DP-aware workers keep one per rank.
The planner charges the prompt's tokens, when the router has them, to the
worker that prefills it, and the load guard holds the charge until the
prefill is done:
- P/D: on the prefill worker's guard, released when the prefill response
completes. Under idx2idx it follows the remapped prefill rank; the idx2idx
reservation test carries a nonzero charge and checks where it lands.
- Regular HTTP, streaming: until the response's first frame.
- Regular HTTP, non-streaming: not charged, since its first frame arrives
only after decoding.
ext-proc single-worker and gRPC placements do not charge yet. A release
larger than the charge saturates at zero and logs a warning.
Ported from #3210 with its review addressed: non-streaming requests are not
charged, with a test, and the charge lives on WorkerLoadGuard rather than a
public PrefillTokenGuard.
Co-authored-by: Jasen2201 <yajizhan@amd.com>
- The cancel and stalled error-body P/D tests check the prefill charge is taken and released, not only the request load. - WorkerLoadGuard::with_prefill_tokens debug-asserts a fresh guard instead of releasing a charge no caller has. - The mesh_worker_prefill_tokens help names the paths that charge it. Co-authored-by: Cursor <cursoragent@cursor.com>
The request weight was a hardcoded copy of ATOM_DP_LB_REQ_EQUIV. AgenticCost now carries it as request_token_equivalent (default 512); keep it equal to the engine's ATOM_DP_LB_REQ_EQUIV, which its least_tokens DP balancer uses for the same weight. The cost stays integer.
`--prefill-policy agentic` (or `--policy agentic` in regular mode) places each request on the worker (url@rank) with the lowest AgenticCost: - cached_tokens: the KV event index's GPU-tier hits; PolicyRegistry hands the index to agentic as it does to cache_aware. A request the index cannot match (no tokens, media, or no candidate's events indexed) falls back to a text tree of past placements, which credits the worker with the longest match its bytes / 4. The tree shares --eviction-interval and --max-tree-size with cache_aware. - prompt_tokens: the tokens, or the text's bytes / 4 without them, so these requests are charged too. - inflight_prefill_tokens and inflight_requests: the worker's counters. The selected worker's uncached tokens go back to the planner as RouteDecision::prefill_tokens, the charge it records. For a request the index can match, agentic calls on_routed on the selected worker and reports estimated_hit_ratio, so its placements join the KV events predictions and reconciliation. Branches: hit, relocate and miss by the index; text_hit, text_relocate and text_miss by the tree; unmatched. Configuration rejects agentic for the decode pool, including --policy agentic in P/D mode without --decode-policy: decode carries no prefill charge, so long sessions would stay pinned to one decode. --agentic-request-token-equivalent (512) sets the request weight. The module is private, re-exported like the other policies. agentic_cost.md documents the policy, its inputs and its limits; the README and metrics.md list it and its branches. The CI step also runs the placement, proxy body, factory, CLI and config tests.
The registry removed a departed worker only from cache_aware trees, so it stayed a tenant of agentic's text tree: its sessions' next text-placed turn still matched it, every candidate scored no hit, and its text stayed in memory. remove_worker_from_cache_aware now forgets the worker in agentic's trees as well; a matched tenant missing from the candidates is still kept, since under idx2idx it may be alive on another rank. Also: - max_tree_size caps each worker's text, not the tree; the doc says so. - The CI step is back to running policies::agentic only: the first step already runs every --lib test. - The planner test of a policy's prefill estimate uses AgenticPolicy instead of a stub policy.
Co-authored-by: Cursor <cursoragent@cursor.com>
A decode still in prefill or waiting on KV transfer has to count toward url@rank load, or the next choice cannot see it. Failed load samples stay out of the power_of_two cache, and the two DPA acceptance cases select agentic prefill with least_load decode. Co-authored-by: Cursor <cursoragent@cursor.com>
valar-cop
left a comment
There was a problem hiding this comment.
a few small things..
MI355X DPA decode and MI455X DP4 regression results? both unchecked in test plan.
ci green.
| long, | ||
| default_value = "cache_aware", | ||
| value_parser = ["random", "round_robin", "dp_sticky", "cache_aware", "power_of_two", "prefix_hash", "agentic"], | ||
| value_parser = ["random", "round_robin", "dp_sticky", "cache_aware", "power_of_two", "prefix_hash", "agentic", "least_load"], |
There was a problem hiding this comment.
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.
Rejected in validation. least_load is 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_load with another prefill policy still passes. 6d9fb853c
|
|
||
| /// Take over a reservation made at selection. Does not charge again. | ||
| pub fn adopt(reservation: LoadReservation) -> Self { | ||
| let (worker, tokens) = reservation.defuse(); |
There was a problem hiding this comment.
max_completion_tokens matches the key anywhere in a chunk, content can inflate the reservation. scope it to usage frames? also missing tests for adopt/observe_output_chunk..
There was a problem hiding this comment.
Usage is read from the SSE event JSON (usage, meta_info, or nested response/message usage). Generated content and completion_tokens_details no longer match. Split frames are reassembled before parse. adopt and observe_output_chunk are covered: the selection charge is not incremented again, content does not add tokens, a cumulative usage value adds the delta once, and drop releases prompt plus generated tokens. 6d9fb853c
|
|
||
| /// Lowest outstanding decode cost at `url@rank`: reserved KV tokens plus | ||
| /// one request-equivalent per in-flight request. | ||
| #[serde(rename = "least_load")] |
There was a problem hiding this comment.
new user-facing policy, but no least_load row in the README load balancing table? please add it and note it's for PD decode.
There was a problem hiding this comment.
Added a least_load row to the mesh README load-balancing table, and noted it is PD decode only. 6d9fb853c
7574c4c to
f37dd63
Compare
f37dd63 to
b15bc6f
Compare
A regular router dropped the selection reservation, so least_load there only saw the in-flight count. Reject that configuration. Completion tokens now come from the SSE usage object, so generated text cannot inflate the reservation. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Addressed the three code notes in MI355X DPA decode and MI455X DP4 regression are still unchecked. Those GPU runs have not been started, so the test plan stays open for them. |
|
@valar-cop thanks, all three notes are addressed in `6d9fb853c`, each with a reply in its thread:
The MI355X DPA decode and MI455X DP4 regression items are still open and not run yet. |
|
@MengqingCao checked 6d9fb85, all three are in: fine by me on those. holding the lgtm until the MI355X DPA decode and MI455X DP4 runs are back. |
|
Splitting this PR into the three functional pieces, stacked on #3406:
Closing this combined PR so review continues on those three. |
Summary
least_load. Its cost is the KV reserved on thaturl@rankplus 512 tokens per in-flight request, the same request weight asagenticand the engine'sATOM_DP_LB_REQ_EQUIV. The reservation is taken inside the selection, before the lock is released, so a request still in prefill or waiting on decode is visible to the next choice. Equal cost keeps the lower index. If any candidate has a reservation without a token count, the whole choice uses in-flight requests only.completion_tokensdelta until the body is dropped. The prefill token counter from feat(mesh): count in-flight prefill tokens per worker (url@rank) #3481 is a separate ledger and is not reused. Decode-first selection stays in feat(mesh): under idx2idx, select decode first and prefill on its rank #3493.atom:dp_inflight_requests{rank}from/metrics; other backends still use/get_load, and only for workers that are not DP ranks. A failed sample is left out of thepower_of_twocache, whileGET /get_loadsstill reports-1. The sample interval follows the smallestpower_of_two.load_check_interval_secs.router.prefill_policyandrouter.decode_policythrough.minimax-m3-fp4-2p1d-dpa-tp4and the DSv4-0813 agentic DPA anchor selectagenticprefill andleast_loaddecode. Dropping those two keys restoresdp_stickyorcache_aware. MI455 DP4 is unchanged, and the global policy default staysrandom.Test plan
cargo test --offline --locked --lib -- least_load worker_manager::tests factory::tests(15 passed)cargo test --offline --locked --lib -- placement::(132 passed)cargo test --offline --locked --lib -- load_tests(20 passed)cargo test --offline --locked --lib -- http_pd_router::tests(25 passed)minimax-m3-fp4-2p1d-dpa-tp4and DSv4-0813 1P1D DPA. P90 ITL should move beyond run noise; throughput and P90 TTFT should not worsen; 0 failed; GSM8K should not worsen.Made with Cursor