radiance 1.4.0

- Qwen3.8-Flash-Next on one card: the heat engine moves 64 experts a step (was 8), its copies and
  the prefill's expert staging run on the card's DMA engines instead of as copy kernels, and at
  decode the next layer's likeliest experts are copied onto the card ahead of its GEMMs. Against
  1.3.0 at --tp 1: prefill +17-20% from 8K tokens up, throughput under load +16-20%
- deploy/compose/flashnext-tp1.yaml: Qwen3.8-Flash-Next on one card and 64 GB of host RAM
  (4096-token prefill steps, 4 sequences, a 301K-token cache)
- #61: --busy-prefill-chunk (default auto): a long prefill leaves the rest of the step to the
  requests decoding beside it and to new arrivals, instead of taking all of it (baKon)
- LiquidAI's LFM2 and LFM2-VL, and d1's /v1/systemone (after zivius's PR #50)
- a startup report: every option with its value and where it came from, the hardware, and what
  on it costs speed with the fix; /diagnostics serves it (behind the API key; without one, only
  to the same machine)
- #69: a GPU memory fault names the buffer and kernel argument behind it and ends the server at
  once (exit status 70), instead of hanging or writing a core of tens of gigabytes
- #64: a card without Resizable BAR is refused at startup, naming what to turn on, instead of
  crashing at the first launch
- the image is built with ROCm 10.1 (the host's amdgpu driver must support it), with ROCm's
  libLLVM rebuilt so the same source compiles to the same kernels every time; a source build
  takes ROCm 10.1 or 7.2
- #71: the image ships curl, jq and a CA bundle, so --model <HF repo id> works in the container,
  and hfget.sh runs under its busybox (baKon)
- --profile-ops shows how long each op's lane sat idle before it; cardclock.py skips an
  integrated GPU instead of stopping
This commit is contained in:
Deadcode committed 2026-10-12 11:46:14 +02:00
1 parent d5b65cddc6
commit dc339b4cd2
153 files changed
+12956 -1067

No files matched your search

+5
View File
@@ -117,6 +117,7 @@ std::vector<Case> build_cases() {
HF("wadd", 1), HF("gate_eps", 1e-6) });
add("ple_conv", { HI("M", 9), HI("n", 128), HI("width", 4), HI("dilation", 2),
HS("dtype", dt) });
add("causal_conv1d", { HI("M", 9), HI("n", 128), HI("width", 3), HS("dtype", dt) });
}
add("ngram_ids", { HI("M", 9), HI("heads", 3), HI("ngram", 4), HI("eos", 2) });
@@ -309,6 +310,10 @@ std::vector<Case> build_cases() {
HF("theta", 10000.0), HF("scale", 1.0), HS("mode", "axial"),
HI("rotary_dim", 72), HS("sections", "18 18"), HS("dtype", dt) });
add("grid_embed", { HI("M", 20), HI("n", 72), HI("side", 6), HS("dtype", dt) });
/* Two table sides. A drawn grid is never larger than the table, so enlarging is
* avx_check's hand-built case. */
add("grid_embed_aa", { HI("M", 20), HI("n", 72), HI("side", 16), HS("dtype", dt) });
add("grid_embed_aa", { HI("M", 40), HI("n", 72), HI("side", 4), HS("dtype", dt) });
}
/* MoE. `a_order` exists because the two grouped GEMMs of one routed block disagree about it,
+25
View File
@@ -624,6 +624,31 @@ static bool hand_cases(const Lib& ref, const Lib& avx, bool verbose, int* n_chec
.pi("M", BAND).pi("n", N).pi("width", WIDTH).pi("dilation", DIL).ps("dtype", "f32");
hs.push_back(std::move(c));
/* LFM2's form of the same window: width 3, undilated, no residual and no activation. */
const int64_t CW = 3, CHIST = CW - 1, CSL = CHIST + 2;
Hand k("M = 64 over 5 rows, verifies of 3 and 2", "causal_conv1d", 1e-5);
k.dense(RAD_F32, { T, N }, hfill(55))
.dense(RAD_F32, { N, CW }, hfill(56, 0.5f))
.dense(RAD_F32, { 2, N, CSL }, hfill(57), true)
.idx({ 0, 3, 5 })
.idx({ 1, 0 })
.idx({ 7, 9 })
.idx({ 2, 3 })
.dense(RAD_F32, { T, N }, hfill(58), true)
.pi("M", BAND).pi("n", N).pi("width", CW).ps("dtype", "f32");
hs.push_back(std::move(k));
/* The antialiased resample ENLARGING a 4 x 4 table (a drawn case's grid is never larger
* than the table), one row shrinking it, and a 1 x 1 grid. */
static const int32_t kAaCrd[4][6] = { { 0, 6, 3, 1, 0, 5 }, { 0, 8, 4, 2, 0, 1 },
{ 7, 7, 7, 2, 1, 7 }, { 9, 9, 9, 3, 1, 9 } };
Hand ga("a 4 x 4 table onto 7 x 9, 2 x 3 and 1 x 1 grids", "grid_embed_aa", 1e-6);
ga.dense(RAD_F32, { 6, N }, hfill(59), true)
.dense(RAD_F32, { 16, N }, hfill(60))
.dense(RAD_I32, { 4, 6 }, [](int64_t i) { return (float)kAaCrd[i / 6][i % 6]; })
.pi("M", 6).pi("n", N).pi("side", 4).ps("dtype", "f32");
hs.push_back(std::move(ga));
Hand n("M = 64 over 5 rows, verifies of 3 and 2", "ngram_ids", 0.0);
n.idx({ 11, 12, 13, 21, 22 })
.dense(RAD_I32, { 2, 2 + 2 }, [](int64_t i) { return (float)(100 + i); }, true)
+1 -1
View File
@@ -86,7 +86,7 @@ int avx_isa_force(int level);
/* ---- elementwise and norms */ \
X(rmsnorm) X(rmsnorm_add) X(hc_enter) X(hc_read) \
X(hc_write) X(mtp_enter) X(layernorm) X(add) \
X(grid_embed) \
X(grid_embed) X(grid_embed_aa) X(causal_conv1d) \
X(mul) X(silu_mul) X(gelu) X(silu) \
X(sigmoid) X(gather_rows) X(scatter_rows) X(ngram_ids) \
X(ple_gate) X(ple_conv) X(cast) X(softmax) \
+27 -12
View File
@@ -176,17 +176,16 @@ AVX_KERNEL(ple_gate) {
* Absent, every token commits and the last (width-1)*dilation inputs land at offset zero. The
* write happens in a SECOND pass after every read is done, because a sequence longer than the
* window would otherwise overwrite history it is still reading. */
AVX_KERNEL(ple_conv) {
if (a->n_t < 9) return RAD_E_INVAL;
const RadTensor* x = rad_arg_in(a, 0);
const RadTensor* w = rad_arg_in(a, 1);
const RadTensor* cs = rad_arg_in(a, 2);
const RadTensor* cu = rad_arg_in(a, 3);
const RadTensor* resid = rad_arg_in(a, 4);
const RadTensor* sidx = rad_arg_in(a, 5);
const RadTensor* hini = rad_arg_in(a, 6);
const RadTensor* nacc = rad_arg_in(a, 7);
const RadTensor* y = rad_arg_in(a, 8);
/* ONE BODY FOR ple_conv AND causal_conv1d (LFM2's short convolution: undilated, no activation, no
* residual), as in libref, so the two cannot disagree about the window's layout. */
struct ConvOps {
const RadTensor *x, *w, *cs, *cu, *resid, *sidx, *hini, *nacc, *y;
bool silu;
};
static int depthwise_causal_conv(const RadArgs* a, const ConvOps& o) {
const RadTensor *x = o.x, *w = o.w, *cs = o.cs, *cu = o.cu, *resid = o.resid;
const RadTensor *sidx = o.sidx, *hini = o.hini, *nacc = o.nacc, *y = o.y;
if (!x || !w || !cs || !cu || !y) return RAD_E_INVAL;
const int64_t n = p_int(a, "n", 0);
@@ -260,7 +259,7 @@ AVX_KERNEL(ple_conv) {
acc += vv * tap[j];
}
const float r = resid ? ldt(resid, (bos + t) * rrow + c * rcol) : 0.0f;
stt(y, (bos + t) * yrow + c * ycol, r + acc / (1.0f + std::exp(-acc)));
stt(y, (bos + t) * yrow + c * ycol, r + (o.silu ? acc / (1.0f + std::exp(-acc)) : acc));
}
}
@@ -298,6 +297,22 @@ AVX_KERNEL(ple_conv) {
return RAD_OK;
}
AVX_KERNEL(ple_conv) {
if (a->n_t < 9) return RAD_E_INVAL;
return depthwise_causal_conv(a, { rad_arg_in(a, 0), rad_arg_in(a, 1), rad_arg_in(a, 2),
rad_arg_in(a, 3), rad_arg_in(a, 4), rad_arg_in(a, 5),
rad_arg_in(a, 6), rad_arg_in(a, 7), rad_arg_in(a, 8), true });
}
/* ple_conv's operands without `resid`, at dilation one and with no activation. */
AVX_KERNEL(causal_conv1d) {
if (a->n_t < 8) return RAD_E_INVAL;
if (p_int(a, "dilation", 1) != 1) return RAD_E_INVAL;
return depthwise_causal_conv(a, { rad_arg_in(a, 0), rad_arg_in(a, 1), rad_arg_in(a, 2),
rad_arg_in(a, 3), nullptr, rad_arg_in(a, 4),
rad_arg_in(a, 5), rad_arg_in(a, 6), rad_arg_in(a, 7), false });
}
/* ------------------------------------------------------------------ ngram_ids
*
* ids[m][h] = (hash of the n-gram ending at m) % vocab[h] + offset[h].
+64
View File
@@ -284,3 +284,67 @@ AVX_KERNEL(grid_embed) {
}
return RAD_OK;
}
/* ------------------------------------------------------------------ grid_embed_aa */
/* The table resampled as torch's F.interpolate(bilinear, align_corners=False, antialias=True) does
* it -- SigLIP2's position embedding -- and added in: libref's grid_embed_aa, operation for
* operation. Per axis a triangle filter on half-pixel centres, widened by the scale when
* shrinking, its taps inside the table normalised; the rows summed first, f32, rounded once
* before the add. A coordinate outside its grid is clamped into it. */
static void aa_taps(int64_t at, int64_t size, int64_t side, float* w, int64_t* lo, int64_t* cnt) {
if (size < 1) size = 1;
at = at < 0 ? 0 : (at >= size ? size - 1 : at);
const float scale = (float)side / (float)size;
const float support = scale > 1.0f ? scale : 1.0f, inv = 1.0f / support;
const float center = scale * ((float)at + 0.5f);
int64_t a = (int64_t)(center - support + 0.5f), b = (int64_t)(center + support + 0.5f);
if (a < 0) a = 0;
if (b > side) b = side;
float total = 0.0f;
for (int64_t j = a; j < b; ++j) {
const float d = std::fabs(((float)j - center + 0.5f) * inv);
w[j - a] = d < 1.0f ? 1.0f - d : 0.0f;
total += w[j - a];
}
for (int64_t j = a; j < b; ++j) w[j - a] = total != 0.0f ? w[j - a] / total : 0.0f;
*lo = a;
*cnt = b > a ? b - a : 0;
}
AVX_KERNEL(grid_embed_aa) {
if (!rad_args_have(a, 3)) return RAD_E_INVAL;
const RadTensor *x = &a->t[0], *tab = &a->t[1], *crd = &a->t[2];
const int64_t n = p_int(a, "n", tab->rank ? tab->shape[tab->rank - 1] : 0);
const int64_t side = p_int(a, "side", 0);
if (n <= 0 || side <= 0 || numel(tab) < side * side * n) return RAD_E_SHAPE;
const int64_t rows = rows_of(x, n);
if (rows <= 0 || crd->rank != 2 || crd->shape[0] < 4 || crd->shape[1] < rows)
return RAD_E_SHAPE;
const int64_t cs = crd->stride[0], ms = crd->stride[1];
const int64_t ts = laststride(tab);
AVX_PARALLEL_FOR_IF(rows * n >= AVX_PAR_MIN)
for (int64_t r = 0; r < rows; ++r) {
int64_t g[4];
for (int c = 0; c < 4; ++c) g[c] = ldi(crd, c * cs + r * ms);
float* wh = scratch_f32((size_t)(2 * side));
float* ww = wh + side;
int64_t h0 = 0, nh = 0, w0 = 0, nw = 0;
aa_taps(g[0], g[2], side, wh, &h0, &nh);
aa_taps(g[1], g[3], side, ww, &w0, &nw);
const int64_t xb = rowoff(x, r, n), xs = laststride(x);
for (int64_t i = 0; i < n; ++i) {
float acc = 0.0f;
for (int64_t y = 0; y < nh; ++y) {
float row = 0.0f;
for (int64_t c = 0; c < nw; ++c)
row += ldt(tab, rowoff(tab, (h0 + y) * side + w0 + c, n) + i * ts) * ww[c];
acc += row * wh[y];
}
float pe = acc;
if (x->dtype == RAD_BF16) pe = rad_bf16_to_f32(rad_f32_to_bf16(pe));
stt(x, xb + i * xs, ldt(x, xb + i * xs) + pe);
}
}
return RAD_OK;
}
+14
View File
@@ -109,6 +109,11 @@ static const RadParamSpec pPleConv[] = { P_INT("M"), P_INT("n"), P_INT("width"
static const RadOperandSpec oPleConv[] = { OPD("x"), WGT("w"), INOUT("conv_state"), OPD("cu"),
OPD_O("resid"), OPD_O("cache_idx"), OPD_O("has_init"),
OPD_O("num_accepted"), OUT("y") };
static const RadParamSpec pCausalConv[] = { P_INT("M"), P_INT("n"), P_INT("width"),
P_STR("dtype") };
static const RadOperandSpec oCausalConv[] = { OPD("x"), WGT("w"), INOUT("conv_state"), OPD("cu"),
OPD_O("cache_idx"), OPD_O("has_init"),
OPD_O("num_accepted"), OUT("y") };
static const RadParamSpec pHcWrite[] = { P_INT("M"), P_INT("n"), P_INT("hc"), P_STR("dtype") };
static const RadOperandSpec oHcEnter[] = { OPD("x"), OUT("h") };
@@ -495,6 +500,8 @@ static const RadOpSchema kSchemas[] = {
{ "layernorm", ARR(pLayernorm), ARR(oLayernorm), "layer norm with gain and optional bias." },
{ "grid_embed", ARR(pGridEmbed), ARR(oGridEmbed),
"x += a side x side position table resampled bilinearly to the row's grid." },
{ "grid_embed_aa", ARR(pGridEmbed), ARR(oGridEmbed),
"x += the table resampled as torch's antialiased half-pixel bilinear, SigLIP2's." },
{ "add", ARR(pMnD), ARR(oBinary), "elementwise sum." },
{ "mul", ARR(pMnD), ARR(oBinary),
"elementwise product; `b` may have extent 1 on any axis `a` does not and is broadcast along it." },
@@ -525,6 +532,8 @@ static const RadOpSchema kSchemas[] = {
"PLE gate: three grouped norms, a dot, a signed sqrt." },
{ "ple_conv", ARR(pPleConv), ARR(oPleConv),
"PLE's dilated depthwise conv, silu and residual add." },
{ "causal_conv1d", ARR(pCausalConv), ARR(oCausalConv),
"depthwise causal conv with ple_conv's window, no activation and no residual (LFM2)." },
{ "ngram_ids", ARR(pNgramIds), ARR(oNgramIds), "hashed n-gram row ids for PLE." },
{ "gather_rows", ARR(pMnD), ARR(oGather), "y[i,:] = x[idx[i],:]." },
{ "scatter_rows", ARR(pMnD), ARR(oScatterRows),
@@ -697,6 +706,9 @@ SIMPLE("avx_layernorm", "layernorm", "norm", "layer norm with gain and bias", DT
L(layernorm)),
SIMPLE("avx_grid_embed", "grid_embed", "elem",
"bilinear resample of a learned position grid, added in", DT_FLOAT, L(grid_embed)),
SIMPLE("avx_grid_embed_aa", "grid_embed_aa", "elem",
"antialiased half-pixel bilinear resample of a position grid, added in", DT_FLOAT,
L(grid_embed_aa)),
SIMPLE("avx_add", "add", "elem", "elementwise sum", DT_FLOAT, L(add)),
SIMPLE("avx_mul", "mul", "elem", "elementwise product, broadcasting b", DT_FLOAT, L(mul)),
SIMPLE("avx_act_mul", "act_mul", "elem", "act(a) * b over two operands", DT_FLOAT, L(act_mul)),
@@ -732,6 +744,8 @@ SIMPLE("avx_ple_gate", "ple_gate", "norm", "PLE gate: three grouped norms, a dot
DT_FLOAT, L(ple_gate)),
SIMPLE("avx_ple_conv", "ple_conv", "norm", "PLE's dilated depthwise conv, silu and residual add",
DT_FLOAT, L(ple_conv)),
SIMPLE("avx_causal_conv1d", "causal_conv1d", "conv", "depthwise causal conv, no activation",
DT_FLOAT, L(causal_conv1d)),
SIMPLE("avx_cast", "cast", "elem", "dtype conversion", DT_ANY, L(cast)),
SIMPLE("avx_softmax", "softmax", "elem", "row-wise softmax", DT_FLOAT, L(softmax)),
SIMPLE("avx_scale_rows", "scale_rows", "elem", "one scalar per row, broadcast across the row",