Archived
New models and formats: - IQR for Qwen3.8-27B: weights on the int8 grid under GPTQ, a trellis down each GPTQ column (IQR-V2), and IQR-V3, a computed trellis code under one scale a row, kept at its codes' width in VRAM and decoded in the GEMM; 15 IQR-V3 recipes from ~2 to ~7 bits a weight (data/recipes/q38-27b-*-v3.recipe, docs/IQR.md) - libhalo: a kernel library for Strix Halo (gfx1151), preferred there over libr3d - Nemotron 3.5 Embed 1B and 8B (nemotron35_embed): text and image embeddings through a Pixtral tower, on the card and on the CPU - Nemotron 3.5 Rerank 8B - /v1/systemone: Cloudflare's clef and clef-flash, Convai Innovations' Laya and Mica beside LiquidAI d1; scored steps read the candidates' logits from the head table with no lm_head pass - LFM2's 8-bit trunk: block-fp8 or int8 linears with the fused producers, and the d1-3B recipe - DeepSeek-V4.1's reply format with DSML tool calls and typed argument tags Weights on the drive: - The file tier reads only the experts the pass routes rows to; the draft head's weights stay in the host pool - A hot VRAM cache for routed experts read off the drive, reads deposited straight into free host pool slots, and copyless evictions; the file tier's counters are now ssd_* - GLM-5 Next shards its routed experts by expert, not by width, so they can live on the drive - The stall watch counts drive reads as progress, and the DMA lane's room check reads the lane's own completion fence Quantisation tooling: - --calib-corpus, --calib-dir and --calib-layers record each linear's input Hessian; beside --kld-record the reference's own run records them - --kld-top N records a sparse KL reference (the N most likely tokens and the tail's mass) - GPTQ in a third of the time with the same codes, trellis GPTQ on the card, vector codebooks with coordinate descent, and rad-convert --reuse repeated, each container supplying what the earlier ones lack Speculation: - Prompt lookup alone (--spec-ngram K, --spec-ngram-min/-max): each sequence keeps an index of its n-grams, and a proposal is verified only when its measured step cost says it pays; --draft-window adaptive follows it Speed: - IQR decode: the narrow tile splits K for four times the int8 tile's waves and folds each 128-K block once; at 8 tokens down and the output projections run in 0.61-0.82x and 0.70-0.92x FP8's time (2-6 bits); IQ6R-S-V3 with its DFlash2 drafter steps in 26.3 ms at TP2, against 29.4 ms before and FP8's 27.3 - Qwen MXFP4 feed-forward: the gated fold up to 16 rows, not 8 - libr4d: the gated prefill fold, the short-prompt split row, and the rows forms of rmsnorm and rope; KLATE again for the head-256 gqa6 paged prefill; gram_accum on the matrix cores Features: - /health, /v1/health and /ping answer 503 with "status": "stuck" once the device has advanced nothing for a minute or a queue has faulted, so a supervisor can restart a wedged server (#356) - --image-gen-max-pixels and --image-gen-max-refs size an image generator's buffers (#344) - The startup report lists only the options not at their default, with a count; -v lists all (#250) - --preempt-wait-ms bounds how long a preempted prefill waits for its whole-recompute room - --placement layer_offload spills dense layers so one --max-model-len sequence fits - Startup refuses amdgpu with CWSR off and says how to fix it; --proceed-with-incompatible-configuration starts anyway under an UNSUPPORTED banner Fixes: - The n-gram read-ahead hands each row to the reader once and reads only as far ahead as the row cache holds, and pauses while decode reads: about one drive read a row instead of two (#355) - A file-tier window reads each of its runs once, not once a run per run - The decode split law's verify floor is bounded by the batch's workgroups: max_seqs 256 no longer declares 64x the scratch (#342) - A prefetch DMA list's mark stays out of the signal pool until the engine has read it, and a prefill stage copies only the blocks its own tables name (#343) - The split-KV row sum is read with fetch-inactive (#328) - LFM2 on the host backend: libref and libavx serve the row-form ops it declares (#348) - The preempted-prefill gate skips a KV group that holds no blocks (#352) - Every request entry point bounded, gated and sanitised (JSON depth, invalid UTF-8, control bytes in the log, the dashboard's CSP, cross-origin browsers on the loopback-only routes); a prompt id outside the vocabulary refused at admission; --api-key "" refused at startup - The telemetry the HTTP thread reads is atomic - An RMS norm row no longer depends on how many rows its launch carries; prefill attention's rescale is decided by live rows only - A --kld-record prefill chunk that finishes no sequence gets its logits on a tied-head model - A kernel's lazily made counter block is zeroed outside the lock other ranks take (a TP2 first-step hang) Changes: Plugin ABI 32. Every plugin exports a layout fingerprint of the ABI structs and the loader refuses a plugin without it or with another (#302), so out-of-tree plugins must be rebuilt. Appended: RadBuildCtx calib_* and gen_max_*, RadArchProbe gen_max_*, RadBatch score_only and plugin_words, RadDeviceProps::unified, RadChatFormat arg_json_value_prefix.
145 lines
7.2 KiB
Plaintext
145 lines
7.2 KiB
Plaintext
/* Derived from libr4d/r4d_gdn_gated_rmsnorm_h128_bf16.hip by the libhalo rename transform (2026-10-26),
|
|
* then ported to gfx1151; see libhalo/README.md. */
|
|
// halo_gdn_gated_rmsnorm_h128_bf16.hip -- the gated RMS norm a gated-delta-net layer applies to its own
|
|
// output before the output projection:
|
|
//
|
|
// out[r][d] = x[r][d] . rsqrt(mean_d(x[r][:]^2) + eps) . w[d] . act(z[r][d])
|
|
//
|
|
// one row per (token, head), 128 wide. Replaces FLA's `rmsnorm_fn` (mamba/ops/layernorm_gated).
|
|
//
|
|
// A separate kernel because the chunked scan's workgroup owns only 64 of a row's 128 v channels
|
|
// (BV=64; 128 would leave 24 workgroups on 64 CUs). The decode recurrent update owns whole rows and
|
|
// fuses this into its epilogue (halo_gdn_recurrent_update_k128_v128_bf16_fp32state.hip).
|
|
//
|
|
// One wave per row, four channels per lane: a barrier-free five-shuffle reduction, and one 8-byte
|
|
// access per lane for each load and the store.
|
|
#include <hip/hip_runtime.h>
|
|
#include "halo.h"
|
|
#include "halo_gdn_args.h"
|
|
#include "halo_common.h" // halo_wave_sum, bf16_to_f32 / f32_to_bf16
|
|
|
|
#define GN_D 128 // channels per row
|
|
#define GN_DPL 4 // channels per lane
|
|
#define GN_NW 8 // rows in flight per workgroup
|
|
|
|
__device__ __forceinline__ float gn_act(float z, int kind) {
|
|
const float s = 1.0f / (1.0f + __expf(-z));
|
|
return kind ? s : z * s; // 1 = sigmoid, 0 = silu / swish
|
|
}
|
|
|
|
template <int ACT>
|
|
__global__ __launch_bounds__(GN_NW * 32)
|
|
void halo_gdn_gated_rmsnorm_kernel(const unsigned short* __restrict__ x,
|
|
const unsigned short* __restrict__ z,
|
|
const float* __restrict__ w,
|
|
unsigned short* __restrict__ o,
|
|
long rows, long xrow, long zrow, long orow,
|
|
long zheads, long ztok, float eps)
|
|
{
|
|
const int lane = threadIdx.x & 31, warp = threadIdx.x >> 5;
|
|
const long r = (long)blockIdx.x * GN_NW + warp;
|
|
if (r >= rows) return;
|
|
const int d0 = lane * GN_DPL;
|
|
// The gate may be a column view of a fused [q|k|v|z] projection: within a token the `zheads`
|
|
// gate rows are `zrow` apart and the next token is `ztok` away. zheads <= 0 is the flat case.
|
|
const long zoff = zheads > 0 ? (r / zheads) * ztok + (r % zheads) * zrow : r * zrow;
|
|
|
|
const ushort4 xv = *(const ushort4*)(x + r * xrow + d0);
|
|
float v[GN_DPL] = {bf16_to_f32(xv.x), bf16_to_f32(xv.y), bf16_to_f32(xv.z),
|
|
bf16_to_f32(xv.w)};
|
|
|
|
float ss = 0.0f;
|
|
#pragma unroll
|
|
for (int c = 0; c < GN_DPL; ++c) ss += v[c] * v[c];
|
|
ss = halo_wave_sum(ss);
|
|
const float scale = __frsqrt_rn(ss * (1.0f / GN_D) + eps);
|
|
|
|
const ushort4 zv = *(const ushort4*)(z + zoff + d0);
|
|
const float zz[GN_DPL] = {bf16_to_f32(zv.x), bf16_to_f32(zv.y), bf16_to_f32(zv.z),
|
|
bf16_to_f32(zv.w)};
|
|
const float4 ww = *(const float4*)(w + d0);
|
|
const float wv[GN_DPL] = {ww.x, ww.y, ww.z, ww.w};
|
|
|
|
unsigned short out[GN_DPL];
|
|
#pragma unroll
|
|
for (int c = 0; c < GN_DPL; ++c)
|
|
out[c] = f32_to_bf16(v[c] * scale * wv[c] * gn_act(zz[c], ACT));
|
|
*(ushort4*)(o + r * orow + d0) = make_ushort4(out[0], out[1], out[2], out[3]);
|
|
}
|
|
|
|
extern "C" int halo_gdn_gated_rmsnorm_h128_bf16(const void* x, const void* z, const void* w,
|
|
void* o, long rows, long xrow, long zrow,
|
|
long orow, long zheads, long ztok, int width,
|
|
float eps, int act, void* stream)
|
|
{
|
|
if (width != GN_D) return -1;
|
|
dim3 grid((unsigned)((rows + GN_NW - 1) / GN_NW)), blk(GN_NW * 32);
|
|
if (act)
|
|
hipLaunchKernelGGL((halo_gdn_gated_rmsnorm_kernel<1>), grid, blk, 0, (hipStream_t)stream,
|
|
(const unsigned short*)x, (const unsigned short*)z, (const float*)w,
|
|
(unsigned short*)o, rows, xrow, zrow, orow, zheads, ztok, eps);
|
|
else
|
|
hipLaunchKernelGGL((halo_gdn_gated_rmsnorm_kernel<0>), grid, blk, 0, (hipStream_t)stream,
|
|
(const unsigned short*)x, (const unsigned short*)z, (const float*)w,
|
|
(unsigned short*)o, rows, xrow, zrow, orow, zheads, ztok, eps);
|
|
return (int)hipGetLastError();
|
|
}
|
|
|
|
// ============================================================== the plugin ABI entry points
|
|
// Shared operand helpers: halo_gdn_args.h.
|
|
/* ------------------------------------------------------------------ gated rms norm */
|
|
|
|
enum { GN_X = 0, GN_Z, GN_W, GN_O };
|
|
|
|
extern "C" int halo_rad_gdn_gated_rmsnorm(const RadArgs* a, RadStream s) {
|
|
const RadTensor* x = halo_opt(a, GN_X);
|
|
const RadTensor* z = halo_opt(a, GN_Z);
|
|
const RadTensor* w = halo_opt(a, GN_W);
|
|
const RadTensor* o = halo_opt(a, GN_O);
|
|
/* bf16 x, z, out; fp32 weight. */
|
|
HALO_DT(x, RAD_BF16); HALO_DT(z, RAD_BF16); HALO_DT(o, RAD_BF16); HALO_DT(w, RAD_F32);
|
|
if (!x || !z || !w || !o) return HALO_NO(RAD_E_INVAL);
|
|
if (x->rank < 2 || z->rank < 2 || o->rank < 2) return HALO_NO(RAD_E_SHAPE);
|
|
|
|
if (!halo_contig(w)) return HALO_NO(RAD_E_STRIDE);
|
|
|
|
/* One row is one (token, head). x and out are [tokens, heads, channels] (rank 3, as the chunk
|
|
* scan requires) while the gate may be the flat [tokens, heads*channels] projection. So the
|
|
* width comes from `channels` (or x's last axis), the row count from x, and each operand's
|
|
* pitch between consecutive (token, head) rows is read per its shape. */
|
|
const long long width = halo_geti_or(a, "channels", x->shape[x->rank - 1]);
|
|
if (width <= 0 || halo_numel(x) % width) return HALO_NO(RAD_E_SHAPE);
|
|
const long long rows = halo_numel(x) / width;
|
|
if (halo_numel(z) < rows * width || halo_numel(o) < rows * width) return HALO_NO(RAD_E_SHAPE);
|
|
|
|
const long long xrow = gn_row_pitch(x, width);
|
|
const long long orow = gn_row_pitch(o, width);
|
|
if (xrow < 0 || orow < 0) return HALO_NO(RAD_E_STRIDE);
|
|
|
|
/* The gate may also be a column slice of a wider [q|k|v|z] row (fp8 delta net): heads are
|
|
* `width` apart within a token and tokens are the slice's stride apart, so the kernel also
|
|
* takes the head count. zheads stays 0 for the flat layouts. */
|
|
long long zrow = gn_row_pitch(z, width), zheads = 0, ztok = 0;
|
|
if (zrow < 0 && z->rank == 2 && z->stride[1] == 1 && z->shape[1] % width == 0) {
|
|
zheads = z->shape[1] / width;
|
|
ztok = z->stride[0];
|
|
zrow = width;
|
|
/* The gate's head count must divide the row count and match x's head axis if it has one;
|
|
* a mismatch would silently interleave rows. */
|
|
if (zheads <= 0 || rows % zheads) return HALO_NO(RAD_E_SHAPE);
|
|
if (x->rank >= 3 && x->shape[x->rank - 2] != zheads) return HALO_NO(RAD_E_SHAPE);
|
|
}
|
|
if (zrow < 0) return HALO_NO(RAD_E_STRIDE);
|
|
|
|
const float eps = (float)halo_getf(a, "eps", 1e-6);
|
|
/* "silu" (0) or "sigmoid" (1). */
|
|
const int act = halo_act_code(a, "act", nullptr, -1);
|
|
if (act != 0 && act != 1) return HALO_NO(RAD_E_INVAL);
|
|
|
|
return HALO_RAW(halo_gdn_gated_rmsnorm_h128_bf16(x->data, z->data, w->data, o->data,
|
|
(long)rows, (long)xrow, (long)zrow,
|
|
(long)orow, (long)zheads, (long)ztok,
|
|
(int)width, eps, act, s));
|
|
}
|
|
|