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

+44
View File
@@ -0,0 +1,44 @@
/* mtp_couple_evidence.h -- what the completed-verify log line may claim.
*
* The line reports a coupled verify only when the build that staged bound rows belongs to the step
* whose wait just returned, and counts only sequences still live after that wait. It reads
* Sampler::couple_build(), the snapshot build_step froze, because the drafter's build_greedy
* clears staged_any_couple() before the wait. The op's domain is printed so a host reference row
* is not read as a device verify.
*
* A pure function of the snapshot, a liveness predicate and the domain, so it is tested without
* an Engine (tests/sample_test.cpp).
*/
#pragma once
#include "sampler.h"
#include <string>
namespace rad {
struct MtpCoupleEvidence {
int64_t rows = 0; /* bound rows of sequences still live after the wait */
bool device = false; /* the op that ran is a device op */
std::string seqs; /* those sequences, comma separated, in build order */
};
/* `live(seq)` answers whether the sequence is still Running; the engine passes a predicate over
* Scheduler::running(), the tests a set. Empty (rows == 0) when the snapshot is not this step's,
* or nothing it staged is still live. */
template <class Live>
MtpCoupleEvidence mtp_couple_evidence(const Sampler::CoupleBuild& b, int64_t step, int domain,
Live&& live) {
MtpCoupleEvidence e;
if (b.step != step) return e;
e.device = domain == RAD_DOMAIN_DEVICE;
for (const auto& s : b.seqs)
if (live(s.first)) {
e.rows += s.second;
if (!e.seqs.empty()) e.seqs += ",";
e.seqs += std::to_string(s.first);
}
return e;
}
} // namespace rad
+86 -2
View File
@@ -133,6 +133,7 @@ int Sampler::declare(RadBuilder* b, const SamplerConfig& cfg) {
}
cfg_ = cfg;
couple_ = cfg.draft_coupling;
if (cfg_.n_vocab_local <= 0) cfg_.n_vocab_local = cfg_.n_vocab / cfg_.world_size;
/* The staged mask covers this rank's shard; the grammar's covers the whole vocabulary.
@@ -185,6 +186,14 @@ int Sampler::declare(RadBuilder* b, const SamplerConfig& cfg) {
* exempts that column. The ban op indexes it by the sampled row, not by mask_row. */
buf_ngram_wl_ = decl("sampler.ngram_wl", RAD_U32, rows, mask_words_, RAD_BUF_PERSIST);
buf_mask_ = decl("sampler.mask", RAD_U32, rows, mask_words_, RAD_BUF_PERSIST);
/* The coupled state plane, one row per sampled position, PERSIST because an upload fills it
* before the run phase issues anything. A round's state belongs to the verify row that
* follows it, so it rides the sampler's row array. */
if (couple_) {
buf_couple_ = decl("sampler.mtp_couple", RAD_U32, rows, RAD_MTP_COUPLE_STATE_WORDS,
RAD_BUF_PERSIST);
if (!buf_couple_) return RAD_E_NOMEM;
}
buf_cand_i_ = decl("sampler.cand_idx", RAD_I32, rows, ncand, RAD_BUF_TRANSIENT);
buf_cand_v_ = decl("sampler.cand_val", RAD_F32, rows, ncand, RAD_BUF_TRANSIENT);
if (vocab_parallel()) {
@@ -257,6 +266,19 @@ int Sampler::declare(RadBuilder* b, const SamplerConfig& cfg) {
op_typical_ = op_cand("sample_typical");
op_xtc_ = op_cand("sample_xtc");
op_pick_ = op_cand("sample_pick");
/* The coupled verify, over the candidate plane the pick read. A row with no bound state keeps
* the pick's token; a step with no bound row does not issue it. */
if (couple_) {
RadParam pc[3] = {
RadParam{ "M", RAD_P_RANGE, 1, rows, nullptr },
RadParam{ "n_cand", RAD_P_INT, (long long)ncand, 0, nullptr },
RadParam{ "n_vocab", RAD_P_INT, (long long)cfg_.n_vocab, 0, nullptr },
};
op_couple_ = rad_decl_op(b, "mtp_couple_verify", pc, 3, nullptr, 0);
if (!op_couple_) return RAD_E_NOKERNEL;
/* No rad_op_reads: the other sampler ops declare no lists, and a list on this op alone
* would narrow the candidate planes' lifetime to it and refuse the first sample_topk. */
}
/* The temperature kernel again, over the candidate plane: `n_vocab` is only a row length to
* it, so the candidate width works. */
{
@@ -316,6 +338,8 @@ int Sampler::declare(RadBuilder* b, const SamplerConfig& cfg) {
int Sampler::stage_alloc() {
const int64_t rows = rows_for(cfg_);
/* At most one entry per request; reserved here so a coupled step never allocates. */
couple_build_.seqs.reserve((size_t)cfg_.max_seqs);
/* Pinned: uploaded every step, and a pageable source turns the async copy into a staged one
* with a host bounce (spec §8). */
@@ -331,6 +355,11 @@ int Sampler::stage_alloc() {
ngram_stage_ = (int32_t*)rad_dev_alloc(rows * 2 * 4, RAD_MEM_HOST_PINNED);
ngram_wl_stage_ = (uint32_t*)rad_dev_alloc(rows * mask_words_ * 4, RAD_MEM_HOST_PINNED);
mask_stage_ = (uint32_t*)rad_dev_alloc(rows * mask_words_ * 4, RAD_MEM_HOST_PINNED);
/* The coupled rows, pinned: uploaded every coupled step, and a pageable source would turn the
* async copy into a staged one with a host bounce (spec §8). */
if (couple_)
couple_stage_ = (RadMtpCoupleState*)rad_dev_alloc(
rows * (int64_t)sizeof(RadMtpCoupleState), RAD_MEM_HOST_PINNED);
/* Logprobs readback; only rank 0 reads it. */
if (cfg_.rank == 0) {
@@ -347,7 +376,7 @@ int Sampler::stage_alloc() {
}
if (!params_stage_ || !greedy_stage_ || !late_stage_ || !hist_stage_ || !brk_stage_ ||
!ngram_stage_ || !ngram_wl_stage_ || !mask_stage_) {
!ngram_stage_ || !ngram_wl_stage_ || !mask_stage_ || (couple_ && !couple_stage_)) {
RAD_ERR("sampler: could not pin %s of staging",
humanb(rows * (3 * (int64_t)sizeof(DeviceSampleParams) + cfg_.max_hist * 5 +
mask_words_ * 8 + 8)).c_str());
@@ -366,6 +395,8 @@ void Sampler::stage_free() {
if (ngram_stage_) rad_dev_free(ngram_stage_, RAD_MEM_HOST_PINNED);
if (ngram_wl_stage_) rad_dev_free(ngram_wl_stage_, RAD_MEM_HOST_PINNED);
if (mask_stage_) rad_dev_free(mask_stage_, RAD_MEM_HOST_PINNED);
if (couple_stage_) rad_dev_free(couple_stage_, RAD_MEM_HOST_PINNED);
couple_stage_ = nullptr;
if (lp_host_) rad_dev_free(lp_host_, RAD_MEM_HOST_PINNED);
if (lp_ci_host_) rad_dev_free(lp_ci_host_, RAD_MEM_HOST_PINNED);
if (lp_cv_host_) rad_dev_free(lp_cv_host_, RAD_MEM_HOST_PINNED);
@@ -602,7 +633,21 @@ bool Sampler::speculation_fixed(uint64_t req_id) const {
/* ================================================================== the step path */
int Sampler::build_step(const std::vector<Request*>& reqs) {
/* Every state must name this request and its own round: one from another request or round would
* couple against a Q this step never drew. */
int Sampler::set_mtp_couple(uint64_t req_id, const RadMtpCoupleState* states, int n) {
if (!couple_ || n < 0 || n > RAD_MTP_COUPLE_MAX_ROUNDS || (n && !states)) return RAD_E_STATE;
const auto it = seqs_.find(req_id);
if (it == seqs_.end()) return RAD_E_NOTFOUND;
for (int i = 0; i < n; ++i)
if (states[i].draw.seq != req_id || states[i].round != i + 1) return RAD_E_STATE;
SeqState& s = it->second;
for (int i = 0; i < n; ++i) s.couple[i] = states[i];
s.couple_n = n;
return RAD_OK;
}
int Sampler::build_step(const std::vector<Request*>& reqs, int64_t step) {
if (!declared_) return RAD_E_STATE;
const auto t_build = std::chrono::steady_clock::now();
@@ -612,8 +657,13 @@ int Sampler::build_step(const std::vector<Request*>& reqs) {
any_late_ = false;
any_ngram_ = false;
any_ngram_wl_ = false;
any_couple_ = false;
cur_stage_ = params_stage_;
lp_rows_.clear();
/* The evidence snapshot this build owns; build_greedy never touches it. */
couple_build_.step = step;
couple_build_.rows = 0;
couple_build_.seqs.clear();
/* DRY's host half for one row whose history `h[0, take)` is staged. Over the window the
* kernel uses (the tail of the row, `dry_penalty_last_n` long when positive) it computes the
@@ -701,6 +751,30 @@ int Sampler::build_step(const std::vector<Request*>& reqs) {
if (walk && k > 0 && !dead && gr->accept_token(r->draft[k - 1]) < 0) dead = true;
if (budget && k > 0) think.push(sp.reasoning, r->draft[k - 1]);
const int64_t row = n_seq_++;
/* Row k verifies draft k against the state its round left. A row with no bound state
* (the bonus row, a greedy row, an uncoupled step) gets a zeroed one, and the verify
* leaves the pick's token alone. */
if (couple_) {
couple_stage_[row] = RadMtpCoupleState{};
const auto sit = seqs_.find(r->id);
if (sit != seqs_.end() && !sp.greedy() && r->draft && k + 1 < n_pos &&
k < sit->second.couple_n) {
const RadMtpCoupleState& c = sit->second.couple[k];
/* Same request and seed, this row's round, position and proposed token
* (rad_mtp_couple_binds); anything else is a stale state from another step. */
if (rad_mtp_couple_binds(c, r->id, sp.seed, (uint64_t)n_out, k, r->draft[k],
cfg_.n_vocab)) {
couple_stage_[row] = c;
any_couple_ = true;
++couple_build_.rows;
auto& q = couple_build_.seqs;
size_t j = 0;
while (j < q.size() && q[j].first != r->id) ++j;
if (j == q.size()) q.emplace_back(r->id, 1);
else ++q[j].second;
}
}
}
DeviceSampleParams& p = params_stage_[row];
std::memset(&p, 0, sizeof p);
@@ -940,6 +1014,7 @@ int Sampler::build_greedy(int64_t n) {
any_late_ = false;
any_ngram_ = false;
any_ngram_wl_ = false;
any_couple_ = false;
cur_stage_ = greedy_stage_;
/* A drafter's rows run the argmax only, so the n-gram plane is cleared: `run` reads it from
* the staging, and a stale pair from an earlier request's build must not issue the ban over
@@ -1030,6 +1105,9 @@ int Sampler::run(RadCtx* c, rad_buf logits, rad_buf out_tokens) {
if (any_mask)
RAD_TRY(rad_memcpy_async(rad_buf_ptr(c, buf_mask_), mask_stage_,
n_seq_ * mask_words_ * 4, s));
if (any_couple_)
RAD_TRY(rad_memcpy_async(rad_buf_ptr(c, buf_couple_), couple_stage_,
n_seq_ * (int64_t)sizeof(RadMtpCoupleState), s));
const RadOperand o_logits = opd_rows(logits, n_seq_);
const RadOperand o_params = opd_rows(buf_params_, n_seq_);
@@ -1119,6 +1197,12 @@ int Sampler::run(RadCtx* c, rad_buf logits, rad_buf out_tokens) {
RAD_TRY(issue(op_temp_late_, { o_cv, opd_rows(buf_params_late_, n_seq_) }));
RAD_TRY(issue(op_pick_, { o_ci, o_cv, o_params, o_tok }));
/* After the pick, over the same plane: a coupled row replaces the pick's token and an unbound
* row keeps it. The issued step is recorded for the evidence line. */
if (any_couple_) {
RAD_TRY(issue(op_couple_, { o_ci, o_cv, o_params, opd_rows(buf_couple_, n_seq_), o_tok }));
couple_issued_step_ = couple_build_.step;
}
/* Copy the logprobs rows to the host behind the pick, on rank 0 only (collect_step asks
* it): the summary and the candidate planes, which logprobs_for reads when the summary lacks
+45 -2
View File
@@ -77,6 +77,7 @@
*/
#pragma once
#include "rad_sample.h"
#include "rad_spechub.h"
#include "../rad_core.h"
#include "grammar.h"
@@ -86,6 +87,7 @@
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
namespace rad {
@@ -115,6 +117,10 @@ struct SamplerConfig {
* from this many of the most likely tokens, not the whole vocabulary. A request asking for a
* larger top-k is refused at admission, not silently narrowed. */
int64_t max_candidates = kSampleCandidates;
/* --draft-coupling: declare the coupled verify (`mtp_couple_verify`) behind the pick and the
* per-row state plane it reads. */
bool draft_coupling = false;
};
/* ================================================================== the driver */
@@ -166,13 +172,18 @@ public:
/* Whether allows_speculation's answer can no longer change. It changes only when a grammar
* whose backend cannot rewind starts to constrain (on a commit). */
bool speculation_fixed(uint64_t req_id) const;
/* --draft-coupling: bind the per-round states of the linear draft just published, `n` of
* them (0 clears). Each must name this request, the round it belongs to, and a `draw.mode` the
* row actually ran. RAD_E_NOTFOUND for a request already ended here. */
int set_mtp_couple(uint64_t req_id, const RadMtpCoupleState* states, int n);
/* ---------------------------------------------------------- step path */
/* Stage this step's parameter rows, penalty history and grammar bitmasks into pinned memory.
* Scheduler thread, before the rank threads are released at the barrier. Allocates nothing;
* every buffer was sized at declare against max_seqs (spec §3.1). */
int build_step(const std::vector<Request*>& reqs);
* every buffer was sized at declare against max_seqs (spec §3.1). `step` is the engine's step
* the build stages for, carried into the coupling snapshot. */
int build_step(const std::vector<Request*>& reqs, int64_t step = -1);
/* Stage `n` greedy rows for a drafter: no penalties, mask or history, and no RNG use, so
* only the argmax runs. Draft output is a proposal checked by a greedy verifier
@@ -206,6 +217,26 @@ public:
* meaningful only where the row carries RAD_SP_MASK. */
const uint32_t* staged_mask(int64_t row) const { return mask_stage_ + row * mask_words_; }
int64_t mask_words() const { return mask_words_; }
/* Staged row `row`'s bound coupled state, as `run` uploads it: all-zero where the row carries
* none (bonus row, greedy row, uncoupled step). Lets a build be checked without a device. */
const RadMtpCoupleState& staged_couple(int64_t row) const { return couple_stage_[row]; }
/* Whether any row of the last build carries a bound state, i.e. whether `run` issues the
* verify op at all. Cleared by build_greedy: a gate for run(), not for evidence. */
bool staged_any_couple() const { return any_couple_; }
/* The verify op the last build resolved, for naming its kernel in a log line. */
rad_op staged_couple_op() const { return op_couple_; }
/* What build_step staged for the coupled verify. build_greedy, which runs between that build
* and the step's wait, clears any_couple_ but leaves this snapshot. */
struct CoupleBuild {
int64_t step = -1; /* the engine step this build staged */
int64_t rows = 0; /* bound rows */
/* The distinct sequences among them, with their bound rows. */
std::vector<std::pair<uint64_t, int64_t>> seqs;
};
const CoupleBuild& couple_build() const { return couple_build_; }
/* The engine step whose build run() last issued the verify op for, or -1. */
int64_t staged_couple_issued_step() const { return couple_issued_step_; }
private:
/* Whether the vocabulary is split, judged by this rank's logit width rather than the rank
@@ -224,6 +255,11 @@ private:
* newly committed tokens only. Read only when the request carries a thinking budget. */
ReasoningCount think;
size_t think_seen = 0;
/* --draft-coupling: the linear draft's per-round states for the window the scheduler
* published, bound by set_mtp_couple and consumed by build_step. `couple_n` is how many of
* `couple` are live; 0 for a request whose drafts carry no coupled proposal. */
RadMtpCoupleState couple[RAD_MTP_COUPLE_MAX_ROUNDS]{};
int couple_n = 0;
};
/* Mask staged row `row` to the reasoning block's close token, once the budget is spent
@@ -253,6 +289,7 @@ private:
rad_op op_argmax_ = RAD_NULL_HANDLE;
rad_op op_allgather_ = RAD_NULL_HANDLE;
rad_op op_merge_ = RAD_NULL_HANDLE; /* the candidate merge, under tensor parallel */
rad_op op_couple_ = RAD_NULL_HANDLE; /* --draft-coupling only */
rad_op op_logprobs_ = RAD_NULL_HANDLE; /* summary of the raw distribution */
rad_op op_lp_gather_ = RAD_NULL_HANDLE; /* every rank's summary, under a split vocabulary */
@@ -272,6 +309,12 @@ private:
rad_buf buf_pairs_ = RAD_NULL_HANDLE; /* this rank's candidates as (global id, logit) */
rad_buf buf_lp_ = RAD_NULL_HANDLE; /* sample_logprobs' stats, [rows, lp_width()] */
rad_buf buf_lp_g_ = RAD_NULL_HANDLE; /* and every rank's side by side */
rad_buf buf_couple_ = RAD_NULL_HANDLE; /* [rows, RAD_MTP_COUPLE_STATE_WORDS], flag only */
RadMtpCoupleState* couple_stage_ = nullptr; /* pinned, one row per sampled position */
bool couple_ = false; /* --draft-coupling */
bool any_couple_ = false; /* does any row this step carry a bound state? */
CoupleBuild couple_build_{}; /* what the last build_step staged, for the evidence line */
int64_t couple_issued_step_ = -1; /* step whose verify op run() last issued */
/* Pinned staging, allocated once at declare. */
DeviceSampleParams* params_stage_ = nullptr;