kv tiers: rad_kv_group_replicated -- a group every rank holds whole is kept once a host slot

Under tensor parallelism a host slot held every rank's shard of an entry end to end, so a
group every rank holds whole (an MLA latent cache computed from a replicated projection) was
stored once a rank: on GLM-5.3-Flash at eight ranks 396.75 KiB a 4-token block for 49.59 KiB
of distinct bytes. The plugin now says which paged groups are replicated (additive export,
RAD_ABI_VERSION does not move), and the slot holds those once, in one window at its front
that rank 0 writes and every rank reads back on a restore; the sharded groups follow, one
window a rank, as before. Without the declaration nothing changes.

TierExec::slot_layout is the one place the slot arithmetic lives: bringup takes the windows
from it, and it refuses a group replicated on one rank but zero, unflagged or another width
on another. A follower moves only its own window on a copy out (nothing, when every cached
group is replicated) and both windows on a restore. The startup log names what is held once
and the tokens the tier holds either way.

RADIANCE_DEBUG_TIER_VERIFY now covers the claim: each follower gathers the replicated groups
into a pinned scratch beside the copy and hashes them once landed, and the engine, once every
rank has landed, has the leader compare its window with every follower's sum.

mem_test moves a chain through the real TierExec with a replicated and a sharded group at 1,
2 and 8 ranks, the ranks' copies differing on purpose, and checks every rank gets the leader's
bytes back; beside a zero group; the verify path alike and differing; and the layout's refusal.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
NunzeandClaude Fable 5.1 committed 2026-10-22 09:08:44 +00:00
1 parent 17d004d0d0
commit 66a1d5aa15
15 files changed
+490 -87

No files matched your search

+25 -15
View File
@@ -3050,21 +3050,17 @@ int Engine::configure_kv() {
{
const bool tier_asked = cfg_.prefix_cache_mib > 0;
const std::vector<int32_t>& cg = ranks_[0]->prefix.cached_groups();
/* One slot holds every rank's shard of an entry; each rank writes only its window. Shards
* can differ or be empty (uneven heads, rad_kv_group_zero), so a slot is the sum and each
* window starts where the previous ends. TierExec::sizes uses the largest rank's entry,
* since the staging ring is per rank. */
std::vector<int64_t> rank_entry(ranks_.size(), 0), entry_off(ranks_.size(), 0);
int64_t entry_bytes = 0, slot_bytes = 0;
for (size_t i = 0; i < ranks_.size(); ++i) {
for (int32_t g : cg) {
const KVGroupPlan* p = ranks_[i]->kv.plan(g);
if (p && p->paged()) rank_entry[i] += p->bytes_per_block;
}
entry_off[i] = slot_bytes;
slot_bytes += rank_entry[i];
entry_bytes = std::max(entry_bytes, rank_entry[i]);
}
/* One slot holds the whole engine's entry: the groups every rank holds alike
* (rad_kv_group_replicated) once, at the front, then every rank's own shard in its own
* window. Shards can differ or be empty (uneven heads, rad_kv_group_zero). The layout is
* TierExec's, so the arithmetic here and the copies agree; TierExec::sizes takes the
* largest rank's entry, since the staging ring is per rank. */
std::vector<const KVManager*> rank_kv;
for (auto& r : ranks_) rank_kv.push_back(&r->kv);
TierExec::SlotLayout layout;
RAD_TRY(TierExec::slot_layout(rank_kv, cg, &layout));
const std::vector<int64_t>& entry_off = layout.own_off;
const int64_t entry_bytes = layout.entry_bytes, slot_bytes = layout.slot_bytes;
/* Snapshots live in the checkpoint store (--checkpoint-slots); --prefix-cache-mib is for
* blocks only. */
@@ -3092,6 +3088,20 @@ int Engine::configure_kv() {
* fit is right after the turn. */
const int64_t held = T.arena().capacity() * tc.block_tokens;
const int64_t ctx = cfg_.max_ctx > 0 ? cfg_.max_ctx : meta_.n_ctx_train;
if (layout.rep_bytes > 0 && ranks_.size() > 1) {
/* What the slot would be with every rank's copy of the replicated groups. */
const int64_t each = slot_bytes + layout.rep_bytes * (int64_t)(ranks_.size() - 1);
std::string names;
for (const std::string& n : layout.replicated)
names += (names.empty() ? "" : ", ") + n;
RAD_INFO("kv tiers: %s (%s of each entry) is the same on every rank and held "
"once a slot: %s a slot rather than %s, so --prefix-cache-mib %lld "
"holds %lld tokens rather than %lld",
names.c_str(), humanb(layout.rep_bytes).c_str(),
humanb(slot_bytes).c_str(), humanb(each).c_str(),
(long long)cfg_.prefix_cache_mib, (long long)held,
(long long)(tc.host_cap_bytes / each * tc.block_tokens));
}
if (held < ctx)
RAD_WARN("kv tiers: --prefix-cache-mib %lld holds %lld tokens of context (%s "
"per %lld-token block), less than one --max-model-len %lld "