kv: a rank's recurrent state is cleared and tiered by its own plan, not rank 0's

A freshly assigned recurrent slot was zeroed on every rank with rank 0's
layer_bytes_per_state. The ranks' shares of a group need not be equal --
a world the heads do not divide gives them different counts -- and a rank
holding more heads than rank 0 had the tail of its state left as the last
sequence left it, read by the recurrence from the first token. Every rank
now clears by its own plan. The host/disk tier made the same assumption
twice: a slot was rank 0's entry times the world and a rank's window sat
at rank times that; a slot is now the sum of the ranks' entries, each
rank's window where the ranks before it end, and the staging ring is
sized for the largest. Equal shares give the bytes they always gave.

Found by moving the extra delta-net head of Flash-Next at three ranks
onto the attention-zero rank: rank 0 held five heads, rank 2 six, and
every answer was noise.
This commit is contained in:
baKon authored and StillDeadcode committed 2026-10-06 11:23:06 +02:00
1 parent 017cf52218
commit 2d93182213
2 files changed
+35 -15

No files matched your search

+10 -5
View File
@@ -534,15 +534,20 @@ int Engine::step_loop() {
* recorded the grab and cannot do the write itself (StateClear in core/mem/kv.h); this is
* the first moment a stream exists and the last before the ranks are released, and it is
* off the hot path -- the list is empty on every step but a sequence's first. Every rank
* clears its own pool: the slot number is the scheduler's, the memory is the rank's. */
* clears its own pool BY ITS OWN PLAN: the slot number is the scheduler's, the memory and
* its size are the rank's. A state is as large as the heads this rank holds of the group,
* and the ranks' shares need not be equal (rad_arch.h remainder_place): a rank clearing
* rank 0's byte count of a larger state leaves its tail as the last sequence left it, and
* the recurrence reads it from the first token. */
for (const StateClear& c : ranks_[0]->kv.state_clears()) {
const KVGroupPlan* gp = ranks_[0]->kv.plan(c.group);
if (!gp || !gp->stateful()) continue;
const int64_t bytes = gp->layer_bytes_per_state();
for (auto& rk : ranks_)
for (auto& rk : ranks_) {
const KVGroupPlan* gp = rk->kv.plan(c.group);
if (!gp || !gp->stateful()) continue;
const int64_t bytes = gp->layer_bytes_per_state();
for (int64_t l = 0; l < gp->n_layers; ++l)
if (void* p = rk->kv.state_ptr(c.group, (int32_t)l, c.slot))
rad_memset_async(p, 0, bytes, rk->ctx.stream());
}
}
ranks_[0]->kv.clear_state_clears();