radiance 1.0.12

- Wrong answers under concurrency on models with gated delta net layers (Qwen3.8-Flash-Next,
  Qwen3.8-27B, Qwen3.6-35B-A3B). A conv state slot was one entry wider in the allocation than in
  the state the kernels index, so clearing the slot a newly admitted request was given -- and a
  prefix-cache checkpoint's save and restore -- reached into the next request's conv and n-gram
  windows. A request decoding beside an admission then lost part of its recent context: a right
  first token followed by a context-free continuation ("1. **Identify the numbers..." for "What
  is 65 times 3?"), repeated or skipped digits. A single request was never affected. One
  definition of the slot now, and the server refuses to start if the allocation and the kernels
  ever disagree on it. Present since 1.0.0; reported with a strict concurrent sanity check.
- --num-speculative-tokens 0 no longer stops the engine at the first multi-sequence decode step:
  an all-reduce argument struct's padding was uninitialised, and a recorded pass's audit read it
  as a changed argument.
This commit is contained in:
Deadcode committed 2026-10-05 18:27:23 +02:00
1 parent 469441d90f
commit a4845834ea
10 files changed
+106 -31

No files matched your search

+11 -15
View File
@@ -1382,22 +1382,18 @@ void Builder::finish_kv_groups() {
* (d.state_dim[1] ? d.state_dim[1] : 1)) * n_bound;
break;
case RAD_KV_CONV: {
/* A rolling window of conv_width-1 + n_spec + 1 entries, so a speculative
* rejection is a change of read offset rather than a recompute (spec §10). The
* window is sized for the largest speculative window this deployment was
* configured for.
/* A rolling window of conv_width-1 + n_spec entries, so a speculative rejection
* is a change of read offset rather than a recompute (spec §10). The window is
* sized for the largest speculative window this deployment was configured for.
*
* THE +1 IS THE VERIFY STEP'S OWN OUTPUT, and it is not optional. A verify writes
* 1 + n_spec conv outputs before anyone knows which survive, so peak occupancy is
* the conv_width-1 of retained history PLUS all 1 + n_spec of them. Sizing this
* `conv_width - 1 + max_spec` instead -- six entries at width 4 depth 3 -- puts it
* one short of the modulus BatchBuilder::init and Scheduler::conv_window cycle
* `conv_cursor` by, which is `conv_width - 1 + n_spec + 1`, seven: `(cursor + 1 +
* a) % 7` reaches 6, one past the end of the allocation and into the slot that
* belongs to the next sequence. At n_spec 0 the two agree (modulus conv_width,
* history conv_width-1 plus the one output), so the discrepancy hides there. */
int64_t entries = (d.conv_width > 0 ? d.conv_width - 1 : 0) +
(prog_.ctx.max_spec > 0 ? prog_.ctx.max_spec : 0) + 1;
* EXACTLY THE STATE TENSOR'S EXTENT, conv_window_entries(), and not one more. The
* kernels lay the slots out from the tensor, so an allocation one entry wider a
* slot puts the manager's slot `s` -- the bytes it clears when it hands the slot
* out, and saves and restores at a checkpoint -- over the start of the kernels'
* slot `s + 1`. Handing a slot to a new sequence then zeroes part of a running
* sequence's window. conv_state_index's cursor cycles by the same number, so it
* stays inside the slot. */
int64_t entries = conv_window_entries(d, prog_.ctx.max_spec);
if (entries <= 0) entries = 1;
gi.bytes_per_block = 0;
gi.bytes_per_state =
+19 -2
View File
@@ -191,8 +191,7 @@ int KVManager::plan_groups(const std::vector<KVGroupInfo>& groups, const Config&
* a change of read offset rather than a recompute (spec §10). The engine's
* contract is that the kernel pair supports that; the manager's job is to make the
* slot big enough for it. */
p.conv_slots = (g.decl.conv_width > 0 ? g.decl.conv_width - 1 : 0)
+ (cfg.n_spec > 0 ? cfg.n_spec : 0);
p.conv_slots = conv_window_entries(g.decl, cfg.n_spec);
if (p.conv_slots <= 0) {
RAD_ERR("KV group '%s': conv_width %lld with n_spec %d gives 0 slots",
p.name.c_str(), (long long)g.decl.conv_width, cfg.n_spec);
@@ -231,6 +230,24 @@ int KVManager::plan_groups(const std::vector<KVGroupInfo>& groups, const Config&
RAD_ERR("KV group '%s': per-sequence state computes to 0", p.name.c_str());
return RAD_E_INVAL;
}
/* THE SLOT THE KERNELS INDEX, which is the slot this manager has to hand out. The
* kernels lay slots out from the state tensor ([n_states, channels, conv_slots] or
* [n_states, n_head_kv, state_dim]); this manager lays them out from bytes_per_state,
* and clears, saves and restores slots in that layout. Two different sizes make every
* one of those touch a neighbouring sequence's state. */
const int64_t indexed =
(p.kind == RAD_KV_CONV
? p.conv_slots * g.decl.n_head_kv * g.decl.head_dim
: g.decl.n_head_kv * g.decl.state_dim[0] * g.decl.state_dim[1])
* elt * p.n_layers;
if (p.bytes_per_state != indexed) {
RAD_ERR("KV group '%s': %lld bytes a sequence are allocated, and the state the "
"kernels index is %lld bytes over its %lld layers -- the slot this manager "
"clears, checkpoints and restores would not be the slot the kernels read",
p.name.c_str(), (long long)p.bytes_per_state, (long long)indexed,
(long long)p.n_layers);
return RAD_E_SHAPE;
}
/* Exactly one slot per concurrent sequence, times whatever the kernel needs beside
* it. Not a heuristic: a sequence owns exactly one recurrent state, so max_seqs is
* the count of LOGICAL states, full stop. */
+12
View File
@@ -285,6 +285,18 @@ struct KVGroupInfo {
std::vector<int> layers;
};
/* A RAD_KV_CONV GROUP'S WINDOW, IN ENTRIES: conv_width - 1 of history and one more for every
* speculative position. It is the last extent of the state tensor the kernels index, and the
* kernels take the layout from that extent -- a slot is `entries` consecutive entries a channel,
* and libr4d's conv update derives the verify step's query length from it as
* entries - (conv_width - 2). So the allocation's slot, the KV manager's view of a slot (its clear
* when one is handed out, a checkpoint's save and restore) and the cursor conv_state_index derives
* all take this one number. A slot sized larger on the manager's side than in the tensor puts
* each of those views across the start of the next sequence's window. */
inline int64_t conv_window_entries(const RadKVGroupDecl& d, int64_t n_spec) {
return (d.conv_width > 0 ? d.conv_width - 1 : 0) + (n_spec > 0 ? n_spec : 0);
}
/* Everything declare produced. The core owns it; the plugin only ever sees handles into it. */
class Program {
public:
+4 -4
View File
@@ -399,8 +399,9 @@ int BatchBuilder::layout(Program& prog, const Config& cfg) {
if (max_ctx_ <= 0) max_ctx_ = cfg.max_tok;
/* The conv rolling window: width-1 entries of history plus room for the whole speculative
* window, because a verify writes num_spec+1 conv outputs before anything is accepted, and a
* rejection then reads back at the slot the last accepted token left (spec §10). */
* window, and a rejection then reads back at the slot the last accepted token left (spec §10).
* The state tensor's own extent (conv_window_entries), so the cursor derived from it stays
* inside the slot the kernels index. */
conv_window_.assign(prog.kv_groups.size(), 1);
conv_group_ = -1;
n_conv_ = 0;
@@ -410,8 +411,7 @@ int BatchBuilder::layout(Program& prog, const Config& cfg) {
++n_conv_;
conv_group_ = n_conv_ == 1 ? (int32_t)i : -1; /* -1 once there is more than one */
if (g.decl.conv_width > 0)
conv_window_[i] = (int32_t)(g.decl.conv_width - 1 +
(cfg.n_spec > 0 ? cfg.n_spec : 0) + 1);
conv_window_[i] = (int32_t)conv_window_entries(g.decl, cfg.n_spec);
}
/* ------------------------------------------------------------ derived buffers */
+1 -1
View File
@@ -2089,7 +2089,7 @@ int32_t Scheduler::conv_window() const {
int32_t W = 1;
for (const KVGroupInfo& g : prog_->kv_groups)
if (g.decl.kind == RAD_KV_CONV && g.decl.conv_width > 0)
W = (int32_t)(g.decl.conv_width - 1 + (cfg_.n_spec > 0 ? cfg_.n_spec : 0) + 1);
W = (int32_t)conv_window_entries(g.decl, cfg_.n_spec);
return W;
}