Archived
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:
1 parent
d5b65cddc6
commit
dc339b4cd2
153 files changed
+12956
-1067
No files matched your search
@@ -8,6 +8,9 @@
|
||||
#include "ref_common.h"
|
||||
#include "ref_ops.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
using namespace ref;
|
||||
|
||||
/* Rows of a tensor read as [rows, n]. `n` is a declared parameter and the row count is whatever
|
||||
@@ -188,6 +191,68 @@ int ref_grid_embed(const RadArgs* a, RadStream) {
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* grid_embed_aa: the table resampled as torch's F.interpolate(mode="bilinear", align_corners=False,
|
||||
* antialias=True) does it -- SigLIP2's position embedding. Per axis a triangle filter on half-pixel
|
||||
* centres, widened by the scale when shrinking, its taps inside the table normalised to sum to one.
|
||||
* Separable, f32 throughout, rounded once before the add. A coordinate outside its grid is clamped
|
||||
* into it, so every input is defined. */
|
||||
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;
|
||||
}
|
||||
|
||||
int ref_grid_embed_aa(const RadArgs* a, RadStream) {
|
||||
if (!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);
|
||||
|
||||
#pragma omp parallel for schedule(static)
|
||||
for (int64_t r = 0; r < rows; ++r) {
|
||||
int64_t g[4];
|
||||
for (int c = 0; c < 4; ++c) g[c] = ld_int(crd->dtype, crd->data, c * cs + r * ms);
|
||||
std::vector<float> wh((size_t)side), ww((size_t)side);
|
||||
int64_t h0 = 0, nh = 0, w0 = 0, nw = 0;
|
||||
aa_taps(g[0], g[2], side, wh.data(), &h0, &nh);
|
||||
aa_taps(g[1], g[3], side, ww.data(), &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[(size_t)c];
|
||||
acc += row * wh[(size_t)y];
|
||||
}
|
||||
const float pe = round_to(x->dtype, acc);
|
||||
stt(x, xb + i * xs, ldt(x, xb + i * xs) + pe);
|
||||
}
|
||||
}
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ add / mul */
|
||||
/* Elementwise over the output's extent. `b` may carry one row instead of all of them, so a bias
|
||||
* add is this op rather than a second one: an operand with exactly `n` elements against an output
|
||||
|
||||
@@ -70,6 +70,7 @@ int ref_hc_write (const RadArgs*, RadStream);
|
||||
int ref_mtp_enter (const RadArgs*, RadStream);
|
||||
int ref_layernorm (const RadArgs*, RadStream);
|
||||
int ref_grid_embed (const RadArgs*, RadStream);
|
||||
int ref_grid_embed_aa (const RadArgs*, RadStream);
|
||||
int ref_add (const RadArgs*, RadStream);
|
||||
int ref_mul (const RadArgs*, RadStream);
|
||||
int ref_silu_mul (const RadArgs*, RadStream);
|
||||
@@ -92,6 +93,7 @@ int ref_scatter_rows (const RadArgs*, RadStream);
|
||||
int ref_ngram_ids (const RadArgs*, RadStream);
|
||||
int ref_ple_gate (const RadArgs*, RadStream);
|
||||
int ref_ple_conv (const RadArgs*, RadStream);
|
||||
int ref_causal_conv1d (const RadArgs*, RadStream);
|
||||
int ref_cast (const RadArgs*, RadStream);
|
||||
int ref_softmax (const RadArgs*, RadStream);
|
||||
|
||||
@@ -199,6 +201,7 @@ REF_SHAPE_FN(ref_hc_write);
|
||||
REF_SHAPE_FN(ref_mtp_enter);
|
||||
REF_SHAPE_FN(ref_layernorm);
|
||||
REF_SHAPE_FN(ref_grid_embed);
|
||||
REF_SHAPE_FN(ref_grid_embed_aa);
|
||||
REF_SHAPE_FN(ref_add);
|
||||
REF_SHAPE_FN(ref_mul);
|
||||
REF_SHAPE_FN(ref_silu_mul);
|
||||
@@ -221,6 +224,7 @@ REF_SHAPE_FN(ref_scatter_rows);
|
||||
REF_SHAPE_FN(ref_ngram_ids);
|
||||
REF_SHAPE_FN(ref_ple_gate);
|
||||
REF_SHAPE_FN(ref_ple_conv);
|
||||
REF_SHAPE_FN(ref_causal_conv1d);
|
||||
REF_SHAPE_FN(ref_cast);
|
||||
REF_SHAPE_FN(ref_softmax);
|
||||
|
||||
|
||||
+28
-14
@@ -219,19 +219,17 @@ int ref_ple_gate(const RadArgs* a, RadStream) {
|
||||
* several would hand a step that accepted only the first of them a history ending at a rejected
|
||||
* draft, and one that accepted two a slot nothing wrote.
|
||||
*/
|
||||
int ref_ple_conv(const RadArgs* a, RadStream) {
|
||||
/* NINE positions, four of them optional, so the count is checked and the optionals are tested
|
||||
* one by one -- `have()` would refuse the op for an absent operand that is allowed to be. */
|
||||
if (a->n_t < 9) return RAD_E_INVAL;
|
||||
const RadTensor* x = t_in(a, 0);
|
||||
const RadTensor* w = t_in(a, 1);
|
||||
const RadTensor* cs = t_in(a, 2);
|
||||
const RadTensor* cu = t_in(a, 3);
|
||||
const RadTensor* resid = t_in(a, 4); /* optional */
|
||||
const RadTensor* sidx = t_in(a, 5); /* optional */
|
||||
const RadTensor* hini = t_in(a, 6); /* optional */
|
||||
const RadTensor* nacc = t_in(a, 7); /* optional */
|
||||
const RadTensor* y = t_in(a, 8);
|
||||
/* THE DEPTHWISE CAUSAL CONVOLUTION AND ITS ROLLING WINDOW, shared by `ple_conv` (dilated, silu,
|
||||
* an optional residual) and `causal_conv1d` (LFM2's short convolution: undilated, no activation,
|
||||
* no residual). One body, so the two ops cannot disagree about the window's layout. */
|
||||
struct ConvArgs {
|
||||
const RadTensor *x, *w, *cs, *cu, *resid, *sidx, *hini, *nacc, *y;
|
||||
bool silu;
|
||||
};
|
||||
|
||||
static int depthwise_causal_conv(const RadArgs* a, const ConvArgs& 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);
|
||||
@@ -303,7 +301,7 @@ int ref_ple_conv(const RadArgs* a, RadStream) {
|
||||
acc += v * ldt(w, c * wrow + j * wcol);
|
||||
}
|
||||
const float r = resid ? ldt(resid, (bos + t) * rrow + c * rcol) : 0.0f;
|
||||
stt(y, (bos + t) * yrow + c * ycol, r + act_silu(acc));
|
||||
stt(y, (bos + t) * yrow + c * ycol, r + (o.silu ? act_silu(acc) : acc));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,3 +343,19 @@ int ref_ple_conv(const RadArgs* a, RadStream) {
|
||||
}
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
int ref_ple_conv(const RadArgs* a, RadStream) {
|
||||
/* NINE positions, four of them optional, so the count is checked and the optionals are tested
|
||||
* one by one -- `have()` would refuse the op for an absent operand that is allowed to be. */
|
||||
if (a->n_t < 9) return RAD_E_INVAL;
|
||||
return depthwise_causal_conv(a, { t_in(a, 0), t_in(a, 1), t_in(a, 2), t_in(a, 3), t_in(a, 4),
|
||||
t_in(a, 5), t_in(a, 6), t_in(a, 7), t_in(a, 8), true });
|
||||
}
|
||||
|
||||
/* ple_conv's operands without `resid`, at dilation one and with no activation. */
|
||||
int ref_causal_conv1d(const RadArgs* a, RadStream) {
|
||||
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, { t_in(a, 0), t_in(a, 1), t_in(a, 2), t_in(a, 3), nullptr,
|
||||
t_in(a, 4), t_in(a, 5), t_in(a, 6), t_in(a, 7), false });
|
||||
}
|
||||
@@ -124,6 +124,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") };
|
||||
@@ -655,6 +660,11 @@ static const RadOpSchema kSchemas[] = {
|
||||
"`coord` is [4, M] -- row, column, grid height, grid width -- and the position is sampled "
|
||||
"bilinearly with the grid's corners on the table's corners (align_corners), edge taps clamped. "
|
||||
"The taps are summed in f32 and rounded to x's dtype, then added to x and rounded again." },
|
||||
{ "grid_embed_aa", ARR(pGridEmbed), ARR(oGridEmbed),
|
||||
"x += the side x side table resampled as torch's F.interpolate(bilinear, align_corners=False, "
|
||||
"antialias=True) resamples it to the row's grid -- SigLIP2's position embedding: per axis a "
|
||||
"triangle filter on half-pixel centres, widened by the scale when shrinking, its in-table taps "
|
||||
"normalised. Separable, f32, rounded once before the add; coordinates clamp into their grid." },
|
||||
{ "add", ARR(pMnD), ARR(oBinary),
|
||||
"y = a + b. An operand carrying exactly n elements against a taller output broadcasts along "
|
||||
"rows; nothing else broadcasts." },
|
||||
@@ -723,6 +733,12 @@ static const RadOpSchema kSchemas[] = {
|
||||
"(width-1)*dilation - 1 slots plus one a token. Absent, every token commits: the read is at "
|
||||
"offset zero and the last (width-1)*dilation inputs land at offset zero, which is the prefill "
|
||||
"chunk. `resid` absent drops the add and leaves the plain convolution." },
|
||||
{ "causal_conv1d", ARR(pCausalConv), ARR(oCausalConv),
|
||||
"y[t] = sum_j w[c][j] * x[t - (width-1-j)], a DEPTHWISE CAUSAL convolution with no activation "
|
||||
"and no residual (LFM2's short convolution, whose gates the caller applies). The state, "
|
||||
"`has_init`, `cache_idx` and `num_accepted` are ple_conv's at dilation one: a window of width-1 "
|
||||
"values, read at `num_accepted - 1` and rewritten shifted by one with every input of a decode "
|
||||
"step behind it, or left as the chunk's last width-1 inputs when `num_accepted` is absent." },
|
||||
{ "ngram_ids", ARR(pNgramIds), ARR(oNgramIds),
|
||||
"ids[m][h] = remainder(hash of the n-gram ending at m, vocab_sizes[h]) + offsets[h], where "
|
||||
"hash = t0*mult[0] ^ t1*mult[1] ^ ... over as many shifted tokens as head h's block needs -- "
|
||||
@@ -1094,6 +1110,9 @@ SIMPLE("ref_layernorm", "layernorm", "norm", "layer norm with gain and bias", DT
|
||||
ref_layernorm),
|
||||
SIMPLE("ref_grid_embed", "grid_embed", "elem",
|
||||
"bilinear resample of a learned position grid, added in", DT_FLOAT, ref_grid_embed),
|
||||
SIMPLE("ref_grid_embed_aa", "grid_embed_aa", "elem",
|
||||
"antialiased half-pixel bilinear resample of a position grid, added in", DT_FLOAT,
|
||||
ref_grid_embed_aa),
|
||||
SIMPLE("ref_add", "add", "elem", "elementwise sum", DT_FLOAT, ref_add),
|
||||
SIMPLE("ref_mul", "mul", "elem", "elementwise product", DT_FLOAT, ref_mul),
|
||||
SIMPLE("ref_silu_mul", "silu_mul", "elem", "silu-gated product over a fused gate_up", DT_FLOAT,
|
||||
@@ -1126,6 +1145,8 @@ SIMPLE("ref_ple_gate", "ple_gate", "norm", "PLE gate: three grouped norms, a dot
|
||||
DT_FLOAT, ref_ple_gate),
|
||||
SIMPLE("ref_ple_conv", "ple_conv", "norm", "PLE's dilated depthwise conv, silu and residual add",
|
||||
DT_FLOAT, ref_ple_conv),
|
||||
SIMPLE("ref_causal_conv1d", "causal_conv1d", "conv", "depthwise causal conv, no activation",
|
||||
DT_FLOAT, ref_causal_conv1d),
|
||||
SIMPLE("ref_gather_rows", "gather_rows", "elem", "y[i,:] = x[idx[i],:]", DT_ANY, ref_gather_rows),
|
||||
SIMPLE("ref_scatter_rows", "scatter_rows", "elem", "x[idx[i],:] = v[i,:]", DT_ANY, ref_scatter_rows),
|
||||
SIMPLE("ref_cast", "cast", "elem", "dtype conversion", DT_ANY, ref_cast),
|
||||
@@ -1305,3 +1326,9 @@ extern "C" const RadKernelInfo* rad_kernel_at(int i) {
|
||||
if (i < 0 || i >= rad_kernel_count()) return nullptr;
|
||||
return &kKernels[i];
|
||||
}
|
||||
/* The rows that join the other ranks (ref_collective.cpp), said through the ABI
|
||||
* (RadKernelCollectiveFn) so the gather counts as one as well as the all-reduce. */
|
||||
extern "C" int rad_kernel_collective(int i) {
|
||||
const RadKernelInfo* k = rad_kernel_at(i);
|
||||
return k && k->init == ref_collective_init;
|
||||
}
|
||||
@@ -434,6 +434,18 @@ int ref_grid_embed_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* ou
|
||||
return o.finish("grid_embed", operand, out);
|
||||
}
|
||||
|
||||
/* grid_embed's operands; the coordinates are drawn over the table's side, as there. */
|
||||
int ref_grid_embed_aa_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const uint32_t D = act_dt(p, n_p);
|
||||
const int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0), side = gi(p, n_p, "side", 0);
|
||||
if (M <= 0 || n <= 0 || side <= 0) return RAD_E_UNSUPPORTED;
|
||||
Opd o;
|
||||
o.t(D, { M, n }); /* x, INOUT */
|
||||
o.t(D, { side * side, n }); /* table */
|
||||
o.t_idx({ 4, M }, side, -1, 0);
|
||||
return o.finish("grid_embed_aa", operand, out);
|
||||
}
|
||||
|
||||
int ref_layernorm_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const uint32_t D = act_dt(p, n_p);
|
||||
const int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0);
|
||||
@@ -721,6 +733,24 @@ int ref_ple_conv_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out)
|
||||
return o.finish("ple_conv", operand, out);
|
||||
}
|
||||
|
||||
/* ple_conv's description without `resid` and at dilation one. */
|
||||
int ref_causal_conv1d_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const uint32_t D = act_dt(p, n_p);
|
||||
const int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0), wid = gi(p, n_p, "width", 0);
|
||||
if (M <= 0 || n <= 0 || wid <= 0) return RAD_E_UNSUPPORTED;
|
||||
const int64_t S = 1, depth = wid - 2 + M;
|
||||
Opd o;
|
||||
o.t(D, { M, n }); /* x */
|
||||
o.t(D, { n, wid }); /* w */
|
||||
o.t(D, { S, n, depth }); /* conv_state, INOUT */
|
||||
o.t_idx({ S + 1 }, 0, -1, (uint32_t)RAD_OPD_F_IDX_CU); /* cu */
|
||||
o.t_idx({ S }, S, -1, (uint32_t)RAD_OPD_F_IDX_UNIQUE); /* cache_idx */
|
||||
o.t_idx({ S }, 0, 1, 0); /* has_init: warm */
|
||||
o.t_idx({ S }, 0, M, 0); /* num_accepted: read at M - 1 */
|
||||
o.t(D, { M, n }); /* y */
|
||||
return o.finish("causal_conv1d", operand, out);
|
||||
}
|
||||
|
||||
int ref_ngram_ids_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0);
|
||||
const int64_t heads = gi(p, n_p, "heads", 0);
|
||||
|
||||
Reference in new issue
Block a user