Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c058fc9
mesh: weigh Mooncake Store hits in cache_aware, on main
wanzhenchn Nov 20, 2026
6f2bb8b
feat(mesh): count prefixes a rank copies in from its UMBP share group
wanzhenchn Nov 20, 2026
0243184
mesh: test kv_affinity placement against a store that holds nothing, …
wanzhenchn Nov 20, 2026
4c4000c
Merge remote-tracking branch 'origin/zwan/mesh-kvev-m5-lookup' into z…
wanzhenchn Nov 20, 2026
f8cc40b
mesh: ask every rank's keys of a store with several pools, and no sto…
wanzhenchn Nov 20, 2026
9a87969
perf(mesh): leave share groups out of a request until two followed ra…
wanzhenchn Nov 20, 2026
4a3cb94
mesh: give the long-prompt lookup test a deadline a loaded machine meets
wanzhenchn Nov 20, 2026
274fbb5
Merge remote-tracking branch 'origin/zwan/mesh-kvev-m5-lookup' into z…
wanzhenchn Nov 20, 2026
159d249
mesh: test what the Store lookup takes from the CLI, and the prompts …
wanzhenchn Nov 21, 2026
52184cb
mesh: test that --kv-share-weight reaches the KV event monitor
wanzhenchn Nov 21, 2026
4b820cc
Merge remote-tracking branch 'origin/zwan/mesh-kvev-m5-lookup' into z…
wanzhenchn Nov 21, 2026
0615f09
mesh: share groups for ranks that keep some blocks private
wanzhenchn Nov 21, 2026
f0a23b2
Merge remote-tracking branch 'origin/main' into zwan/mesh-kvev-m5-loo…
wanzhenchn Nov 23, 2026
e664ebb
Merge remote-tracking branch 'origin/main' into zwan/mesh-kvev-m5-loo…
wanzhenchn Nov 23, 2026
f900792
Merge remote-tracking branch 'origin/main' into zwan/mesh-kvev-m5-lookup
wanzhenchn Nov 25, 2026
38d885f
Merge branch 'zwan/mesh-kvev-m5-lookup' into zwan/mesh-umbp-share-groups
wanzhenchn Nov 25, 2026
c455406
kv_events: a rank reports the umbp_pool it shares, for the router's s…
wanzhenchn Nov 25, 2026
aad5e5b
kv_events: a rank reports the blocks it copies in from its share group
wanzhenchn Nov 25, 2026
1a83eb4
Merge branch 'main' into zwan/mesh-umbp-share-groups
wanzhenchn Nov 27, 2026
6ed88f6
Merge main (c6bfb0ad2) into zwan/mesh-umbp-share-groups
wanzhenchn Nov 27, 2026
a189371
mesh: a TierWeights in each cache-aware policy's config, filled by th…
wanzhenchn Nov 27, 2026
e2e0b8d
refactor(mesh): one TieredHit per worker from the KV event index, sco…
wanzhenchn Nov 27, 2026
ea180db
refactor(mesh): one TieredHit per worker from the KV event index, sco…
wanzhenchn Nov 27, 2026
aaeb8e6
feat(mesh): count prefixes a DP rank copies in from its UMBP share group
wanzhenchn Nov 27, 2026
5253a94
Merge the two-PR stack: this PR keeps the use in routing, on #3946
wanzhenchn Nov 27, 2026
8c0896e
Merge #3946 at 26cc0bd53 (zwan/mesh-umbp-share-lanes) into this PR
wanzhenchn Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions atom/kv_transfer/pool/umbp/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,11 @@ def fetch_async(
def fetch_pending(self, owner: Hashable) -> bool:
return owner in self._fetches

def poll_fetches(self) -> None:
def poll_fetches(self) -> list[tuple[Hashable, list[int]]]:
"""Index what finished copies brought in; release the rest."""
if not self._fetches:
return
return []
finished = []
done = [o for o, entry in self._fetches.items() if entry[0].done()]
for owner in done:
future, ids, hashes, tokens_of, started, generation = self._fetches.pop(
Expand All @@ -539,17 +540,18 @@ def poll_fetches(self) -> None:
# Content from before a clear is not indexed again.
landed = len(slots) if generation == self._clear_generation else 0
index = self._hash_to_block_id
published = 0
indexed = []
for i, block_id in enumerate(ids):
h = hashes[i]
# Computed here meanwhile: keep that copy, drop this one.
if i < landed and h not in index:
self.publish(block_id, h, tokens_of(i))
published += 1
indexed.append(i)
self.free(block_id)
if published:
if indexed:
# A memoised walk stops at a miss it rereads; make it reread.
self.index_version += 1
finished.append((owner, indexed))
elapsed = time.perf_counter() - started
self.blocks_fetched += copied
self.bytes_fetched += copied_bytes
Expand All @@ -564,6 +566,7 @@ def poll_fetches(self) -> None:
copied_bytes / (1 << 20),
elapsed * 1e3,
)
return finished

def _fetch_executor(self):
if self._executor is None:
Expand Down Expand Up @@ -1153,8 +1156,8 @@ def fetch_async(self, owner: Hashable, hashes, tokens_of) -> bool:
def fetch_pending(self, owner: Hashable) -> bool:
return self.umbp.fetch_pending(owner)

def poll_fetches(self) -> None:
self.umbp.poll_fetches()
def poll_fetches(self) -> list[tuple[Hashable, list[int]]]:
return self.umbp.poll_fetches()

def flush(self) -> None:
self.umbp.flush()
Expand Down
44 changes: 44 additions & 0 deletions atom/kv_transfer/pool/umbp/report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# SPDX-License-Identifier: MIT
# Copyright (C) 2026, Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2026 ATOM Project Contributors

"""The shared device pool as the Atomesh router reads it (`/kv_event_sources`).

From the report of each rank the router finds its share group: the ranks of one
node whose pools are in one group of one UMBP server copy the prefix they miss
from each other's pools before they compute it, so a rank is scored by what its
group holds, not by its own blocks alone.
"""

from __future__ import annotations

from typing import Any

from atom.kv_transfer.disaggregation.factory import KVConnectorFactory
from atom.kv_transfer.pool.umbp.settings import UmbpPoolSettings


def kv_pool_report(config: Any) -> dict[str, Any] | None:
"""The report of the `umbp_pool` connector `config` runs, on its own view
of `config` (a `multi` entry's); None without one."""
for name, leaf in KVConnectorFactory.leaf_connectors(config) or ():
if name == "umbp_pool":
return _umbp_pool_report(leaf)
return None


def _umbp_pool_report(config: Any) -> dict[str, Any]:
# `pool` imports the block pools it builds on: only a server that runs the
# connector loads it.
from atom.kv_transfer.pool.umbp.pool import share_group_for

settings = UmbpPoolSettings.from_transfer_config(config.kv_transfer_config)
return {
"backend": "umbp_pool",
"address": settings.address,
# As each rank's pool derives it when the setting is empty: engines
# started alike on one server report one group.
"group": share_group_for(config, settings),
"share_ratio": settings.share_ratio,
"fetch": settings.fetch,
}
2 changes: 1 addition & 1 deletion atom/mesh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ Supported tool parsers: `json`, `python`, `xml`.
|--------|-------------|
| `random` | Uniform random selection |
| `round_robin` | Sequential rotation with atomic counters |
| `cache_aware` | Prefix-tree matching for cache reuse, with configurable balance thresholds; with `--kv-events`, a request the router can tokenize goes by the blocks each worker's device cache holds, and with `--kv-storage-weight` by what its engine will load from the Mooncake Store it reads, at that weight per token, once one holds more of it than `cache_threshold`. Requests with media, imbalanced load and workers without indexed events stay on the tree |
| `cache_aware` | Prefix-tree matching for cache reuse, with configurable balance thresholds; with `--kv-events`, a request the router can tokenize goes by the blocks each worker's device cache holds, by what its engine will copy in from the device pools of its share group (ATOM's `umbp_pool`) at `--kv-share-weight` (0.9) per token, and with `--kv-storage-weight` by what its engine will load from the Mooncake Store it reads, at that weight per token, once one holds more of it than `cache_threshold`. Requests with media, imbalanced load and workers without indexed events stay on the tree |
| `power_of_two` | Chooses the lighter of two randomly sampled workers |
| `prefix_hash` | Consistent prefix hashing |

Expand Down
14 changes: 9 additions & 5 deletions atom/mesh/docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ Defaults are the CLI defaults.
| | `relocate` | That ratio is at or below the threshold: the least-loaded worker, ties broken at random. Workers outside the candidates keep their matches in the tree. | ratio |
| | `imbalanced` | The max minus min load exceeds `--balance-abs-threshold` (64) and the max exceeds `--balance-rel-threshold` (1.5) times the min: the least-loaded worker, without a tree lookup. | |
| | `no_tree` | No tree for the model and pool: a random healthy worker. | |
| | `kv_affinity` | With `--kv-events`: the worker whose device cache holds the largest share of the prompt, above the threshold, then the least loaded. | ratio |
| | `kv_shared` | The same, where that worker's share counts what its engine will copy in from the device pools of its share group, at `--kv-share-weight` (0.9) per token. | ratio |
| `prefix_hash` | `ring_hit` | The hash ring owner of the first `--prefix-token-count` (256) tokens, when its load is at most `--prefix-hash-load-factor` (1.25) times the average load including this request. | |
| | `load_balance_walk` | The owner is over that bound: the least-loaded worker within it, or the owner if none is. | |
| | `fallback_least_load` | No ring, or the owner is not healthy: the least-loaded worker. | |
Expand Down Expand Up @@ -215,10 +217,11 @@ match ratio only when it picked the worker holding the best match, which covers
every `affinity` decision and any `relocate` that happened to pick it. With
`--kv-events`, its `kv_affinity` decisions estimate the selection from the KV
event index, short of the block of the prompt's last token, which the engine
always computes. With `--kv-storage-weight`, they add what the engine will load
from the Mooncake Store the worker reads, by ATOM's load rule. When that store
does not answer, the match rate counts the device cache alone and the decision
has no estimate. The
always computes. `kv_shared` decisions add what the engine will copy in from
the device pools of its share group, which it reports cached as well. With
`--kv-storage-weight`, they add what the engine will load from the Mooncake
Store the worker reads, by ATOM's load rule. When that store does not answer,
the match rate leaves the store out and the decision has no estimate. The
router drops the estimate when it sends the prompt to a different worker than
the policy chose, because DP ranks keep separate KV caches; under
`--atom-pd-rank-mapping-policy idx2idx` that takes a health or membership change
Expand All @@ -231,7 +234,8 @@ while the engine counts tokens in blocks, and the tree does not see engine
eviction, chat templates or KV offload. `kv_affinity` counts tokens: the
blocks the index matches, short of the last token's block, and with
`--kv-storage-weight` what the engine will load from the store, over the
prompt's tokens. It differs where the index is not the engine's cache at that
prompt's tokens; `kv_shared` also counts what the engine will copy in from its
share group. It differs where the index is not the engine's cache at that
moment: batches not applied yet, blocks evicted since, and predictions for a
worker without exact events. A positive error means the router overestimated; a
negative one means the engine reused more than predicted.
Expand Down
1 change: 1 addition & 0 deletions atom/mesh/src/app_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ impl AppContextBuilder {
if let Some(storage) = &kv_storage {
monitor.read_stores(storage.clone(), router_config.kv_storage_weight);
}
monitor.share_pools(router_config.kv_share_weight);
policy_registry.set_kv_events(monitor.clone());
}
let tokenize_limits = TokenizeLimits::new(&router_config);
Expand Down
25 changes: 25 additions & 0 deletions atom/mesh/src/cliargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ pub struct CliArgs {
#[arg(long, default_value_t = 0.0, value_parser = parse_fraction, help_heading = "Routing Policy")]
pub kv_storage_weight: f64,

/// With --kv-events, what a token a worker's engine will copy in from the device pool of
/// another rank of its share group (ATOM's umbp_pool) counts for in cache_aware's match
/// rate (0 to 1), against one its own device cache holds; 0 ignores share groups
#[arg(long, default_value_t = 0.9, value_parser = parse_fraction, help_heading = "Routing Policy")]
pub kv_share_weight: f64,

// ==================== PD Disaggregation ====================
/// Enable PD (Prefill-Decode) disaggregated mode
#[arg(long, default_value_t = false, help_heading = "PD Disaggregation")]
Expand Down Expand Up @@ -722,6 +728,7 @@ impl CliArgs {
.mooncake_admin_port(self.mooncake_admin_port)
.kv_storage_deadline_ms(self.kv_storage_deadline_ms)
.kv_storage_weight(self.kv_storage_weight)
.kv_share_weight(self.kv_share_weight)
.retries(!self.disable_retries)
.circuit_breaker(!self.disable_circuit_breaker)
.build()
Expand Down Expand Up @@ -858,6 +865,23 @@ mod tests {
}
}

#[tokio::test]
async fn cli_kv_share_weight_reaches_the_kv_event_monitor() {
use crate::{
app_context::AppContext, core::prepare_pool::PreparePoolRuntime,
kv_index::PrefixMatchProvider,
};

let args = CliArgs::try_parse_from(["atomesh", "--kv-events", "--kv-share-weight", "0.5"])
.unwrap();
let config = args.to_router_config(Vec::new()).unwrap();
let runtime = PreparePoolRuntime::new(config.resolved_prepare_pool().unwrap()).unwrap();
let context = AppContext::from_config(config, 5, runtime.handle())
.await
.unwrap();
assert_eq!(context.kv_event_monitor.unwrap().share_weight(), 0.5);
}

#[test]
fn cli_kv_storage_options_map_to_router_config() {
let args = CliArgs::try_parse_from([
Expand Down Expand Up @@ -1007,6 +1031,7 @@ impl Default for CliArgs {
mooncake_admin_port: 9003,
kv_storage_deadline_ms: 3,
kv_storage_weight: 0.0,
kv_share_weight: 0.9,
pd_disaggregation: false,
decode: Vec::new(),
prefill_policy: None,
Expand Down
5 changes: 5 additions & 0 deletions atom/mesh/src/config/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ impl RouterConfigBuilder {
self
}

pub fn kv_share_weight(mut self, weight: f64) -> Self {
self.config.kv_share_weight = weight;
self
}

/// Inverse of disable_retries field
pub fn retries(mut self, enable: bool) -> Self {
self.config.disable_retries = !enable;
Expand Down
9 changes: 9 additions & 0 deletions atom/mesh/src/config/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ pub struct RouterConfig {
/// device; 0 asks no store.
#[serde(default)]
pub kv_storage_weight: f64,
/// What a token a worker copies in from its share group counts for in routing, against
/// one on its device; 0 ignores share groups.
#[serde(default = "default_kv_share_weight")]
pub kv_share_weight: f64,
pub api_key: Option<String>,
pub metrics: Option<MetricsConfig>,
pub log_dir: Option<String>,
Expand Down Expand Up @@ -515,6 +519,10 @@ fn default_kv_storage_deadline_ms() -> u64 {
3
}

fn default_kv_share_weight() -> f64 {
0.9
}

impl Default for RouterConfig {
fn default() -> Self {
Self {
Expand All @@ -538,6 +546,7 @@ impl Default for RouterConfig {
mooncake_admin_port: default_mooncake_admin_port(),
kv_storage_deadline_ms: default_kv_storage_deadline_ms(),
kv_storage_weight: 0.0,
kv_share_weight: default_kv_share_weight(),
api_key: None,
metrics: None,
log_dir: None,
Expand Down
23 changes: 17 additions & 6 deletions atom/mesh/src/config/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,17 @@ impl ConfigValidator {
});
}

if !(0.0..=1.0).contains(&config.kv_storage_weight) {
return Err(ConfigError::InvalidValue {
field: "kv_storage_weight".to_string(),
value: config.kv_storage_weight.to_string(),
reason: "Must be between 0 and 1".to_string(),
});
for (field, weight) in [
("kv_storage_weight", config.kv_storage_weight),
("kv_share_weight", config.kv_share_weight),
] {
if !(0.0..=1.0).contains(&weight) {
return Err(ConfigError::InvalidValue {
field: field.to_string(),
value: weight.to_string(),
reason: "Must be between 0 and 1".to_string(),
});
}
}

Ok(())
Expand Down Expand Up @@ -474,6 +479,12 @@ mod tests {
};
let error = config.validate().unwrap_err();
assert!(error.to_string().contains("kv_storage_weight"), "{error}");
let config = RouterConfig {
kv_share_weight: weight,
..Default::default()
};
let error = config.validate().unwrap_err();
assert!(error.to_string().contains("kv_share_weight"), "{error}");
}
}

Expand Down
Loading
Loading