Files
Deadcode 3b13fd3266 radiance 2.3.0
New models. Thinking Machines' Inkling 2 Mini by gostar (#584-#586): its text backbone and loop, the
release's NVFP4 and MXFP8 checkpoint read by the converter, an int8 trunk, the vision tower, tensor
parallelism, tool calls (with Warzuponus) and an image processor that matches transformers bit for
bit (millaguie). Inkling's routed experts are served in IQR-V4's four-bit trellis (moe_gemm_iqr),
fitted by GPTQ against Hessians the plugin now records (`--calib-dir`), its token embedding in int8
(read in place by embed_lookup), and incoai's DFlash2 drafter in four bits in place of the release's
DSpark. That container, 14.4 GiB with the vision tower, decodes 190 / 427 / 658 tokens a second at 1
/ 4 / 8 streams at tp 2 on two R9700 with `draft-window: adaptive` (code 240 / 550 / 790,
step-by-step arithmetic 358 / 811 / 1116): 19-43% ahead of the same target with the release's DSpark
drafter and 45-83% ahead of the all-int8 container (26.1 GiB, 124 / 263 / 386), at a mean KL of
0.0066 against the release's weights (int8: 0.0042). DeepSeek-V4.1-Flash on 2.x by baKon (#583),
with its vision tower, its IQ1_S and IQ2_XXS containers and linears and experts served in
llama.cpp's own blocks; parts ported from mikoskinen/r9700-exact-serving by Dad_Vibes' fork.
GLM-5.3-Flash on 2.x with its IQR / IQ8R container, an int8 latent cache and four-card serving by
AnimusNull (#566). Gemma 4 dense on EXL3-V3 by keptn42 (#537), on the EXL3 dense rows and
qwen35_exl3 tensor parallelism by Hero422. NVIDIA's 2-bit Nemotron-3.5-Bolt-74B-A9B on one card by
keptn42 (#477). Wan 2.2 TI2V-5B text-to-video and first-frame video by rkcth (#535). LFM3-1.7B on
RDNA3 iGPUs by DokterSmol (#578). Qwen3.8-27B in bf16 with the DFlash2 drafter, and bf16x12, bf16
weights packed losslessly in 12.25 bits, by eddie168 (#577). Int8 experts for drama-3 by morevgalex
(#598).

Speculative decoding. Draft trees for Qwen3.8-27B's DFlash2 drafts by Kezi (#450, opt-in): one card,
+17% at one stream and +14% at two. --draft-max-lanes and --draft-min-accept, two gates on a block
drafter, and --draft-window-ckpt, its window KV kept in the checkpoint slots, by rkcth (#600-#602).
`draft-window: adaptive` verifies each sequence's drafts up to the first one unlikely to be kept. A
verify's rows share each K and V tile in Inkling's attention by gostar (#608): 93 to 118 tokens a
second at a 70k-token prompt on one card.

Generation. Krea 2 instruction edits with one or two references and registered outfill, LoRA on the
image generators with bias deltas and row-mixer adapters applied per request, and MiniMax-H3's
model-declared sparse attention profiles, by rkcth (#534, #542, #543, #605-#609). MiniMax-H3's audio
reference guide pinned from a frame by 1beb (#595). LTX-2's chunk ceiling raised to 40 by Itoash
(#570).

Fleets and memory. memory.queue-reserve, the hardware queues a card keeps ready, by kevinjd (#589).
memory.pinned-numa-node by Foundry (#580). memory.card-headroom-mib on single-model tensor-parallel
budgets by zihaomu (#624). Parked weights rebuilt on the CPU, memory ownership kept across a failed
handoff and quiescent callbacks serialised, by rkcth (#557-#561). A warm load may unload a parked
model (#592); the first card listed chooses the architecture (#458).

Kernels. libr3d's packed dense IQR GEMM and routed IQR expert rows on gfx1100, and libhalo's GEMV
decode for Qwen3.8-Flash-Next's MoE down, by zihaomu (#562, #620, #622). GGML IQ2_XXS and IQ3_XXS
packed on the card by baKon.

Dashboard. KV cache in tokens (in use, capacity now and with all flexible space), live figures
through long prefill steps, step / decode / prefill / acceptance lines without holes, and expert hit
rates only on tiered models. Seven tile and history defects fixed by Noblistic (#597), vision
encoder and per-card hardware figures by davetha (#574), per-LoRA attribution by dowjames (#552).

Fixed. return_tokens / return_token_ids on the OpenAI endpoints (#571). reasoning_effort "none" and
"minimal" reach a template that takes them as levels, by millaguie (#608). Misaligned loads in the
windowed paged attention over an int8 cache (#540). A retired 27B head refused by name (#541).
rad-convert's GPU trellis jobs kept fed, and --reuse-only, by gostar (#575). jinja's tojson takes
sort_keys by Warzuponus (#582). hfget measures file sizes with stat, by kepler_62f (#623). The
tested C++ compiler is stated in the build guide by lowell80 (#551). The codebase was cleaned up:
shared helpers instead of repeated blocks, and the int8 linear, activation and GEMM code no longer
named after the retired fp8 formats.

Inkling 2 Mini is served in one form: IQR-V4 experts with the DFlash2 drafter
(StillDeadcode/inkling-2-mini-iq4r-v4 on Hugging Face, or
data/recipes/inkling2-mini-iq4r-v4.recipe). A container with the release's DSpark drafter, or with
NVFP4, int8 or 4-bit experts, is refused by name and needs converting again.

Plugin ABI 44: out-of-tree plugins need to be rebuilt.

Thanks to @gostar, @baKon, @Dad_Vibes, @AnimusNull, @keptn42, @Hero422, @rkcth, @DokterSmol,
@eddie168, @morevgalex, @Kezi, @1beb, @Itoash, @kevinjd, @Foundry, @zihaomu, @Noblistic, @davetha,
@dowjames, @Warzuponus, @millaguie, @kepler_62f, @lowell80 and @Code000.
2026-11-26 15:28:37 +01:00

317 lines
14 KiB
C++

/* Manifold-constrained hyper-connections. The residual mixing matrix is indexed
* [source, destination]; transposing it leaves every shape valid and changes the model.
* The first Sinkhorn pass is softmax + eps, then column normalization. Later passes
* add eps to both denominators. These are separate operations from Qwen's hc_read/write. */
#include "ref_common.h"
#include "ref_ops.h"
#include <algorithm>
#include <cmath>
using namespace ref;
namespace {
bool matrix(const RadTensor& t, int64_t rows, int64_t cols) {
return t.data && t.rank == 2 && t.shape[0] == rows && t.shape[1] == cols;
}
}
namespace {
int64_t part_stride(int64_t hc) { return (hc * (hc + 2) + 1 + 3) / 4 * 4; }
bool pre_params(const RadArgs* a, int64_t* n, int64_t* hc, int64_t* iters, float* eps,
float* heps) {
*n = p_int(a, "n", 0);
*hc = p_int(a, "hc", 0);
*iters = p_int(a, "iterations", 0);
*eps = p_f32(a, "eps", 0);
*heps = p_f32(a, "hc_eps", 0);
return *n > 0 && *hc >= 2 && *hc <= 8 && *iters >= 1 && *iters <= 256 && std::isfinite(*eps) &&
std::isfinite(*heps) && *eps > 0 && *heps >= 0;
}
/* The outputs' shapes, shared by mhc_pre and mhc_pre_finish. */
bool pre_outputs(const RadTensor& h, const RadTensor& scale, const RadTensor& base,
const RadTensor& x, const RadTensor& post, const RadTensor& comb, int64_t rows,
int64_t n, int64_t hc) {
const int64_t mix = hc * (hc + 2);
return matrix(h, rows, hc * n) && scale.rank == 1 && scale.dtype == RAD_F32 &&
numel(&scale) == 3 && base.rank == 1 && base.dtype == RAD_F32 && numel(&base) == mix &&
matrix(x, rows, n) && matrix(post, rows, hc) && matrix(comb, rows, hc * hc) &&
post.dtype == RAD_F32 && comb.dtype == RAD_F32;
}
/* Row r from its RMS-scaled coefficients: gates, Sinkhorn mixing, and the collapse of h into `x`
* (mhc_pre) or the pre gates into `pre_out` (mhc_mix); either may be null. */
void finish_row(const float* coeff, const RadTensor& h, const RadTensor& scale,
const RadTensor& base, const RadTensor* x, const RadTensor& post,
const RadTensor& comb, int64_t r, int64_t n, int64_t hc, int64_t iters,
float heps, const RadTensor* pre_out = nullptr) {
float pre[8], c[64];
const int64_t hb = rowoff(&h, r, hc * n), hs = laststride(&h);
for (int64_t j = 0; j < hc; ++j) {
pre[j] =
1.0f / (1.0f +
std::exp(-(coeff[j] * ldt(&scale, 0) + ldt(&base, j * laststride(&base))))) +
heps;
const float z = coeff[hc + j] * ldt(&scale, laststride(&scale)) +
ldt(&base, (hc + j) * laststride(&base));
stt(&post, rowoff(&post, r, hc) + j * laststride(&post), 2.0f / (1.0f + std::exp(-z)));
}
for (int64_t j = 0; j < hc; ++j) {
float mx = -INFINITY;
for (int64_t k = 0; k < hc; ++k) {
const int64_t q = 2 * hc + j * hc + k;
c[j * hc + k] =
coeff[q] * ldt(&scale, 2 * laststride(&scale)) + ldt(&base, q * laststride(&base));
mx = std::max(mx, c[j * hc + k]);
}
float sum = 0;
for (int64_t k = 0; k < hc; ++k) {
c[j * hc + k] = std::exp(c[j * hc + k] - mx);
sum += c[j * hc + k];
}
for (int64_t k = 0; k < hc; ++k) c[j * hc + k] = c[j * hc + k] / sum + heps;
}
for (int64_t it = 0; it < iters; ++it) {
if (it)
for (int64_t j = 0; j < hc; ++j) {
float sum = 0;
for (int64_t k = 0; k < hc; ++k) sum += c[j * hc + k];
for (int64_t k = 0; k < hc; ++k) c[j * hc + k] /= sum + heps;
}
for (int64_t k = 0; k < hc; ++k) {
float sum = 0;
for (int64_t j = 0; j < hc; ++j) sum += c[j * hc + k];
for (int64_t j = 0; j < hc; ++j) c[j * hc + k] /= sum + heps;
}
}
const int64_t cb = rowoff(&comb, r, hc * hc), cs = laststride(&comb);
for (int64_t j = 0; j < hc * hc; ++j) stt(&comb, cb + j * cs, c[j]);
if (pre_out)
for (int64_t j = 0; j < hc; ++j)
stt(pre_out, rowoff(pre_out, r, hc) + j * laststride(pre_out), pre[j]);
if (!x) return;
const int64_t xb = rowoff(x, r, n), xs = laststride(x);
for (int64_t i = 0; i < n; ++i) {
float v = 0;
for (int64_t j = 0; j < hc; ++j) v += pre[j] * ldt(&h, hb + (j * n + i) * hs);
stt(x, xb + i * xs, v);
}
}
}
int ref_mhc_pre(const RadArgs* a, RadStream) {
if (!have(a, 7)) return RAD_E_INVAL;
int64_t n, hc, iters;
float eps, heps;
if (!pre_params(a, &n, &hc, &iters, &eps, &heps)) return RAD_E_SHAPE;
const auto &h = a->t[0], &fn = a->t[1], &scale = a->t[2], &base = a->t[3];
const auto &x = a->t[4], &post = a->t[5], &comb = a->t[6];
const int64_t width = hc * n, mix = hc * (hc + 2);
if (h.rank != 2) return RAD_E_SHAPE;
const int64_t rows = h.shape[0];
if (rows < 1 || !matrix(fn, mix, width) || fn.dtype != RAD_F32 ||
!pre_outputs(h, scale, base, x, post, comb, rows, n, hc))
return RAD_E_SHAPE;
#pragma omp parallel for schedule(static)
for (int64_t r = 0; r < rows; ++r) {
float coeff[80];
const int64_t hb = rowoff(&h, r, width), hs = laststride(&h);
float sq = 0;
for (int64_t i = 0; i < width; ++i) {
const float v = ldt(&h, hb + i * hs);
sq += v * v;
}
const float inv = 1.0f / std::sqrt(sq / (float)width + eps);
for (int64_t j = 0; j < mix; ++j) {
float dot = 0;
const int64_t fb = rowoff(&fn, j, width), fs = laststride(&fn);
for (int64_t i = 0; i < width; ++i) dot += ldt(&h, hb + i * hs) * ldt(&fn, fb + i * fs);
coeff[j] = dot * inv;
}
finish_row(coeff, h, scale, base, &x, post, comb, r, n, hc, iters, heps);
}
return RAD_OK;
}
int ref_mhc_pre_partial(const RadArgs* a, RadStream) {
if (!have(a, 3)) return RAD_E_INVAL;
const int64_t n = p_int(a, "n", 0), hc = p_int(a, "hc", 0), chunk = p_int(a, "chunk", 0);
const int64_t first = p_int(a, "first", -1), count = p_int(a, "chunks", 0);
if (n <= 0 || hc < 2 || hc > 8 || chunk <= 0 || (hc * n) % chunk || first < 0 || count < 1 ||
first + count > hc * n / chunk)
return RAD_E_SHAPE;
const auto &h = a->t[0], &fn = a->t[1], &part = a->t[2];
const int64_t width = hc * n, mix = hc * (hc + 2), S = part_stride(hc);
if (h.rank != 2) return RAD_E_SHAPE;
const int64_t rows = h.shape[0];
if (rows < 1 || !matrix(h, rows, width) || !matrix(fn, mix, width) || fn.dtype != RAD_F32 ||
!matrix(part, rows, count * S) || part.dtype != RAD_F32)
return RAD_E_SHAPE;
#pragma omp parallel for schedule(static)
for (int64_t r = 0; r < rows; ++r) {
const int64_t hb = rowoff(&h, r, width), hs = laststride(&h);
const int64_t pb = rowoff(&part, r, count * S), ps = laststride(&part);
for (int64_t c = 0; c < count; ++c) {
const int64_t lo = (first + c) * chunk;
for (int64_t j = 0; j < S; ++j) {
float sum = 0;
if (j < mix) {
const int64_t fb = rowoff(&fn, j, width), fs = laststride(&fn);
for (int64_t i = lo; i < lo + chunk; ++i)
sum += ldt(&h, hb + i * hs) * ldt(&fn, fb + i * fs);
} else if (j == mix) {
for (int64_t i = lo; i < lo + chunk; ++i) {
const float v = ldt(&h, hb + i * hs);
sum += v * v;
}
}
stt(&part, pb + (c * S + j) * ps, sum);
}
}
}
return RAD_OK;
}
int ref_mhc_pre_finish(const RadArgs* a, RadStream) {
if (!have(a, 7)) return RAD_E_INVAL;
int64_t n, hc, iters;
float eps, heps;
if (!pre_params(a, &n, &hc, &iters, &eps, &heps)) return RAD_E_SHAPE;
const int64_t chunk = p_int(a, "chunk", 0);
if (chunk <= 0 || (hc * n) % chunk) return RAD_E_SHAPE;
const auto &part = a->t[0], &h = a->t[1], &scale = a->t[2], &base = a->t[3];
const auto &x = a->t[4], &post = a->t[5], &comb = a->t[6];
const int64_t width = hc * n, mix = hc * (hc + 2), S = part_stride(hc), chunks = width / chunk;
if (h.rank != 2) return RAD_E_SHAPE;
const int64_t rows = h.shape[0];
if (rows < 1 || !matrix(part, rows, chunks * S) || part.dtype != RAD_F32 ||
!pre_outputs(h, scale, base, x, post, comb, rows, n, hc))
return RAD_E_SHAPE;
#pragma omp parallel for schedule(static)
for (int64_t r = 0; r < rows; ++r) {
float coeff[80];
const int64_t pb = rowoff(&part, r, chunks * S), ps = laststride(&part);
float sq = 0;
for (int64_t c = 0; c < chunks; ++c) sq += ldt(&part, pb + (c * S + mix) * ps);
const float inv = 1.0f / std::sqrt(sq / (float)width + eps);
for (int64_t j = 0; j < mix; ++j) {
float dot = 0;
for (int64_t c = 0; c < chunks; ++c) dot += ldt(&part, pb + (c * S + j) * ps);
coeff[j] = dot * inv;
}
finish_row(coeff, h, scale, base, &x, post, comb, r, n, hc, iters, heps);
}
return RAD_OK;
}
int ref_mhc_post(const RadArgs* a, RadStream) {
if (!have(a, 5)) return RAD_E_INVAL;
const int64_t n = p_int(a, "n", 0), hc = p_int(a, "hc", 0);
if (n <= 0 || hc < 2 || hc > 8) return RAD_E_SHAPE;
const auto &x = a->t[0], &h = a->t[1], &post = a->t[2], &comb = a->t[3], &out = a->t[4];
if (x.rank != 2) return RAD_E_SHAPE;
const int64_t rows = x.shape[0];
if (rows < 1 || !matrix(x, rows, n) || !matrix(h, rows, hc * n) || !matrix(post, rows, hc) ||
!matrix(comb, rows, hc * hc) || !matrix(out, rows, hc * n) || out.data == h.data ||
post.dtype != RAD_F32 || comb.dtype != RAD_F32)
return RAD_E_SHAPE;
#pragma omp parallel for schedule(static)
for (int64_t r = 0; r < rows; ++r) {
const int64_t hb = rowoff(&h, r, hc * n), cb = rowoff(&comb, r, hc * hc);
const int64_t pb = rowoff(&post, r, hc), xb = rowoff(&x, r, n);
const int64_t ob = rowoff(&out, r, hc * n);
for (int64_t k = 0; k < hc; ++k)
for (int64_t i = 0; i < n; ++i) {
float v = 0;
for (int64_t j = 0; j < hc; ++j)
v += ldt(&comb, cb + (j * hc + k) * laststride(&comb)) *
ldt(&h, hb + (j * n + i) * laststride(&h));
v += ldt(&post, pb + k * laststride(&post)) * ldt(&x, xb + i * laststride(&x));
stt(&out, ob + (k * n + i) * laststride(&out), v);
}
}
return RAD_OK;
}
int ref_mhc_contract(const RadArgs* a, RadStream) {
if (!have(a, 2)) return RAD_E_INVAL;
const int64_t n = p_int(a, "n", 0), hc = p_int(a, "hc", 0);
if (n <= 0 || hc < 2 || hc > 8) return RAD_E_SHAPE;
const auto &h = a->t[0], &x = a->t[1];
if (h.rank != 2 || h.shape[0] < 1 || !matrix(h, h.shape[0], hc * n) ||
!matrix(x, h.shape[0], n))
return RAD_E_SHAPE;
#pragma omp parallel for schedule(static)
for (int64_t r = 0; r < h.shape[0]; ++r)
for (int64_t i = 0; i < n; ++i) {
float v = 0;
for (int64_t j = 0; j < hc; ++j)
v += ldt(&h, rowoff(&h, r, hc * n) + (j * n + i) * laststride(&h));
stt(&x, rowoff(&x, r, n) + i * laststride(&x), v / (float)hc);
}
return RAD_OK;
}
/* mhc_pre without the collapse: the gates and mixing of the stream h, with `pre` written out for a
* later collapse (mhc_collapse). DeepSeek-V4.1 collapses each sublayer's input with the pre gates
* the PREVIOUS sublayer computed, so the two halves are separate ops there. */
int ref_mhc_mix(const RadArgs* a, RadStream) {
if (!have(a, 7)) return RAD_E_INVAL;
int64_t n, hc, iters;
float eps, heps;
if (!pre_params(a, &n, &hc, &iters, &eps, &heps)) return RAD_E_SHAPE;
const auto &h = a->t[0], &fn = a->t[1], &scale = a->t[2], &base = a->t[3];
const auto &pre = a->t[4], &post = a->t[5], &comb = a->t[6];
const int64_t width = hc * n, mix = hc * (hc + 2);
if (h.rank != 2) return RAD_E_SHAPE;
const int64_t rows = h.shape[0];
if (rows < 1 || !matrix(fn, mix, width) || fn.dtype != RAD_F32 || !matrix(pre, rows, hc) ||
pre.dtype != RAD_F32 || !matrix(h, rows, width) || scale.rank != 1 ||
scale.dtype != RAD_F32 || numel(&scale) != 3 || base.rank != 1 ||
base.dtype != RAD_F32 || numel(&base) != mix || !matrix(post, rows, hc) ||
!matrix(comb, rows, hc * hc) || post.dtype != RAD_F32 || comb.dtype != RAD_F32)
return RAD_E_SHAPE;
#pragma omp parallel for schedule(static)
for (int64_t r = 0; r < rows; ++r) {
float coeff[80];
const int64_t hb = rowoff(&h, r, width), hs = laststride(&h);
float sq = 0;
for (int64_t i = 0; i < width; ++i) {
const float v = ldt(&h, hb + i * hs);
sq += v * v;
}
const float inv = 1.0f / std::sqrt(sq / (float)width + eps);
for (int64_t j = 0; j < mix; ++j) {
float dot = 0;
const int64_t fb = rowoff(&fn, j, width), fs = laststride(&fn);
for (int64_t i = 0; i < width; ++i) dot += ldt(&h, hb + i * hs) * ldt(&fn, fb + i * fs);
coeff[j] = dot * inv;
}
finish_row(coeff, h, scale, base, nullptr, post, comb, r, n, hc, iters, heps, &pre);
}
return RAD_OK;
}
/* x[i] = sum over the hc streams of pre[s] * h[s, i], accumulated in f32 and rounded once. */
int ref_mhc_collapse(const RadArgs* a, RadStream) {
if (!have(a, 3)) return RAD_E_INVAL;
const int64_t n = p_int(a, "n", 0), hc = p_int(a, "hc", 0);
if (n <= 0 || hc < 2 || hc > 8) return RAD_E_SHAPE;
const auto &h = a->t[0], &pre = a->t[1], &x = a->t[2];
if (h.rank != 2 || h.shape[0] < 1 || !matrix(h, h.shape[0], hc * n) ||
!matrix(pre, h.shape[0], hc) || pre.dtype != RAD_F32 || !matrix(x, h.shape[0], n))
return RAD_E_SHAPE;
#pragma omp parallel for schedule(static)
for (int64_t r = 0; r < h.shape[0]; ++r)
for (int64_t i = 0; i < n; ++i) {
float v = 0;
for (int64_t j = 0; j < hc; ++j)
v += ldt(&pre, rowoff(&pre, r, hc) + j * laststride(&pre)) *
ldt(&h, rowoff(&h, r, hc * n) + (j * n + i) * laststride(&h));
stt(&x, rowoff(&x, r, n) + i * laststride(&x), v);
}
return RAD_OK;
}