Archived
kv: a group a rank keeps no cache for
rad_kv_group_zero(b, group): the group is declared as on every other rank -- the scheduler indexes groups by position and one block table serves every rank -- and this rank carves nothing for it: its block count is the shared table's, its costs are zero, its pool base is null, and issue refuses any op on this rank that names it. For a rank the geometry gives no attention heads, whose attention is a fill of zeros and never stores or reads a key. qwen4exp declares its attention group so on such a rank. The arch test's contract becomes the real one: same KV groups by position; ops are each rank's own.
This commit is contained in:
1 parent
7be92ec8f4
commit
3e629e7a27
9 files changed
+95
-18
No files matched your search
@@ -152,6 +152,7 @@ public:
|
||||
int weight_shard_span_parts(rad_weight w, const int64_t* lo, const int64_t* hi,
|
||||
const int64_t* total, int n);
|
||||
int weight_shard_zero(rad_weight w);
|
||||
int kv_group_zero(rad_kvgroup g);
|
||||
|
||||
/* Finalise: weight first/last use, KV group geometry, buffer liveness and packing. Returns
|
||||
* RAD_OK, or the first structural error class. Resolution MISSES are not an error here -- an
|
||||
|
||||
@@ -926,6 +926,13 @@ int Builder::weight_shard_span_parts(rad_weight h, const int64_t* lo, const int6
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
int Builder::kv_group_zero(rad_kvgroup h) {
|
||||
if (finished_) { err(RAD_E_STATE, "kv_group_zero after declare finished"); return RAD_E_STATE; }
|
||||
if (h == 0 || h >= prog_.kv_groups.size()) return RAD_E_INVAL;
|
||||
prog_.kv_groups[h].zero = true;
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
int Builder::weight_shard_zero(rad_weight h) {
|
||||
if (finished_) { err(RAD_E_STATE, "weight_shard_zero after declare finished"); return RAD_E_STATE; }
|
||||
if (h == 0 || h >= prog_.weights.size()) return RAD_E_INVAL;
|
||||
@@ -1673,6 +1680,11 @@ int rad_weight_shard_zero(RadBuilder* b, rad_weight w) {
|
||||
return B(b)->weight_shard_zero(w);
|
||||
}
|
||||
|
||||
int rad_kv_group_zero(RadBuilder* b, rad_kvgroup g) {
|
||||
if (!b) return RAD_E_INVAL;
|
||||
return B(b)->kv_group_zero(g);
|
||||
}
|
||||
|
||||
int rad_decl_name_map(RadBuilder* b, const RadNameMap* m) {
|
||||
if (!b) return RAD_E_INVAL;
|
||||
return B(b)->decl_name_map(m);
|
||||
|
||||
@@ -256,6 +256,14 @@ int KVManager::plan_groups(const std::vector<KVGroupInfo>& groups, const Config&
|
||||
RAD_ERR("KV group '%s': unknown kind %d", p.name.c_str(), p.kind);
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
/* A ZERO GROUP COSTS THIS RANK NOTHING: declared for its position and its block count,
|
||||
* never carved, never read. The validation above still ran on the real sizes, so a zero
|
||||
* group is a real group on every other rank. */
|
||||
if (g.zero) {
|
||||
p.zero = true;
|
||||
p.bytes_per_block = 0;
|
||||
p.bytes_per_state = 0;
|
||||
}
|
||||
plans_.push_back(std::move(p));
|
||||
}
|
||||
bundling_ = compare_bundling(bundles);
|
||||
@@ -453,6 +461,15 @@ int KVManager::carve_into(Pool& kv_pool) {
|
||||
int64_t bytes = p.paged() ? p.n_blocks * p.bytes_per_block
|
||||
: p.n_states * p.bytes_per_state;
|
||||
if (p.paged()) paged_taken += bytes;
|
||||
if (p.zero) {
|
||||
p.base = nullptr;
|
||||
p.pool_offset = 0;
|
||||
p.pool_bytes = 0;
|
||||
RAD_INFO("KV group '%s': this rank keeps no cache for it (rad_kv_group_zero) -- %lld "
|
||||
"blocks of the shared table, nothing carved", p.name.c_str(),
|
||||
(long long)p.n_blocks);
|
||||
continue;
|
||||
}
|
||||
int64_t off = 0;
|
||||
void* ptr = kv_pool.reserve(p.name, bytes, RAD_ALIGN_UNIT, &off);
|
||||
if (!ptr && !kv_pool.accounting_only()) {
|
||||
|
||||
@@ -74,6 +74,10 @@ struct KVGroupPlan {
|
||||
int64_t window_blocks = 0; /* WINDOW: the per-sequence block cap */
|
||||
|
||||
int64_t n_blocks = 0; /* paged groups: blocks carved from the pool */
|
||||
/* rad_kv_group_zero: this rank keeps no cache for the group. The plan exists for its position
|
||||
* and its block count (one block table serves every rank), its costs are zero and nothing is
|
||||
* carved; no op on this rank names it (issue refuses a group with no pool bound). */
|
||||
bool zero = false;
|
||||
int64_t n_states = 0; /* LINEAR/CONV: n_seq_states * state_copies */
|
||||
/* HOW MANY PHYSICAL SLOTS ONE LOGICAL STATE COSTS. One, normally: a sequence owns a state.
|
||||
* Under speculation a linear kernel needs somewhere to put what it cannot commit yet -- it
|
||||
|
||||
@@ -295,6 +295,7 @@ struct KVGroupInfo {
|
||||
int64_t bytes_per_block = 0;
|
||||
int64_t bytes_per_state = 0; /* linear/conv: per sequence */
|
||||
std::vector<int> layers;
|
||||
bool zero = false; /* rad_kv_group_zero: declared for position, nothing carved */
|
||||
};
|
||||
|
||||
/* A RAD_KV_CONV GROUP'S WINDOW, IN ENTRIES: conv_width - 1 of history and one more for every
|
||||
|
||||
@@ -760,10 +760,12 @@ int Ctx::issue_body(rad_op h, const RadOperand* opd, int n_opd, int64_t n) {
|
||||
const uint32_t g = o.handle;
|
||||
if ((size_t)g >= kv_.size() || !kv_[g].base)
|
||||
return abort_step_msg(h, RAD_E_STATE,
|
||||
fmt("operand %d names KV group %u, which has no pool bound. "
|
||||
"The block manager allocates it at load and binds it "
|
||||
"into the Ctx; a group with none is a startup bug, not "
|
||||
"a runtime condition", i, g));
|
||||
fmt("operand %d names KV group %u, which has no pool bound on "
|
||||
"this rank. The block manager allocates it at load and "
|
||||
"binds it into the Ctx; a group with none is a startup "
|
||||
"bug -- or a group this rank declared with "
|
||||
"rad_kv_group_zero and then issued against, which the "
|
||||
"plugin must not do", i, g));
|
||||
const KVPoolBinding& b = kv_[g];
|
||||
/* A POSITION LOOKUP, not `o.offset - first_layer`. The subtraction is right only for a
|
||||
* group whose layers are contiguous, and they need not be: with 15 attention layers
|
||||
|
||||
Reference in new issue
Block a user