radiance 1.12.0

New models:
- Fish Audio drama-3: speech with speaker tags and inline direction, voices cloned from reference
  clips (the `references` field of /v1/audio/speech and the streaming session), two cards
- Gemma 4 E2B/E4B (KV-shared layers, per-layer embeddings, clipped vision linears), with
  NVIDIA-Nemotron-3.5-Bolt-E4B in bf16 with DFlash and vision on one card, and E4B recipes

Speed:
- MXFP4 GEMMs for one to 64 rows and a tiled prefill GEMM at TN=4 from 1024 rows: the 27B MXFP4
  with DFlash2 decodes about 1% faster at c1, 5% at c4 and 14% at c16
- The fp8 and int8 LM heads read their weight once for 65 to 128 rows
- A prefill step of one sequence runs in two pieces on a second lane at two ranks (qwen35_fp8,
  gemma3): a 45K-token prompt on the 27B fp8 in 15.1 s instead of 16.2 s
- Gemma 3's fused all-reduce junctions also under a lossy wire
- --draft-short-from N: a block drafter runs its shorter block from N decoding sequences on
  (off by default; with 8 on the 27B MXFP4: c8 +12%, c16 +18%, c64 +32%, c1 unchanged)
- --tp-attn-split rows: GLM-5.3-Flash's MLA attention split by rows over the ranks, 18 to 21%
  faster prefill; lossy, `heads` stays the default
- --draft-coupling on: Qwen3.8-Flash-Next's MTP drafter samples its proposals from its reranked
  top-8 and the target's draw is coupled to it; pays at high temperatures (c1 at T 1.0: 155 ->
  178 tok/s), costs at low ones; off by default

Features:
- Edited prompts on windowed models (Gemma 4) reuse their prefix: periodic window snapshots, and
  snapshot-backed prefix KV kept across recomputes (an edited tail on Gemma 4 31B: 96 s -> 2.6 s)
- DELETE /sessions/<label> and DELETE /sessions?id=<id> forget one stored conversation
- --state-cache-dtype f16: the delta-net state cache at half the memory (qwen35 plugins; lossy)

Fixes:
- A browser's CORS preflight allows DELETE

Changes: Plugin ABI 27: out-of-tree plugins must be rebuilt. The environment switches the PRs
added are flags now (--tp-attn-split, --draft-coupling, --state-cache-dtype).
This commit is contained in:
137 files changed
+12959 -1126

No files matched your search

+2 -1
View File
@@ -133,6 +133,7 @@ int chunk_geometry_resolve(const Program& prog, const Config& cfg, ChunkGeometry
else
g.checkpoint_interval = 0;
g.window_ckpt = !has_linear && g.checkpoint_interval > 0;
g.window_periodic = g.window_ckpt && cfg.checkpoint_policy != "tip-only";
/* Window checkpoints do not support skipping snapshots inside a prefill span. */
g.span = (g.checkpoint_interval > 0 && !g.window_ckpt && cfg.prefill_span > 1)
? cfg.prefill_span : 1;
@@ -156,7 +157,7 @@ int chunk_geometry_resolve(const Program& prog, const Config& cfg, ChunkGeometry
* chunk; the log line makes that visible. tip-only window snapshots do not
* split at the interval, so their chunk is bounded by the token budget. */
const int64_t span_tok = g.checkpoint_interval * g.span;
const bool periodic = !g.window_ckpt || cfg.checkpoint_policy != "tip-only";
const bool periodic = !g.window_ckpt || g.window_periodic;
const int64_t eff = (g.checkpoint_interval > 0 && periodic && span_tok < cfg.max_tok)
? span_tok : cfg.max_tok;
RAD_INFO("chunk geometry: quantum %lld (attn block %lld, state chunk %lld), checkpoint "
+3
View File
@@ -56,6 +56,9 @@ struct ChunkGeometry {
* snapshots let an edited prompt resume below its divergence instead of from zero.
* tip-only skips interval snapshots and keeps the original tail-only chunking. */
bool window_ckpt = false;
/* Window checkpoints at interval boundaries too, not only at the tail: every policy but
* tip-only, which keeps the tail alone and so splits no chunk at the interval. */
bool window_periodic = false;
bool checkpoints() const { return checkpoint_interval > 0; }
};
+16
View File
@@ -202,6 +202,16 @@ struct IPrefixCache {
/* Entries expired by --prefix-cache-ttl; not counted as evictions. */
virtual int64_t expired() const { return 0; }
virtual int64_t ckpt_expired() const { return 0; }
/* Entries and snapshots a client released on purpose (release_session). */
virtual int64_t released() const { return 0; }
virtual int64_t ckpt_released() const { return 0; }
/* Forget one stored conversation now, by the client's label or the engine's session id
* (PrefixCache::release_session). RAD_E_UNSUPPORTED from a cache without a session table. */
virtual int release_session(const std::string& /*label*/, uint64_t /*id*/,
int64_t /*keep_tokens*/, SessionRelease* /*out*/) {
return RAD_E_UNSUPPORTED;
}
/* Tokens of context held only by the cache right now. Blocks a running sequence also reads
* are excluded. Separates a working cache from a leak in the pool figures. */
@@ -488,6 +498,12 @@ struct PCBinding final : IPrefixCache {
}
int64_t expired() const override { return m->stats().expired; }
int64_t ckpt_expired() const override { return m->stats().ckpt_expired; }
int64_t released() const override { return m->stats().released; }
int64_t ckpt_released() const override { return m->stats().ckpt_released; }
int release_session(const std::string& label, uint64_t id, int64_t keep_tokens,
SessionRelease* out) override {
return m->release_session(label, id, keep_tokens, out);
}
int64_t held_tokens() const override { return m->unshared_tokens(); }
int64_t next_checkpoint_after(int64_t p) const override { return m->next_checkpoint_after(p); }
+1
View File
@@ -92,6 +92,7 @@ struct SchedMetrics {
* and reservations that went without a snapshot. */
int64_t prefix_ckpt_retired = 0, prefix_ckpt_lru = 0, prefix_ckpt_refused = 0;
int64_t prefix_expired = 0, prefix_ckpt_expired = 0; /* --prefix-cache-ttl */
int64_t prefix_released = 0, prefix_ckpt_released = 0; /* DELETE /sessions */
/* Admissions whose attention hit was cut to nothing: no snapshot at or below it (recurrent
* state or a window snapshot), a windowed trunk group no window snapshot covers, or blocks
* that could not be adopted. `hit_cut_resumed_below` counts those that resumed at a
+72
View File
@@ -0,0 +1,72 @@
/* mtp_couple_bind.h -- the engine's post-commit binding step for a serial drafting row.
*
* Engine::finish_serial_drafter calls this after the commit, once the card's proposal states are
* read back. It decides:
*
* - the position the next build stages the row at: the request's committed output length after
* this commit. It is not rebuilt from the draw's pre-commit base plus the accepted count, which
* differ when a max_tokens or context cut emits fewer tokens than the card accepted;
* - whether the row binds at all: a sequence that is gone from the commit or no longer Running
* will not sample again.
*
* Both come from Scheduler::committed_seq(), filled by commit under the scheduler lock, never from
* the plan's StepEntry::req, which reap() may have freed by now. A header of its own so the rule
* can be tested against a real commit without an Engine (tests/sched_test.cpp).
*/
#pragma once
#include "advance.h"
#include "rad_spechub.h"
#include <cstring>
#include <string>
namespace rad {
/* Where the next build will sample this sequence, after the current step's commit. */
struct MtpCoupleBindPoint {
bool found = false; /* the committed step carried the sequence */
bool live = false; /* and its request was still Running (not finished/cancelled/failed) */
uint64_t n_out = 0; /* its committed output length: what the next build reads as n_out */
};
/* Bind `done` rounds of this row's draw to the positions the next build samples. `rb` is round 1
* of this row in the engine's readback (stride `rb_stride` states), `tok[rd]` the card's token for
* round rd, `S` the card's slot. Fills `out[0, done)` and sets `*n_bound = done`; a sequence that
* is not live binds nothing (`*n_bound = 0`, RAD_OK) and leaves `out` untouched. RAD_E_STATE with
* `why` for a readback that is not this draw's, or is not a state the proposer could have written.
* A sampled round the proposer marked status -1 (a shortlist it could not turn into Q) kept the
* greedy proposal; it is bound as is, the sampler does not couple it, and `*n_malformed` counts it.
* `base` is never read here: it is the draft's coordinate, not the verify's. */
inline int mtp_couple_bind_rounds(const MtpCoupleBindPoint& p, const RadMtpCoupleDraw& d,
const RadMtpCoupleState* rb, int rb_stride, int done,
const StepSlot& S, int64_t vocab, RadMtpCoupleState* out,
int* n_bound, std::string* why, int* n_malformed = nullptr) {
*n_bound = 0;
if (n_malformed) *n_malformed = 0;
if (!p.live) return RAD_OK;
const bool sampled = d.mode == 1;
for (int rd = 1; rd <= done; ++rd) {
const RadMtpCoupleState& st = rb[(size_t)(rd - 1) * (size_t)rb_stride];
const bool malformed = sampled && st.status == -1;
if (std::memcmp(&st.draw, &d, sizeof d) || st.round != rd || st.x != S.tok[rd] ||
(st.status != (sampled ? 1 : 0) && !malformed) ||
(sampled && !malformed && !rad_mtp_couple_state_valid(st, vocab))) {
*why = "MTP coupled: sequence " + std::to_string(d.seq) + " round " +
std::to_string(rd) + " returned status " + std::to_string(st.status) +
" round " + std::to_string(st.round) + " x " + std::to_string(st.x) +
" for card token " + std::to_string(S.tok[rd]) + " (draw " +
(std::memcmp(&st.draw, &d, sizeof d) ? "stale" : "current") +
"); refusing the step";
return RAD_E_STATE;
}
if (malformed && n_malformed) ++*n_malformed;
RadMtpCoupleState b = st;
b.pos = rad_mtp_couple_verify_pos(p.n_out, rd);
out[rd - 1] = b;
}
*n_bound = done;
return RAD_OK;
}
} // namespace rad
+53
View File
@@ -0,0 +1,53 @@
/* mtp_couple_plan.h -- which draw the engine stages for each serial drafting row.
*
* Engine::stage_couple_draws (core/engine_draft.cpp) reads the draw of every sequence on its card
* from the step plan and, for each drafting row, the plan entry naming the row's sequence on the
* row's card. Pure host bookkeeping, so it is tested without a card.
*
* `by_card` has one entry per card slot, indexed by StepEntry::card in [0, max_seqs), the range of
* the StepSlots the advance reads.
*/
#pragma once
#include "batch.h"
#include "scheduler.h" /* Scheduler::SerialRow */
#include "rad_spechub.h"
#include <cstdint>
#include <string>
#include <vector>
namespace rad {
/* Fills `by_card[0, n_card)` from the plan and writes one draw per drafting row to `stage[0, n)`.
* RAD_OK, or RAD_E_STATE with `why` set: the plane is too small for the card slots, or a drafting
* row's card carries no plan entry naming its sequence (a stale row -- the plugin would refuse the
* staged draw, so it is refused here where the row can be named). */
inline int mtp_couple_plan_stage(const StepPlan& plan, int n_card, const Scheduler::SerialRow* rows,
int n, std::vector<RadMtpCoupleDraw>* by_card,
RadMtpCoupleDraw* stage, std::string* why) {
if (!by_card || !stage || !why) return RAD_E_INVAL;
if ((int)by_card->size() < n_card) {
*why = "the draw plane holds " + std::to_string(by_card->size()) +
" card slot(s), the step can use " + std::to_string(n_card);
return RAD_E_STATE;
}
for (int c = 0; c < n_card; ++c) (*by_card)[(size_t)c] = RadMtpCoupleDraw{};
for (const StepEntry& e : plan.e)
if (e.req && e.card >= 0 && e.card < n_card)
(*by_card)[(size_t)e.card] = { e.req->sp.seed, (uint64_t)e.req->output.size(), e.seq,
e.card, e.req->sp.greedy() ? 0u : 1u };
for (int i = 0; i < n; ++i) {
const Scheduler::SerialRow& row = rows[i];
if (row.card < 0 || row.card >= n_card || (*by_card)[(size_t)row.card].seq != row.seq) {
*why = "drafting row " + std::to_string(i) + " (sequence " + std::to_string(row.seq) +
", card " + std::to_string(row.card) + ") has no plan entry on its card";
return RAD_E_STATE;
}
stage[i] = (*by_card)[(size_t)row.card];
}
return RAD_OK;
}
} // namespace rad
+80 -3
View File
@@ -202,6 +202,7 @@ int Scheduler::init(Program& prog, const Config& cfg, IKVManager* kv, IPrefixCac
free_cards_[(size_t)c] = (int32_t)(cfg.max_seqs - 1 - c); /* 0 is taken first */
reqs_.reserve((size_t)cfg.max_seqs);
completed_.reserve((size_t)cfg.max_seqs);
committed_.reserve((size_t)cfg.max_seqs);
by_id_.reserve((size_t)cfg.max_seqs * 2);
hit_blocks_.resize(prog.kv_groups.size());
for (auto& v : hit_blocks_) v.reserve(64);
@@ -325,6 +326,25 @@ Request* Scheduler::find(uint64_t id) {
return it == by_id_.end() ? nullptr : reqs_[(size_t)it->second]->req.get();
}
bool Scheduler::running(uint64_t id) const {
std::lock_guard<std::mutex> lk(mu_);
auto it = by_id_.find(id);
if (it == by_id_.end()) return false;
const SchedReq& s = *reqs_[(size_t)it->second];
return s.req && s.req->state == ReqState::Running;
}
bool Scheduler::committed_seq(uint64_t seq, uint64_t* n_out, bool* live) const {
std::lock_guard<std::mutex> lk(mu_);
for (const CommittedSeq& c : committed_)
if (c.seq == seq) {
if (n_out) *n_out = c.n_out;
if (live) *live = c.live;
return true;
}
return false;
}
int Scheduler::set_draft(uint64_t id, const int32_t* tokens, int n) {
std::lock_guard<std::mutex> lk(mu_);
auto it = by_id_.find(id);
@@ -403,6 +423,40 @@ int64_t Scheduler::reset_prefix_cache() {
return dropped;
}
int Scheduler::release_session(const std::string& label, uint64_t id, int64_t keep_tokens,
SessionRelease* out) {
std::lock_guard<std::mutex> lk(mu_);
if (!pc_ || !cfg_.prefix_cache) return RAD_E_UNSUPPORTED;
if (label.empty() && id == 0) return RAD_E_INVAL;
for (const auto& p : reqs_) {
if (!p || !p->req) continue;
const Request& r = *p->req;
if (r.state == ReqState::Finished || r.state == ReqState::Failed ||
r.state == ReqState::Cancelled)
continue;
if ((id != 0 && r.id == id) || (!label.empty() && r.session_label == label))
return RAD_E_STATE;
}
const int rc = pc_->release_session(label, id, keep_tokens, out);
if (rc == RAD_OK && out) {
if (label.empty())
RAD_INFO("prefix cache: session %llu released: %lld entries (%lld tokens), %lld "
"snapshots; kept %lld tokens as asked, %lld blocks shared, %lld live",
(unsigned long long)id, (long long)out->entries, (long long)out->tokens,
(long long)out->snapshots, (long long)out->kept_tokens,
(long long)out->kept_shared, (long long)out->kept_live);
else
RAD_INFO("prefix cache: session '%s' released (%lld rows): %lld entries (%lld "
"tokens), %lld snapshots; kept %lld tokens as asked, %lld blocks shared, "
"%lld live",
label.c_str(), (long long)out->sessions, (long long)out->entries,
(long long)out->tokens, (long long)out->snapshots,
(long long)out->kept_tokens, (long long)out->kept_shared,
(long long)out->kept_live);
}
return rc;
}
void Scheduler::trim_prefix_cache() {
if (!pc_ || !cfg_.prefix_cache) return;
const std::vector<int32_t>& cg = pc_->cached_groups();
@@ -751,7 +805,7 @@ int64_t Scheduler::plan_chunk(int64_t n_computed, int64_t n_target, int64_t budg
if (geo_.checkpoints()) {
const int64_t I = geo_.checkpoint_interval;
int64_t next = ((n_computed / I) + 1) * I; /* strictly after n_computed */
if (geo_.window_ckpt && cfg_.checkpoint_policy == "tip-only") {
if (geo_.window_ckpt && !geo_.window_periodic) {
/* An explicit tail-only policy should not pay for intermediate
* window copies or chunk splits just to retire those snapshots. */
next = INT64_MAX;
@@ -1882,6 +1936,10 @@ int Scheduler::commit(const StepResult& res) {
}
step_open_ = false;
/* What the serial bind reads after commit, copied here while the Requests are still held:
* reap() may release a finished one before finish_serial_drafter runs. */
committed_.clear();
const int32_t W = conv_window();
/* A mixed step leaves decode rows the same replay factors as a decode step (recurrent path
@@ -1904,6 +1962,7 @@ int Scheduler::commit(const StepResult& res) {
s.pending_free = false;
--n_deferred_;
}
committed_.push_back({e.seq, (uint64_t)r.output.size(), false});
continue;
}
@@ -2060,6 +2119,7 @@ int Scheduler::commit(const StepResult& res) {
} else if (eos) {
close_request(s, ReqState::Finished, "stop", carried);
}
committed_.push_back({e.seq, (uint64_t)r.output.size(), r.state == ReqState::Running});
}
m_.prefill_tokens += step_prefill_tok_;
@@ -2386,8 +2446,12 @@ void Scheduler::serial_end(int rounds_done) {
* also propose. Called while plan() still describes that step, because the context pass mirrors
* it exactly, rejected suffix included: the drafter reads hidden states positionally from its
* own buffer, so batch row i must be buffer row i. The rejected positions lie in [n_computed,
* n_computed + block), which the query pass overwrites before anything reads them, and the
* ensure() below covers them since n_computed + block reaches the trunk step's own end.
* n_computed + the trunk step's block), which a query pass overwrites before anything reads them.
* The ensure() below covers n_computed + `block`; with the block the trunk step verified that
* reaches its end. A short block (rad_drafter_short_block) after a long one does not: rejected
* rows past it fall on pages the commit's rollback freed, whose slot is -1, and every kv_store
* drops a negative slot. That rule is what keeps such a step from writing into another
* sequence's pages.
*
* On the card the step has not committed yet. The step began at n_computed (a row issued ahead
* was staged at its furthest reach; it really continued from the committed end, as commit()
@@ -2503,6 +2567,17 @@ int Scheduler::block_begin(int block, int depth, int window, int32_t mask, Block
return n_draft_rows;
}
int Scheduler::decoded_seqs() const {
std::lock_guard<std::mutex> lk(mu_);
int n = 0;
for (const StepEntry& e : plan_.e) {
if (!e.produces_token || e.slot < 0 || (size_t)e.slot >= reqs_.size()) continue;
const SchedReq& s = *reqs_[(size_t)e.slot];
if (s.req && s.req->state == ReqState::Running && s.running) ++n;
}
return n;
}
const Request* Scheduler::block_req(const BlockSeq& d) const { return live_req(d.slot, d.seq); }
const Request* Scheduler::serial_req(const SerialSeq& m) const { return live_req(m.slot, m.seq); }
@@ -2712,6 +2787,8 @@ SchedMetrics Scheduler::metrics_locked() const {
m.prefix_ckpt_refused = cc.refused;
m.prefix_expired = pc_->expired();
m.prefix_ckpt_expired = pc_->ckpt_expired();
m.prefix_released = pc_->released();
m.prefix_ckpt_released = pc_->ckpt_released();
m.prefix_held_tokens = pc_->held_tokens(); }
m.attn_hit_rate = m.prompt_tokens
? (float)((double)m.attn_cached_tokens / (double)m.prompt_tokens) : 0.0f;
+34
View File
@@ -139,6 +139,15 @@ public:
const int32_t* first_row = nullptr; /* [n_seq] */
};
/* What commit left a sequence at: its committed length and whether it is still Running.
* Copied under the lock in commit because reap() may free the Request before the serial bind
* reads it. */
struct CommittedSeq {
uint64_t seq = 0;
uint64_t n_out = 0;
bool live = false;
};
/* `geo` is the already-resolved chunk geometry. The engine resolves it once because
* PrefixCache::configure runs first and needs its checkpoint interval; pass nullptr to
* resolve one here. */
@@ -167,6 +176,11 @@ public:
* under exactly the load that cancels. */
int cancel(uint64_t id);
Request* find(uint64_t id);
/* Whether the request is still admitted and Running, read under the lock. */
bool running(uint64_t id) const;
/* What the step just committed left for `seq`, copied by commit under the lock. False when
* that step carried no such sequence. */
bool committed_seq(uint64_t seq, uint64_t* n_out, bool* live) const;
/* Requests that reached a terminal state since the last call, oldest first, swapped into
* `out` under the lock (old contents discarded). Only the engine consumes it, to drop
@@ -260,6 +274,13 @@ public:
* cache. Takes the step lock because the step path inserts into the map (live sequences hold
* their own block references). See IScheduler::reset_prefix_cache. */
int64_t reset_prefix_cache();
/* Forget one stored conversation, by label or engine id, keeping its first `keep_tokens`
* (IPrefixCache::release_session). Refused with RAD_E_STATE while a request of that
* conversation is queued or running: its blocks would be skipped as live and its close
* would publish the chain again, so the release would be half done and undone at once.
* Takes the step lock like reset_prefix_cache. */
int release_session(const std::string& label, uint64_t id, int64_t keep_tokens,
SessionRelease* out);
/* ---------------------------------------------------------- the step path */
/* One decision, one batch. Null when there is nothing to run, which is not an error. */
@@ -361,6 +382,17 @@ public:
* in the order block_query() emits them. */
int block_begin(int block, int depth, int window, int32_t mask, BlockRow* out, int max,
bool on_card = false);
/* How many running sequences the step just run decoded (produced a token for), the load a
* block drafter's block length is chosen by. Read before block_begin(). */
int decoded_seqs() const;
/* Whether a block drafter runs its short block (--draft-short-from `from`), given whether it
* ran it last step and this step's decoded_seqs(): on from `from`, off again only at two
* below, so a load wavering at the threshold does not switch the pass shape every step. */
static bool short_block_on(bool was_on, int64_t decoded, int64_t from) {
if (decoded >= from) return true;
if (decoded + 2 <= from) return false;
return was_on;
}
const RadBatch* block_context(int step);
const RadBatch* block_query(int step);
void block_end();
@@ -637,6 +669,8 @@ private:
* covered, both decayed with the same time constant, so their ratio is tokens over time. */
double tps_win_prefill_ = 0.0, tps_win_decode_ = 0.0, tps_win_time_ = 0.0;
bool step_open_ = false;
/* The step just committed: its sequences' committed length and liveness, in plan order. */
std::vector<CommittedSeq> committed_;
/* The single-sequence decode floor (rad::DecodeFloor), fed by step_finished. */
DecodeFloor decode_floor_;