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

223 lines
11 KiB
C++

/* Absorbed MLA: one latent vector is both the attention key and value. The
* per-query table already contains the selected complete pages plus its tail.
* `scale` comes from the original query/key head width, NOT the latent width. */
#include "ref_common.h"
#include "ref_ops.h"
#include <algorithm>
#include <cmath>
using namespace ref;
/* Both projections share the checkpoint's [head,(K|V),latent] matrix.
* Absorb: q @ Wk. Expand: attention_latent @ Wv^T. No per-head KV cache. */
int ref_mla_project(const RadArgs* a, RadStream) {
if (!have(a, 3)) return RAD_E_INVAL;
RadTensor x = a->t[0], y = a->t[2];
const auto& w = a->t[1];
const int64_t h = p_int(a, "heads", 0), d = p_int(a, "head_dim", 0),
l = p_int(a, "latent_dim", 0);
const char* mode = p_str(a, "mode", "");
const bool absorb = !std::strcmp(mode, "absorb"), expand = !std::strcmp(mode, "expand");
auto heads_view = [&](RadTensor& t, int64_t width) {
if (h > 0 && width > 0 && t.rank == 2 && t.shape[1] == h * width) {
t.rank = 3;
t.shape[1] = h;
t.shape[2] = width;
t.stride[2] = t.stride[1];
t.stride[1] *= width;
}
};
heads_view(x, absorb ? d : l);
heads_view(y, absorb ? l : d);
if ((!absorb && !expand) || h < 1 || d < 1 || l < 1 || x.rank != 3 || w.rank != 2 ||
y.rank != 3 || x.shape[0] < 1 || x.shape[1] != h || x.shape[2] != (absorb ? d : l) ||
w.shape[0] != h * 2 * d || w.shape[1] != l || y.shape[0] != x.shape[0] || y.shape[1] != h ||
y.shape[2] != (absorb ? l : d))
return RAD_E_SHAPE;
if (x.dtype != RAD_BF16 || w.dtype != RAD_BF16 || y.dtype != RAD_BF16) return RAD_E_DTYPE;
if (!x.data || !w.data || !y.data) return RAD_E_INVAL;
#pragma omp parallel for schedule(static)
for (int64_t r = 0; r < x.shape[0]; ++r)
for (int64_t head = 0; head < h; ++head)
for (int64_t col = 0; col < (absorb ? l : d); ++col) {
float sum = 0;
for (int64_t j = 0; j < (absorb ? d : l); ++j) {
const int64_t wr = head * 2 * d + (absorb ? j : d + col), wc = absorb ? col : j;
sum += ldt(&x, r * x.stride[0] + head * x.stride[1] + j * x.stride[2]) *
ldt(&w, wr * w.stride[0] + wc * w.stride[1]);
}
stt(&y, r * y.stride[0] + head * y.stride[1] + col * y.stride[2], sum);
}
return RAD_OK;
}
/* Dense causal latent attention over a paged cache whose token row is the normed latent followed
* by the rotated key part (Ling-3.0's MLA). A score is scale * (q . latent + q_rope . rope); the
* value is the latent. Sequences, positions and the causal bound follow attn_paged: sequence s
* owns query rows [cu[s], cu[s+1]), its context after this step is seqused[s], and row i of it
* sits at position seqused[s] - qlen + i and sees keys 0..position. With `gate` the rounded output
* is multiplied by the rounded sigmoid of the head's gate logit and rounded again. */
int ref_mla_attn_paged(const RadArgs* a, RadStream) {
/* q_rope (1) is required when rope_dim is nonzero, gate (6) is optional. */
if (a->n_t < 8 || !t_in(a, 0) || !t_in(a, 2) || !t_in(a, 3) || !t_in(a, 4) || !t_in(a, 5) ||
!t_in(a, 7))
return RAD_E_INVAL;
RadTensor q = a->t[0], qr = a->t[1], o = a->t[7];
const auto &kv = a->t[2], &bt = a->t[3], &su = a->t[4], &cu = a->t[5];
const RadTensor* gate = t_in(a, 6);
const int64_t h = p_int(a, "heads", 0), L = p_int(a, "latent_dim", 0),
R = p_int(a, "rope_dim", 0), bs = p_int(a, "block_size", 0);
const float scale = p_f32(a, "scale", 0);
auto heads_view = [&](RadTensor& t, int64_t width) {
if (h > 0 && width > 0 && t.rank == 2 && t.shape[1] == h * width) {
t.rank = 3;
t.shape[1] = h;
t.shape[2] = width;
t.stride[2] = t.stride[1];
t.stride[1] *= width;
}
};
heads_view(q, L);
heads_view(qr, R);
heads_view(o, L);
if (h < 1 || L < 1 || L > 2048 || R < 0 || bs < 1 || !std::isfinite(scale) || scale <= 0 ||
q.rank != 3 || q.shape[0] < 1 || q.shape[1] != h || q.shape[2] != L ||
(R && (qr.rank != 3 ||
qr.shape[0] != q.shape[0] || qr.shape[1] != h || qr.shape[2] != R)) || kv.rank != 4 ||
kv.shape[1] != 1 || kv.shape[2] != bs || kv.shape[3] < L + R || bt.rank != 2 ||
su.rank != 1 || cu.rank != 1 || numel(&cu) != numel(&su) + 1 || o.rank != 3 ||
o.shape[0] != q.shape[0] || o.shape[1] != h || o.shape[2] != L ||
(gate && (gate->rank != 2 || gate->shape[0] != q.shape[0] || gate->shape[1] < h)))
return RAD_E_SHAPE;
if (!q.data || (R && !qr.data) || !kv.data || !bt.data || !su.data || !cu.data || !o.data)
return RAD_E_INVAL;
const int64_t n_seq = numel(&su), rows = q.shape[0];
if (cu_at(&cu, 0) != 0 || cu_at(&cu, n_seq) != rows) return RAD_E_SHAPE;
#pragma omp parallel for schedule(dynamic)
for (int64_t job = 0; job < rows * h; ++job) {
const int64_t r = job / h, head = job % h;
const int64_t s = seq_of(&cu, n_seq, r);
const int64_t qlen = cu_at(&cu, s + 1) - cu_at(&cu, s), i = r - cu_at(&cu, s);
const int64_t ctx = ld_int(su.dtype, su.data, s * su.stride[0]);
const int64_t pos = ctx - qlen + i;
const int64_t live = std::min(pos + 1, bt.shape[1] * bs);
auto key_offset = [&](int64_t token) -> int64_t {
const int64_t page =
ld_int(bt.dtype, bt.data, s * bt.stride[0] + (token / bs) * bt.stride[1]);
return page < 0 || page >= kv.shape[0]
? -1
: page * kv.stride[0] + (token % bs) * kv.stride[2];
};
auto score = [&](int64_t base) -> float {
float v = 0;
for (int64_t c = 0; c < L; ++c)
v += ldt(&q, r * q.stride[0] + head * q.stride[1] + c * q.stride[2]) *
ldt(&kv, base + c * kv.stride[3]);
for (int64_t c = 0; c < R; ++c)
v += ldt(&qr, r * qr.stride[0] + head * qr.stride[1] + c * qr.stride[2]) *
ldt(&kv, base + (L + c) * kv.stride[3]);
return v * scale;
};
float max = -INFINITY;
for (int64_t j = 0; j < live; ++j) {
const auto base = key_offset(j);
if (base >= 0) max = std::max(max, score(base));
}
float val[2048] = {}, den = 0;
for (int64_t j = 0; j < live; ++j) {
const auto base = key_offset(j);
if (base < 0) continue;
const float w = std::exp(score(base) - max);
den += w;
for (int64_t c = 0; c < L; ++c) val[c] += w * ldt(&kv, base + c * kv.stride[3]);
}
const float g = gate ? round_dt(RAD_BF16, act_sigmoid(ldt(gate, r * gate->stride[0] +
head * gate->stride[1])))
: 1.0f;
for (int64_t c = 0; c < L; ++c) {
float v = den > 0 ? val[c] / den : 0;
if (gate) v = round_dt(RAD_BF16, v) * g;
stt(&o, r * o.stride[0] + head * o.stride[1] + c * o.stride[2], v);
}
}
return RAD_OK;
}
/* The two halves are parts of one latent vector, not separate attention K and V vectors.
* The i8 KV ABI puts their f16 scales after all D signed codes; base is a byte offset. */
static inline void mla_i8_scales(const RadTensor& kv, int64_t base, int64_t d, float (&s)[2]) {
uint16_t bits[2];
std::memcpy(bits, (const uint8_t*)kv.data + base + d, sizeof bits);
s[0] = rad_f16_to_f32(bits[0]);
s[1] = rad_f16_to_f32(bits[1]);
}
int ref_mla_attn(const RadArgs* a, RadStream) {
if (!have(a, 5)) return RAD_E_INVAL;
const auto &q = a->t[0], &kv = a->t[1], &bt = a->t[2], &len = a->t[3], &out = a->t[4];
const int64_t d = p_int(a, "latent_dim", 0), h = p_int(a, "heads", 0),
bs = p_int(a, "block_size", 0);
const float scale = p_f32(a, "scale", 0);
const bool i8 = kv.dtype == RAD_I8;
if (d < 1 || d > 2048 || h < 1 || bs < 1 || !std::isfinite(scale) || scale <= 0 ||
q.rank != 3 || q.shape[0] < 1 || q.shape[1] != h || q.shape[2] != d || kv.rank != 4 ||
kv.shape[1] != 1 || kv.shape[2] != bs || kv.shape[3] != d + (i8 ? 4 : 0) || bt.rank != 2 ||
bt.shape[0] != q.shape[0] || len.rank != 1 || len.shape[0] != q.shape[0] || out.rank != 3 ||
out.shape[0] != q.shape[0] || out.shape[1] != h || out.shape[2] != d ||
bt.dtype != RAD_I32 || len.dtype != RAD_I32)
return RAD_E_SHAPE;
if (i8 && d % 2) return RAD_E_SHAPE;
// Metadata is byte-addressed and contiguous after the codes. Row/page padding is legal.
if (i8 && (kv.stride[3] != 1 || kv.stride[2] < d + 4 ||
kv.stride[0] / bs < kv.stride[2]))
return RAD_E_STRIDE;
for (int i = 0; i < 5; ++i)
if (!a->t[i].data) return RAD_E_INVAL;
#pragma omp parallel for schedule(static)
for (int64_t job = 0; job < q.shape[0] * h; ++job) {
const int64_t r = job / h, head = job % h;
const int64_t live = std::clamp(ld_int(len.dtype, len.data, r * len.stride[0]), (int64_t)0,
bt.shape[1] * bs);
auto key_offset = [&](int64_t token) -> int64_t {
const int64_t page =
ld_int(bt.dtype, bt.data, r * bt.stride[0] + (token / bs) * bt.stride[1]);
return page < 0 || page >= kv.shape[0]
? -1
: page * kv.stride[0] + (token % bs) * kv.stride[2];
};
auto dot = [&](int64_t base) -> float {
float s[2] = {};
if (i8) mla_i8_scales(kv, base, d, s);
float v = 0;
for (int64_t c = 0; c < d; ++c) {
const float k = i8 ? (float)((const int8_t*)kv.data)[base + c] * s[c >= d / 2]
: ldt(&kv, base + c * kv.stride[3]);
v += ldt(&q, r * q.stride[0] + head * q.stride[1] + c * q.stride[2]) * k;
}
return v * scale;
};
float max = -INFINITY;
for (int64_t j = 0; j < live; ++j) {
const auto base = key_offset(j);
if (base >= 0) max = std::max(max, dot(base));
}
float val[2048] = {}, den = 0;
for (int64_t j = 0; j < live; ++j) {
const auto base = key_offset(j);
if (base < 0) continue;
const float w = std::exp(dot(base) - max);
den += w;
float s[2] = {};
if (i8) mla_i8_scales(kv, base, d, s);
for (int64_t c = 0; c < d; ++c) {
const float v = i8 ? (float)((const int8_t*)kv.data)[base + c] * s[c >= d / 2]
: ldt(&kv, base + c * kv.stride[3]);
val[c] += w * v;
}
}
for (int64_t c = 0; c < d; ++c)
stt(&out, r * out.stride[0] + head * out.stride[1] + c * out.stride[2],
den > 0 ? val[c] / den : 0);
}
return RAD_OK;
}