radiance 1.13.0

New models:
- Tencent Hy-Memory (HYV3) from its BF16, FP8 and GGUF checkpoints, with its native tool calls
- M2XFP4: metadata-augmented MXFP4 weights for Qwen3.8-27B and its DFlash2 drafter (top-1 89.1% ->
  92.4% against plain MXFP4), its quantiser and recipe, and ParoQuant's M2XFP4 checkpoints
- Gemma 4 E2B/E4B audio input; NVIDIA-Nemotron-3.5-Bolt-E4B in int8 and 4-bit, on two cards by
  default; Ornith-1.5-122B compose files

Speed:
- Weight reads beside the decode all-reduces (qwen35_fp8, gemma3; --weight-prefetch, on by default):
  the 27B MXFP4 with DFlash2 61.2 -> 67.9 tok/s at c1, TranslateGemma 27B +13%
- Head-256 split-KV decode attention at 256 workgroups and without bank conflicts (27B: +3-5% a
  step at 25-41K context), and the prefill KV split for small launches (a short turn over a long
  context decodes the other sequences 27% faster in that step)
- MXFP4 decode gate_up, activation and fp8 quantiser in one launch (27B, Gemma 3 up to 64 rows:
  TranslateGemma +2-5% at 2-8 streams)
- ParoQuant int4/int5 tiled GEMMs 6-9% faster
- Speculation: a step's tokens are sent before the drafter's passes end, no step waits behind one
  that ends its requests, and the MTP head's first draft no longer collapses after short chats in
  the prefix cache

Features:
- --kv-resident N: KV streaming for a context bigger than VRAM (qwen4exp_fp8, GLM-5.3)
- MiniMax-H3: reference media and keyframe conditioning with the VAE encoders
- Krea 2 rebalance presets balanced, detail and subtle
- The dashboard's request history; a stall watch that reports a frozen step's thread and stack
- rad-tune at the served configuration, collectives measured as the exchange; Gemma 4 E2B/E4B's
  per-layer embeddings read ahead off the step path
- A GPTQ calibration tap and recipe for Gemma 4 31B's w4a8 container

Fixes:
- The two-rank all-reduce checks that a peer's push has landed before reducing it
- z-lab's DFlash drafter on Gemma 4 31B keeps drafting after a prefix-cache hit
- MiniMax-H3's modulation rows

Changes: Plugin ABI 31: out-of-tree plugins must be rebuilt. RADIANCE_PREFETCH_BESIDE is
--weight-prefetch now; RADIANCE_NO_HUGE_PAGES, RADIANCE_IDS_EARLY, RADIANCE_ATTN_BAND_SPLIT,
R4D_PREFILL_SPLITS, RAD_PLE_TIMING and RAD_PLE_CACHE_ROWS are gone.
This commit is contained in:
Deadcode committed 2026-10-27 16:47:35 +01:00
198 files changed
+20904 -3240

No files matched your search

+45 -12
View File
@@ -1,6 +1,9 @@
/* kv.cpp -- see kv.h. */
#include "mem/kv.h"
#include "kvstream/carve.h"
#include "kvstream/plan.h"
#include <algorithm>
#include <cassert>
#include <cstring>
@@ -71,7 +74,7 @@ std::string BundleComparison::report() const {
/* ------------------------------------------------------------------ configure */
static const char* kv_kind_name(int k) {
const char* kv_kind_name(int k) {
switch (k) {
case RAD_KV_FULL: return "full";
case RAD_KV_WINDOW: return "window";
@@ -133,6 +136,7 @@ int KVManager::plan_groups(const std::vector<KVGroupInfo>& groups, const Config&
* other plan-path code has to know the kind. */
p.kind = g.decl.kind == RAD_KV_RING ? RAD_KV_WINDOW : g.decl.kind;
p.n_layers = (int64_t)g.layers.size();
p.dense_read = g.dense_read;
if (p.n_layers <= 0) {
RAD_ERR("KV group '%s': no layers are bound to it, so its page size is unknown "
@@ -309,8 +313,10 @@ int64_t KVManager::ceiling(int64_t ctx) const {
int64_t blocks = max_seqs_ * ((ctx + p.block_size - 1) / p.block_size);
if (p.kind == RAD_KV_WINDOW && !p.runtime_win && p.window_blocks > 0)
blocks = std::min(blocks, window_pool_cap(p));
need += blocks * p.bytes_per_block;
need += kv_ceiling_bytes(p, blocks, stream_.resident_blocks(p));
}
/* The streamed groups' maps come out of this pool too (kvstream/carve.h). */
need += kvstream_maps_charged(plans_, stream_, ctx, max_seqs_);
return need;
}
@@ -415,9 +421,15 @@ int64_t KVManager::paged_split(int64_t budget_bytes, std::vector<int64_t>* block
/* Zero groups take no part in the split; they get the shared table's block count, which is
* what the costed groups settle on here or, under the cap, on the ranks holding the cache. */
std::vector<int32_t> open, zeros;
for (const auto& p : plans_)
if (p.paged()) (p.zero ? zeros : open).push_back(p.index);
/* Every paged group zero: this rank limits nothing, so take the cap, or report unbounded. */
bool dense = false;
for (const auto& p : plans_) {
if (!p.paged()) continue;
if (p.zero) zeros.push_back(p.index);
else if (kvstream_dense(p, plans_, stream_)) dense = true; /* its carve is a floor */
else if (!stream_.windowed(p.index)) open.push_back(p.index);
}
kvstream_split_windows(plans_, stream_, max_ctx_, max_seqs_, &remaining, &out);
/* Every paged group is zero: this rank limits nothing, so take the cap, or report unbounded. */
if (open.empty() && !zeros.empty()) {
const int64_t tokens = tokens_cap_ > 0 ? tokens_cap_ : kUnboundedTokens;
if (blocks) {
@@ -453,6 +465,9 @@ int64_t KVManager::paged_split(int64_t budget_bytes, std::vector<int64_t>* block
}
for (int32_t i : open) out[i] = remaining > 0 ? tokens / plans_[i].block_size : 0;
for (int32_t i : zeros) out[i] = remaining > 0 ? zero_blocks(plans_[i], tokens) : 0;
/* A dense-read group's floor is already charged; with no other open group the pool still pages
* one full-length sequence, which is what the report and the admission cap see. */
if (dense && open.empty() && remaining > 0) tokens = max_ctx_;
if (blocks) *blocks = std::move(out);
return tokens;
}
@@ -486,8 +501,11 @@ int64_t KVManager::zero_blocks(const KVGroupPlan& p, int64_t tokens) const {
}
int KVManager::carve_into(Pool& kv_pool) {
/* The pool size is the resolver's; this only splits it between the groups. */
const int64_t budget_bytes = kv_pool.avail();
/* The pool size is the resolver's; this only splits it between the groups. The streamed
* groups' maps were reserved from it before the carve and paged_split() charges them, so they
* are added back here rather than charged twice. */
const int64_t budget_bytes = kv_pool.avail() +
kvstream_maps_charged(plans_, stream_, max_ctx_, max_seqs_);
const int64_t fixed = fixed_;
pool_base_ = kv_pool.base();
pool_ = &kv_pool;
@@ -505,11 +523,19 @@ int KVManager::carve_into(Pool& kv_pool) {
return RAD_E_NOMEM;
}
/* ---- the resident windows, before anything is split (kvstream/carve.h) ---- */
RAD_TRY(kvstream_window_fit(plans_, stream_, fixed, budget_bytes, max_ctx_, max_seqs_));
/* ---- the paged split; under a cap, the least rank's ---- */
std::vector<int64_t> blocks;
(void)paged_split(budget_bytes, &blocks);
for (auto& p : plans_) if (p.paged()) p.n_blocks = blocks[p.index];
/* How much of that the pool backs, and the refusal of an unbacked streamed plan. */
RAD_TRY(kvstream_apply(plans_, stream_, max_ctx_, max_seqs_));
/* A streamed group's `n_blocks` is its context, so this asks whether it can address anything,
* not whether its window is large enough. */
for (auto& p : plans_) {
if (!p.paged()) continue;
if (p.n_blocks <= 0 && p.zero) {
@@ -531,7 +557,7 @@ int KVManager::carve_into(Pool& kv_pool) {
/* ---- carve. Every reservation comes from the KV pool only; the mover works inside the
* weight slab and cannot reach it (spec §6). ---- */
for (auto& p : plans_) {
int64_t bytes = p.paged() ? p.n_blocks * p.bytes_per_block
int64_t bytes = p.paged() ? kv_pool_bytes(p)
: p.n_states * p.bytes_per_state;
if (p.zero) {
p.base = nullptr;
@@ -625,14 +651,16 @@ int KVManager::carve_into(Pool& kv_pool) {
return p.runtime_win ? "ring" : kv_kind_name(p.kind);
};
for (const auto& p : plans_) {
if (p.paged())
if (p.paged()) {
report_ += fmt(" %-14s %-6s %3lld layers block %4lld tok page %8s "
"%7lld blocks = %9s (%lld tokens)\n",
p.name.c_str(), kind_of(p), (long long)p.n_layers,
(long long)p.block_size, humanb(p.bytes_per_block).c_str(),
(long long)p.n_blocks, humanb(p.pool_bytes).c_str(),
(long long)(p.n_blocks * p.block_size));
else
if (p.streamed())
report_ += kvstream_report_line(p);
} else
report_ += fmt(" %-14s %-6s %3lld layers state %8s %7lld slots = %9s\n",
p.name.c_str(), kind_of(p), (long long)p.n_layers,
humanb(p.bytes_per_state).c_str(),
@@ -758,6 +786,9 @@ int64_t KVManager::total_blocks(int32_t g) const {
int64_t KVManager::live_blocks(int32_t g) const {
return (g >= 0 && g < (int32_t)live_.size()) ? live_[(size_t)g] : 0;
}
int64_t KVManager::held_top_blocks(int32_t g) const {
return (g >= 0 && g < (int32_t)plans_.size()) ? held_top((size_t)g) : 0;
}
/* The larger of one prefill chunk and the recent shortfall peak (see buffer_bytes in kv.h). */
int64_t KVManager::buf_blocks(size_t i) const {
@@ -786,8 +817,10 @@ int64_t KVManager::available_blocks(int32_t g) const {
bool KVManager::lendable(int32_t g) const {
const KVGroupPlan* p = plan(g);
/* A streamed group never lends: its pool is the ring, and a lent block would leave fewer
* slots than one launch's selection needs. */
return p && p->kind == RAD_KV_FULL && p->n_blocks > 0 && p->block_size > 0 &&
p->bytes_per_block > 0;
p->bytes_per_block > 0 && !p->streamed();
}
int64_t KVManager::lent_blocks(size_t i, int64_t tokens) const {
@@ -905,7 +938,7 @@ int64_t KVManager::pool_bytes(int32_t g) const {
int64_t KVManager::pool_bytes_carved(int32_t g) const {
const KVGroupPlan* p = plan(g);
if (!p) return 0;
if (p->paged()) return p->n_blocks * p->bytes_per_block;
if (p->paged()) return kv_pool_bytes(*p);
if (p->stateful()) return p->n_states * p->bytes_per_state;
return 0;
}
+57 -3
View File
@@ -20,6 +20,7 @@
* request by the other.
*/
#pragma once
#include "kvstream/mirror.h"
#include "mem/hostarena.h"
#include "mem/pools.h"
#include "rad_core.h"
@@ -54,6 +55,9 @@ struct BundleComparison {
};
BundleComparison compare_bundling(const std::vector<int64_t>& bundles);
/* A RAD_KV_* kind's name, for reports and refusals. */
const char* kv_kind_name(int kind);
/* ------------------------------------------------------------------ the runtime window */
/* A sequence's per-sequence window on a RAD_KV_WINDOW group, set at runtime (R-SWA, the
* "reference + ring" attention of Unlimited-OCR: a full causal prefill over the prompt and image
@@ -123,11 +127,25 @@ struct KVGroupPlan {
* snapshot would be read. */
bool win_snap = false;
int64_t n_blocks = 0; /* paged groups: blocks carved from the pool */
int64_t n_blocks = 0; /* paged groups: blocks the group addresses (its context) */
/* Paged groups: blocks the device pool backs, fewer than `n_blocks` when the group streams
* (docs/KV-STREAMING.md). Block ids stay dense over `n_blocks`: the allocator, refcounts, block
* table, prefix cache and every `id < n_blocks` guard count the context. Only addressing uses
* this: the pool and its layer stride are `n_slots` blocks deep, and the residency map turns a
* block into a slot. Equal to `n_blocks` otherwise. */
int64_t n_slots = 0;
/* Layer stripes the staged view presents: 0 means `n_layers` (the ring, and every group that
* does not stream), 1 means one stripe that every layer aliases. A depth rather than a
* rewritten `layer_slot`, which is also the host mirror's row (docs/KV-STREAMING.md §3.5.1). Set
* by carve() when the ring is smaller than the context. */
int64_t depth = 0;
/* rad_kv_group_zero: this rank keeps no cache for the group. The plan keeps its position and
* 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;
/* rad_kv_group_dense_read: read over the whole history every step, so it cannot stream; while a
* sibling streams its carve is a floor of max_seqs full contexts (kvstream/carve.h). */
bool dense_read = false;
/* rad_kv_group_replicated: every rank holds the same bytes, so a tier slot carries this
* group once, in a window at its front that rank 0 writes and every rank reads
* (TierExec::slot_layout). The pool is carved as for any group. */
@@ -147,13 +165,19 @@ struct KVGroupPlan {
bool paged() const { return kind == RAD_KV_FULL || kind == RAD_KV_WINDOW; }
bool stateful() const { return kind == RAD_KV_LINEAR || kind == RAD_KV_CONV; }
/* Blocks of device pool this group owns: `n_slots`, which is `n_blocks` unless the group
* streams. Every carve and stride goes through here; every allocation and guard uses
* `n_blocks`. */
int64_t pool_blocks() const { return n_slots > 0 ? n_slots : n_blocks; }
/* The pool holds fewer blocks than the group addresses; a residency map says which. */
bool streamed() const { return paged() && n_slots > 0 && n_slots < n_blocks; }
/* The pool is layer-major, as the ABI requires: a RAD_OPK_KV operand carries the layer as its
* offset and resolves to `base + layer * layer_stride` (RadOperand in rad_runtime.h,
* KVPoolBinding in core/runtime/ctx.h), so a kernel gets one base pointer per layer and
* indexes it with the block table and slot mapping.
*
* Layer i owns [base + i*layer_stride, + layer_stride): n_blocks blocks of
* Layer i owns [base + i*layer_stride, + layer_stride): pool_blocks() blocks of
* `bytes_per_block / n_layers` for a paged group, n_states states of
* `bytes_per_state / n_layers` for a stateful one. */
int64_t layer_bytes_per_block() const {
@@ -163,7 +187,8 @@ struct KVGroupPlan {
return n_layers > 0 ? bytes_per_state / n_layers : bytes_per_state;
}
int64_t layer_stride() const {
return paged() ? n_blocks * layer_bytes_per_block() : n_states * layer_bytes_per_state();
return paged() ? pool_blocks() * layer_bytes_per_block()
: n_states * layer_bytes_per_state();
}
};
@@ -224,6 +249,28 @@ public:
* because paged_split is monotone in the budget. */
int64_t pool_mib_for_tokens(int64_t tokens, int64_t max_mib) const;
void cap_paged_tokens(int64_t tokens) { tokens_cap_ = tokens > 0 ? tokens : 0; }
/* ---- KV streaming: KVStreamStore's state and lifecycle under the manager's names, so callers
* need not include kvstream/mirror.h, which documents each. */
using StreamMap = RadKVStream; /* the ABI's view: the mirror and the ring's maps */
using StreamCost = KVStreamCost;
using StreamStats = KVStreamStats;
void cap_resident_tokens(int32_t group, int64_t tokens) { stream_.cap(group, tokens); }
void set_stream_map(int32_t group, const StreamMap& m) { stream_.set_map(group, m); }
const StreamMap* stream_map(int32_t group) const { return stream_.map(group); }
const RadKVStream* stream_view(int32_t group) const {
return stream_.view(plan(group), group);
}
StreamCost stream_cost() const { return stream_.cost(plans_, max_ctx_, max_seqs_); }
int alloc_stream(MemAllocator& host_alloc, Pool& kv_pool) {
return stream_.alloc(plans_, max_ctx_, max_seqs_, host_alloc, kv_pool);
}
int init_stream(RadStream s) { return stream_.init(plans_, s); }
void free_stream(MemAllocator& host_alloc) { stream_.release(host_alloc); }
StreamStats stream_stats() const { return stream_.stats(plans_); }
void note_stream_traffic(int64_t misses, int64_t bytes) {
stream_.note_traffic(misses, bytes);
}
int carve(Pool& kv_pool);
const std::vector<KVGroupPlan>& plans() const { return plans_; }
@@ -368,6 +415,10 @@ public:
/* The carve: the range every block id is addressed against. live_blocks() is what the cache
* keeps unlent. */
int64_t total_blocks(int32_t group) const;
/* One past the highest held block, rounded up to a `held_hist_` bucket (0 when nothing is held):
* an upper bound on every id a block table can name, which a streamed group's stage copies up
* to (kvstream/stage.h). It counts blocks the prefix cache and other sequences hold too. */
int64_t held_top_blocks(int32_t group) const;
int64_t free_states(int32_t group) const;
/* Pool size in bytes, the only unit in which groups can be summed: paged and stateful groups
@@ -622,6 +673,9 @@ private:
int64_t fixed_ = 0; /* the non-negotiable floor: states, conv slots, padding */
int64_t ckpts_ = 0; /* --checkpoint-slots, kept for the warning on a model with none */
int64_t tokens_cap_ = 0; /* cap_paged_tokens(): the least any rank can carve; 0 is none */
/* KV streaming's state by group handle (kvstream/mirror.h); empty when nothing streams. */
KVStreamStore stream_;
/* declare_runtime_window(): group -> W. Survives forget(), which plan_groups() calls at its
* start: it is a declaration about the program, not about a plan. */
std::unordered_map<int32_t, int64_t> runtime_decl_;
+20 -4
View File
@@ -186,6 +186,15 @@ int PrefixCache::configure(const Config& cfg, KVManager* kv, int64_t checkpoint_
p.name.c_str(), (long long)p.block_size, (long long)block_size_);
}
/* An entry can be demoted only when the host tier can hold every group in it. A streamed
* group's rows are its pinned mirror, addressed by the block id the sequence used, so an entry
* holding one stays in VRAM and is evicted whole (docs/KV-STREAMING.md §4.1). */
demotable_ = true;
for (int32_t g : groups_) {
const KVGroupPlan* p = kv->plan(g);
if (p && p->streamed()) demotable_ = false;
}
interval_ = checkpoint_interval;
/* A window snapshot is state too: a hit is reusable only at a checkpoint, whose slot carries
* the window behind it (KVManager::has_window_snapshot). */
@@ -217,6 +226,11 @@ int PrefixCache::configure(const Config& cfg, KVManager* kv, int64_t checkpoint_
(long long)kv->checkpoint_slots(), humanb(kv->checkpoint_bytes()).c_str(),
policy_->name());
report_ += skipped;
if (!demotable_) {
/* Stated whether or not a host tier is configured. */
report_ += " a streamed group is cached, so no entry can be demoted to the host tier: a "
"streamed group's rows are its pinned mirror, addressed by block id\n";
}
return RAD_OK;
}
@@ -431,14 +445,15 @@ int PrefixCache::insert(uint64_t session,
* The ids come from the map, not from `blocks`. For an entry that already existed the loop
* above kept the cache's blocks, and `blocks` belongs to a sequence about to be freed; the
* tiers would copy from blocks reassigned to another sequence. */
if (tiers_) {
if (tiers_ && demotable_) {
for (int64_t b = 0; b < n_full; ++b) {
auto it = map_.find(hs[(size_t)b]);
if (it == map_.end()) continue;
tiers_->note_used(hs[(size_t)b], it->second.blocks, now, b);
}
tiers_->note_session(session, hs, n_tokens, now, label);
}
/* The session index names no blocks, so it is kept with or without a host copy. */
if (tiers_) tiers_->note_session(session, hs, n_tokens, now, label);
take_over(session, hs, n_full * block_size_);
return RAD_OK;
@@ -635,11 +650,12 @@ int64_t PrefixCache::trim_sparing(int64_t n_blocks,
it = next;
continue;
}
if (keep && !tiers_->droppable(h)) { ++it; continue; }
/* Skip an entry whose copy is still in flight; one the tier cannot hold never gets a copy. */
if (keep && demotable_ && !tiers_->droppable(h)) { ++it; continue; }
it = lru_.erase(it);
e.in_lru = false;
release_blocks(e);
if (keep) {
if (keep && demotable_) {
tiers_->drop_commit(h);
++stats_.drops;
} else {
+5
View File
@@ -205,6 +205,10 @@ public:
int64_t block_size() const { return block_size_; }
int64_t checkpoint_interval() const { return interval_; }
const std::vector<int32_t>& cached_groups() const { return groups_; }
/* Whether the host tier can hold this cache's entries. False when a cached group streams: its
* rows are addressed by the sequence's block ids, so entries stay in VRAM and are evicted
* whole (docs/KV-STREAMING.md §4.1). */
bool demotable() const { return demotable_; }
std::string report() const;
/* Overrides the policy configure() installed from Config::checkpoint_policy (custom policies,
@@ -461,6 +465,7 @@ private:
int64_t block_size_ = 0;
int64_t interval_ = 0;
std::vector<int32_t> groups_; /* paged groups this cache indexes */
bool demotable_ = false; /* the host tier can hold every group in an entry */
bool has_linear_ = false;
mutable std::unordered_map<BlockHash, Entry, BlockHashHash> map_;
+6
View File
@@ -239,6 +239,12 @@ static int resolve(Config& cfg, const std::vector<VramFacts>& per_rank, VramBudg
cfg.vram_weights_mib = to_mib_up(b.weights);
const int64_t w_over = cfg.vram_weights_mib * kMiB - b.weights;
cfg.vram_kv_mib = to_mib(std::max<int64_t>(b.kv - w_over, 0));
/* A streamed plan's maps are charged in kv_one but reserved outside the paged split, so the MiB
* truncation would leave the pool short of the one conversation kv_one was sized for. Under
* streaming kv_one is a requirement, so it is rounded up. */
if (cfg.kv_streams && kv_one > 0 &&
b.kv >= kv_one && cfg.vram_kv_mib * kMiB < kv_one)
cfg.vram_kv_mib = to_mib_up(kv_one);
/* A cache given its whole ceiling is rounded up to cover it, out of the headroom as the
* weights' MiB is: truncated, a ceiling under a MiB would be an empty pool and one just over a
* whole MiB a pool short of its own context. */