Archived
radiance 2.1.0
New models. Recursive Flint (39.8B, about 2.5B active) by everplays (#422): `arch/flint`, as an IQ8R container with rotated int8 experts or a four-bit one, with a sink-aware WMMA prefill attention and the fused attention prologue at `rotary_dim` 0. Meta Muse Glimmer 30B by launch80_assets (#423): bf16, an int4 trunk or IQ8R, its windowed vision tower, its DFlash drafter, the ATEM tool dialect and context extension. Ling-3.0-tiny by RikshaDriver (#441): served from its GGUF releases or as IQ8R on `bailing_hybrid`, with six more libr3d kernels. Block FP8, MXFP4 and NVFP4 conversions of the three are not served. IQ8R containers of all three (round to nearest, no calibration) are on Hugging Face under StillDeadcode: flint-iq8r, muse-glimmer-30b-iq8r-dflash and ling-3.0-tiny-iq8r. They were checked for sane answers on two R9700; nothing was benchmarked, and Muse Glimmer's pictures, video and tool calls were not tried. Speech. Breeze-TTS-2 clones a voice from a reference recording and its transcript, with an optional delivery direction, by farcryjohn (#436). The published Breeze container needs converting again with the updated recipe before it can. Tools. A model entry with `diagnose: DIR` runs a fixed workload on the engine instead of serving and writes a report: step times, tokens a step, draft acceptance, TTFT and prefill rates by category, concurrency and prompt length, and with `diagnose-baseline` a token-for-token comparison against an earlier report (docs/DIAGNOSE.md), by Code000 (#418). Scheduler. `mixed-step-target-ms` holds a mixed prefill and decode step to a service time, off by default, by tnhnyzc (#413). `scheduler.stuck-exit` (60s by default, 0 never) ends the process when the device has advanced nothing for that long, so a restart policy brings a hung server back (#409, #415, #428). Fixed. Draft trees with the int8 KV cache, which stopped Gemma 4 31B with DFlash2 on its first request (#454, diagnosed by aelfwyne). The expert loan held at zero by a few leftover cache blocks after long sessions (#455, diagnosed by thekk1). The mapped tier's pages kept in the page cache across a load and a restore, by C_Tamas (#421). Replayed tool calls with blank arguments, and arguments that are not JSON refused naming the call, by dschmitz (#444). The dashboard's card temperature reads the junction sensor, by dschmitz (#453). The VRAM shortfall report says what the KL mode needs, by baKon (#448). The out-of-tree plugin test builds its plugins in parallel and takes its toolchain from the tree. Plugin ABI 40: out-of-tree plugins need to be rebuilt. Thanks to @everplays, @launch80_assets, @RikshaDriver, @farcryjohn, @Code000, @tnhnyzc, @C_Tamas, @dschmitz, @baKon, @aelfwyne and @thekk1.
This commit is contained in:
1 parent
ddcb9c69bb
commit
2a2b756371
166 files changed
+20749
-327
No files matched your search
+247
-2
@@ -21,8 +21,139 @@
|
||||
|
||||
namespace {
|
||||
|
||||
__global__ void elu_f32_kernel(const float* x, float* y, int rows, int n, int xp, int yp) {
|
||||
const int i = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
if (i >= rows * n) return;
|
||||
const float v = x[(size_t)(i / n) * xp + i % n];
|
||||
y[(size_t)(i / n) * yp + i % n] = v >= 0 ? v : expm1f(v);
|
||||
}
|
||||
|
||||
/* One workgroup a frame, one thread a candidate at a time. Candidate ties reduce to the
|
||||
* lower index. The projected residual is only updated after every candidate has read it. */
|
||||
__global__ void vq_euclidean_kernel(float* x, const float* cb, int* codes, int n, int bins,
|
||||
int xp, int cp, int cs) {
|
||||
const int r = blockIdx.x, t = threadIdx.x;
|
||||
__shared__ float dist[256];
|
||||
__shared__ int pick[256];
|
||||
float best = INFINITY;
|
||||
int id = 0;
|
||||
for (int k = t; k < bins; k += 256) {
|
||||
float d = 0;
|
||||
for (int j = 0; j < n; ++j) {
|
||||
const float delta = x[(size_t)r * xp + j] - cb[(size_t)k * cp + j];
|
||||
d += delta * delta;
|
||||
}
|
||||
if (d < best) { best = d; id = k; }
|
||||
}
|
||||
dist[t] = best; pick[t] = id;
|
||||
__syncthreads();
|
||||
for (int s = 128; s; s /= 2) {
|
||||
if (t < s && (dist[t + s] < dist[t] ||
|
||||
(dist[t + s] == dist[t] && pick[t + s] < pick[t]))) {
|
||||
dist[t] = dist[t + s]; pick[t] = pick[t + s];
|
||||
}
|
||||
__syncthreads();
|
||||
}
|
||||
if (!t) codes[(size_t)r * cs] = pick[0];
|
||||
for (int j = t; j < n; j += 256)
|
||||
x[(size_t)r * xp + j] -= cb[(size_t)pick[0] * cp + j];
|
||||
}
|
||||
|
||||
constexpr int kT = 256;
|
||||
|
||||
/* Small f32 encoder primitives. The generator remains bf16; these keep the released
|
||||
* reference tokenizer in f32 instead of routing its transformer through a host fallback. */
|
||||
__device__ float encoder_sum(float v, float* buf) {
|
||||
const int t = threadIdx.x;
|
||||
buf[t] = v;
|
||||
__syncthreads();
|
||||
for (int s = 128; s; s /= 2) {
|
||||
if (t < s) buf[t] += buf[t + s];
|
||||
__syncthreads();
|
||||
}
|
||||
return buf[0];
|
||||
}
|
||||
|
||||
__global__ void encoder_layernorm(const float* x, const float* w, const float* bias,
|
||||
float* y, int n, int xp, int yp, float eps) {
|
||||
__shared__ float buf[256];
|
||||
const int r = blockIdx.x, t = threadIdx.x;
|
||||
float v = 0;
|
||||
for (int j = t; j < n; j += 256) v += x[(size_t)r * xp + j];
|
||||
const float mean = encoder_sum(v, buf) / n;
|
||||
__syncthreads();
|
||||
v = 0;
|
||||
for (int j = t; j < n; j += 256) {
|
||||
const float d = x[(size_t)r * xp + j] - mean;
|
||||
v += d * d;
|
||||
}
|
||||
const float inv = rsqrtf(encoder_sum(v, buf) / n + eps);
|
||||
__syncthreads();
|
||||
for (int j = t; j < n; j += 256)
|
||||
y[(size_t)r * yp + j] = (x[(size_t)r * xp + j] - mean) * inv * w[j] + (bias ? bias[j] : 0);
|
||||
}
|
||||
|
||||
__global__ void encoder_gelu(const float* x, float* y, int rows, int n, int xp, int yp) {
|
||||
const int i = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
if (i >= rows * n) return;
|
||||
const float v = x[(size_t)(i / n) * xp + i % n];
|
||||
y[(size_t)(i / n) * yp + i % n] = 0.5f * v * (1.0f + erff(v * 0.7071067811865475f));
|
||||
}
|
||||
|
||||
__global__ void encoder_rope(float* x, const int* positions, int heads, int pitch,
|
||||
float theta, float scale) {
|
||||
const int r = blockIdx.x;
|
||||
for (int k = threadIdx.x; k < heads * 32; k += 256) {
|
||||
const int h = k / 32, j = k % 32;
|
||||
float* row = x + (size_t)r * pitch + h * 64;
|
||||
const float angle = positions[r] / scale / powf(theta, (2.0f * j) / 64.0f);
|
||||
float sn, cs;
|
||||
sincosf(angle, &sn, &cs);
|
||||
const float a = row[j], b = row[j + 32];
|
||||
row[j] = a * cs - b * sn; row[j + 32] = a * sn + b * cs;
|
||||
}
|
||||
}
|
||||
|
||||
/* One workgroup a (query, head), <=512 keys. Only the reference encoder uses this f32
|
||||
* attention path; its sequence is at most 250 rows, so no quadratic global score plane. */
|
||||
__global__ void encoder_attn(const float* q, const float* k, const float* v, const int* cu,
|
||||
float* out, int heads, int qp, int kp, int vp, int op,
|
||||
int nseq, int div, int window, float scale) {
|
||||
__shared__ float score[512], reduce[256];
|
||||
const int r = blockIdx.x, h = blockIdx.y, t = threadIdx.x;
|
||||
int seq = 0;
|
||||
while (seq + 1 < nseq && cu[seq + 1] <= r * div) ++seq;
|
||||
const int first = max(cu[seq] / div, window > 0 ? r - window + 1 : 0);
|
||||
const int last = min(cu[seq + 1] / div, r + 1), count = last - first;
|
||||
if (count <= 0 || count > 512) return;
|
||||
float best = -INFINITY;
|
||||
for (int j = t; j < count; j += 256) {
|
||||
float dot = 0;
|
||||
for (int d = 0; d < 64; ++d)
|
||||
dot += q[(size_t)r * qp + h * 64 + d] * k[(size_t)(first + j) * kp + h * 64 + d];
|
||||
score[j] = dot * scale;
|
||||
best = fmaxf(best, score[j]);
|
||||
}
|
||||
reduce[t] = best;
|
||||
__syncthreads();
|
||||
for (int s = 128; s; s /= 2) {
|
||||
if (t < s) reduce[t] = fmaxf(reduce[t], reduce[t + s]);
|
||||
__syncthreads();
|
||||
}
|
||||
best = reduce[0];
|
||||
__syncthreads();
|
||||
float sum = 0;
|
||||
for (int j = t; j < count; j += 256) { score[j] = expf(score[j] - best); sum += score[j]; }
|
||||
const float denom = encoder_sum(sum, reduce);
|
||||
__syncthreads();
|
||||
if (t < 64) {
|
||||
float result = 0;
|
||||
for (int j = 0; j < count; ++j)
|
||||
result += score[j] / denom * v[(size_t)(first + j) * vp + h * 64 + t];
|
||||
out[(size_t)r * op + h * 64 + t] = result;
|
||||
}
|
||||
}
|
||||
|
||||
// A window entry's flags (RadAudioGenBatch, RAD_AGEN_F_*), as libref restates them.
|
||||
enum { kFirst = 1, kLast = 8, kJoin = 16 };
|
||||
|
||||
@@ -1334,6 +1465,119 @@ extern "C" int r4d_rad_conv_t1d(const RadArgs* a, RadStream s) {
|
||||
/* The f32 rows. The weight is the _f32 layout hooks' (tap-major for conv1d, phase-major with
|
||||
* ceil(k / stride) taps for conv_t1d). The column tile is the narrowest of 128, 64 and 32 that
|
||||
* covers cout in as few workgroups; fewer than 16 channels take the direct conv1d kernel. */
|
||||
extern "C" int r4d_rad_encoder_layernorm(const RadArgs* a, RadStream s) {
|
||||
const auto *x = r4d_opt(a, 0), *w = r4d_opt(a, 1), *b = r4d_opt(a, 2), *y = r4d_opt(a, 3);
|
||||
if (!x || !w || !y || !is_f32(x) || !is_f32(w) || !is_f32(y) || (b && !is_f32(b)))
|
||||
return R4D_NO(RAD_E_DTYPE);
|
||||
const long long n = r4d_geti_or(a, "n", 0);
|
||||
if (n < 1 || n > 4096 || r4d_numel(w) != n || (b && r4d_numel(b) != n)) return R4D_NO(RAD_E_SHAPE);
|
||||
long long rx = 0, ry = 0;
|
||||
const auto xp = r4d_rows_pitch(x, n, &rx), yp = r4d_rows_pitch(y, n, &ry);
|
||||
if (xp < 0 || yp < 0 || !r4d_contig(w) || (b && !r4d_contig(b))) return R4D_NO(RAD_E_STRIDE);
|
||||
const float eps = r4d_getf(a, "eps", 1e-5);
|
||||
if (ry < 1 || ry > 65535 || rx < ry || xp > 0x7fffffffll || yp > 0x7fffffffll || !(eps > 0))
|
||||
return R4D_NO(RAD_E_SHAPE);
|
||||
hipLaunchKernelGGL(encoder_layernorm, dim3((unsigned)ry), dim3(kT), 0, (hipStream_t)s,
|
||||
(const float*)x->data, (const float*)w->data, b ? (const float*)b->data : nullptr,
|
||||
(float*)y->data, (int)n, (int)xp, (int)yp, eps);
|
||||
return st_of(hipGetLastError());
|
||||
}
|
||||
|
||||
extern "C" int r4d_rad_encoder_gelu(const RadArgs* a, RadStream s) {
|
||||
const auto *x = r4d_opt(a, 0), *y = r4d_opt(a, 1);
|
||||
if (!x || !y || !is_f32(x) || !is_f32(y)) return R4D_NO(RAD_E_DTYPE);
|
||||
const long long n = r4d_geti_or(a, "n", 0);
|
||||
if (n < 1 || n > 0x7fffffffll) return R4D_NO(RAD_E_SHAPE);
|
||||
long long rx = 0, ry = 0;
|
||||
const auto xp = r4d_rows_pitch(x, n, &rx), yp = r4d_rows_pitch(y, n, &ry);
|
||||
if (xp < 0 || yp < 0) return R4D_NO(RAD_E_STRIDE);
|
||||
if (ry < 1 || rx < ry || ry > 0x7fffffffll / n || xp > 0x7fffffffll || yp > 0x7fffffffll)
|
||||
return R4D_NO(RAD_E_SHAPE);
|
||||
hipLaunchKernelGGL(encoder_gelu, dim3(blocks_for(ry * n)), dim3(kT), 0, (hipStream_t)s,
|
||||
(const float*)x->data, (float*)y->data, (int)ry, (int)n, (int)xp, (int)yp);
|
||||
return st_of(hipGetLastError());
|
||||
}
|
||||
|
||||
extern "C" int r4d_rad_encoder_rope(const RadArgs* a, RadStream s) {
|
||||
const auto *x = r4d_opt(a, 0), *p = r4d_opt(a, 1);
|
||||
if (!x || !p || !is_f32(x) || !is_i32(p)) return R4D_NO(RAD_E_DTYPE);
|
||||
const long long nh = r4d_geti_or(a, "n_head", 0), nk = r4d_geti_or(a, "n_head_kv", 0);
|
||||
const char* mode = r4d_gets(a, "mode");
|
||||
if (r4d_geti_or(a, "head_dim", 0) != 64 || r4d_geti_or(a, "rotary_dim", 64) != 64 ||
|
||||
nh < 1 || nh > 64 || nk != nh || !mode || std::strcmp(mode, "neox") || p->rank != 1 ||
|
||||
r4d_gets(a, "sections") || r4d_getf(a, "yarn_factor", 0) != 0 ||
|
||||
r4d_getf(a, "llama3_factor", 0) != 0) return R4D_NO(RAD_E_UNSUPPORTED);
|
||||
long long rx = 0;
|
||||
const auto xp = r4d_rows_pitch(x, 3 * nh * 64, &rx), rows = r4d_numel(p);
|
||||
if (xp < 0 || !r4d_contig(p)) return R4D_NO(RAD_E_STRIDE);
|
||||
const float theta = r4d_getf(a, "theta", 10000), scale = r4d_getf(a, "scale", 1);
|
||||
if (rows < 1 || rows > 65535 || rx < rows || xp > 0x7fffffffll || !(theta > 0) || !(scale > 0))
|
||||
return R4D_NO(RAD_E_SHAPE);
|
||||
hipLaunchKernelGGL(encoder_rope, dim3((unsigned)rows), dim3(kT), 0, (hipStream_t)s,
|
||||
(float*)x->data, (const int*)p->data, (int)(nh + nk), (int)xp, theta, scale);
|
||||
return st_of(hipGetLastError());
|
||||
}
|
||||
|
||||
extern "C" int r4d_rad_encoder_attn(const RadArgs* a, RadStream s) {
|
||||
const auto *q = r4d_opt(a, 0), *k = r4d_opt(a, 1), *v = r4d_opt(a, 2),
|
||||
*cu = r4d_opt(a, 3), *y = r4d_opt(a, 4);
|
||||
if (!q || !k || !v || !cu || !y || !is_f32(q) || !is_f32(k) || !is_f32(v) ||
|
||||
!is_f32(y) || !is_i32(cu)) return R4D_NO(RAD_E_DTYPE);
|
||||
if (r4d_geti_or(a, "head_dim", 0) != 64 || r4d_geti_or(a, "gqa", 1) != 1 ||
|
||||
r4d_geti_or(a, "causal", 0) != 1) return R4D_NO(RAD_E_UNSUPPORTED);
|
||||
const long long n = r4d_dim(q, (int)q->rank - 1), div = r4d_geti_or(a, "cu_div", 1);
|
||||
if (n < 64 || n % 64 || n > 4096 || div < 1 || div > 0x7fffffffll) return R4D_NO(RAD_E_SHAPE);
|
||||
long long rq = 0, rk = 0, rv = 0, ry = 0;
|
||||
const auto qp = r4d_rows_pitch(q, n, &rq), kp = r4d_rows_pitch(k, n, &rk),
|
||||
vp = r4d_rows_pitch(v, n, &rv), yp = r4d_rows_pitch(y, n, &ry);
|
||||
if (qp < 0 || kp < 0 || vp < 0 || yp < 0 || !r4d_contig(cu)) return R4D_NO(RAD_E_STRIDE);
|
||||
const auto ns = r4d_numel(cu) - 1, window = r4d_geti_or(a, "window", 0);
|
||||
if (ry < 1 || ry > 512 || rq < ry || rk < ry || rv < ry || ns < 1 || ns > 512 ||
|
||||
qp > 0x7fffffffll || kp > 0x7fffffffll || vp > 0x7fffffffll || yp > 0x7fffffffll ||
|
||||
window < 0 || window > 0x7fffffffll) return R4D_NO(RAD_E_SHAPE);
|
||||
hipLaunchKernelGGL(encoder_attn, dim3((unsigned)ry, (unsigned)(n / 64)), dim3(kT), 0,
|
||||
(hipStream_t)s, (const float*)q->data, (const float*)k->data, (const float*)v->data,
|
||||
(const int*)cu->data, (float*)y->data, (int)(n / 64), (int)qp, (int)kp, (int)vp, (int)yp,
|
||||
(int)ns, (int)div, (int)window, (float)r4d_getf(a, "scale", 0.125));
|
||||
return st_of(hipGetLastError());
|
||||
}
|
||||
|
||||
extern "C" int r4d_rad_elu(const RadArgs* a, RadStream s) {
|
||||
const RadTensor *x = r4d_opt(a, 0), *y = r4d_opt(a, 1);
|
||||
if (!x || !y || !is_f32(x) || !is_f32(y)) return R4D_NO(RAD_E_DTYPE);
|
||||
const long long n = r4d_geti_or(a, "n", 0);
|
||||
long long rx = 0, ry = 0;
|
||||
if (n <= 0) return R4D_NO(RAD_E_SHAPE);
|
||||
const long long xp = r4d_rows_pitch(x, n, &rx), yp = r4d_rows_pitch(y, n, &ry);
|
||||
if (xp < 0 || yp < 0) return R4D_NO(RAD_E_STRIDE);
|
||||
if (ry <= 0 || rx < ry || n > 0x7fffffffll || ry > 0x7fffffffll / n ||
|
||||
xp > 0x7fffffffll || yp > 0x7fffffffll) return R4D_NO(RAD_E_SHAPE);
|
||||
hipLaunchKernelGGL(elu_f32_kernel, dim3(blocks_for(ry * n)), dim3(kT), 0,
|
||||
(hipStream_t)s, (const float*)x->data, (float*)y->data,
|
||||
(int)ry, (int)n, (int)xp, (int)yp);
|
||||
return st_of(hipGetLastError());
|
||||
}
|
||||
|
||||
extern "C" int r4d_rad_vq_euclidean(const RadArgs* a, RadStream s) {
|
||||
const RadTensor *x = r4d_opt(a, 0), *cb = r4d_opt(a, 1), *c = r4d_opt(a, 2);
|
||||
if (!x || !cb || !c || !is_f32(x) || !is_f32(cb) || !is_i32(c))
|
||||
return R4D_NO(RAD_E_DTYPE);
|
||||
const long long n = r4d_geti_or(a, "n", 0), bins = r4d_geti_or(a, "bins", 0);
|
||||
if (n <= 0 || bins <= 0) return R4D_NO(RAD_E_SHAPE);
|
||||
long long rx = 0, rc = 0;
|
||||
const long long xp = r4d_rows_pitch(x, n, &rx), cp = r4d_rows_pitch(cb, n, &rc);
|
||||
if (xp < 0 || cp < 0) return R4D_NO(RAD_E_STRIDE);
|
||||
if (rx < 1 || rc != bins || r4d_numel(c) < rx || rx > 65535 || n > 4096 ||
|
||||
bins > 65536 || xp > 0x7fffffffll || cp > 0x7fffffffll)
|
||||
return R4D_NO(RAD_E_SHAPE);
|
||||
const long long cs = c->rank ? c->stride[c->rank - 1] : 1;
|
||||
if (cs < 1 || cs > 0x7fffffffll) return R4D_NO(RAD_E_STRIDE);
|
||||
hipLaunchKernelGGL(vq_euclidean_kernel, dim3((unsigned)rx), dim3(kT), 0,
|
||||
(hipStream_t)s, (float*)x->data, (const float*)cb->data,
|
||||
(int*)c->data, (int)n, (int)bins, (int)xp, (int)cp, (int)cs);
|
||||
return st_of(hipGetLastError());
|
||||
}
|
||||
|
||||
extern "C" int r4d_rad_conv1d_f32(const RadArgs* a, RadStream s) {
|
||||
const RadTensor *x = r4d_opt(a, 0), *w = r4d_opt(a, 1), *cu = r4d_opt(a, 2);
|
||||
const RadTensor *res = r4d_opt(a, 3), *y = r4d_opt(a, 4), *b = r4d_opt(a, 5);
|
||||
@@ -1348,8 +1592,9 @@ extern "C" int r4d_rad_conv1d_f32(const RadArgs* a, RadStream s) {
|
||||
const long long cd = r4d_geti_or(a, "cu_div", 1);
|
||||
const int act = conv1d_act(r4d_gets(a, "act"));
|
||||
if (act < 0) return R4D_NO(RAD_E_INVAL);
|
||||
/* The strided forms are bf16 only. */
|
||||
if (r4d_geti_or(a, "stride", 1) != 1 || r4d_geti_or(a, "pad", -1) >= 0)
|
||||
/* Explicit symmetric padding is still the bf16-only form. Causal strides share the
|
||||
* same loaders as stride 1 and retain each clip's own cu_div bounds. */
|
||||
if (r4d_geti_or(a, "pad", -1) >= 0)
|
||||
return R4D_NO(RAD_E_DTYPE);
|
||||
if (cin <= 0 || cout <= 0 || k <= 0 || (!causal && (k & 1) == 0) || dil <= 0 || causal < 0 ||
|
||||
causal > 1 || st < 1 || (st > 1 && (!causal || dil * (k - 1) + 1 < st)) || cd < 1)
|
||||
|
||||
Reference in new issue
Block a user