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.
243 lines
13 KiB
Plaintext
243 lines
13 KiB
Plaintext
/* Derived from libr4d/r4d_ple_conv_bf16.hip by the libhalo rename transform (2026-10-26),
|
|
* then ported to gfx1151; see libhalo/README.md. */
|
|
// halo_ple_conv_bf16.hip -- Per-Layer Embedding's dilated depthwise convolution, its silu, and the
|
|
// residual add that finishes the layer; and, as `causal_conv1d`, the same convolution with no
|
|
// activation, no residual and no dilation, which is LFM2's short convolution.
|
|
//
|
|
// y[t][c] = resid[t][c] + silu( sum_j w[c][j] * x[t - (width-1-j)*dilation][c] )
|
|
//
|
|
// libref/ref_ple.cpp is the oracle and docs/OPS.md the contract. The taps are `dilation` apart, so
|
|
// at width 4 and dilation 3 they sit 9, 6, 3 and 0 timesteps back and a sequence carries a history
|
|
// of (width-1)*dilation = 9, not 3. An off-by-one in a convolution cache yields fluent output from
|
|
// a slightly wrong context, so the indexing mirrors ref's line for line: state slot `i` holds
|
|
// relative position `i - hist`, a read at `src < 0` becomes `cs[slot][c][off + src + hist]`, and
|
|
// `has_init` 0 means that window is zeros, not the slot's stale contents.
|
|
//
|
|
// One thread per channel: a depthwise convolution never mixes channels, so only time must stay
|
|
// together. A thread walks a tile of tokens; consecutive threads own consecutive channels, so a
|
|
// wave loads one contiguous 512-byte slice of a token row.
|
|
//
|
|
// The grid is (channel blocks, token tiles, sequences). Token tiles are counted from the batch's
|
|
// total token count, an upper bound on any one sequence's; a short sequence's extra blocks find
|
|
// `t0 >= slen` and return. A per-sequence count would mean reading `cu` on the host.
|
|
//
|
|
// The taps are read from memory, not kept in a shift register: the window would need `hist + 1`
|
|
// registers indexed by a runtime value, which compiles to a select tree (see CU_STATIC in
|
|
// halo_gdn_conv_w4_h128_bf16.hip), and a compile-time window would need a specialisation per
|
|
// (width, dilation). The re-reads hit a tile working set of (BT + hist) * 512 bytes (21 KB at
|
|
// BT 32, L0-resident), and the op is bound by the three arrays it must touch anyway.
|
|
//
|
|
// The window write-back is in the same launch; see the note at the end of the kernel. It relies
|
|
// on `hist < kPcBT`, asserted below.
|
|
#include "halo.h"
|
|
#include "halo_args.h"
|
|
#include "halo_common.h"
|
|
|
|
#include <cstdint>
|
|
|
|
namespace {
|
|
|
|
enum {
|
|
kPcThreads = 256,
|
|
kPcBT = 32, /* tokens a thread walks; the tile's working set is (BT + hist) * 512 B */
|
|
kPcMaxW = 8, /* taps held in registers, so the weight loop unrolls to a static bound */
|
|
kPcMaxHist = 16, /* (width-1)*dilation, the write-back's register window; see cPleConv */
|
|
};
|
|
|
|
/* The write-back lives in tile 0, which is sound only while the deepest tap is inside the first
|
|
* tile. At hist >= BT a second block would read history and the write-back would overwrite bytes
|
|
* it is still reading, silently corrupting a sequence's first tokens. The constraint table caps
|
|
* hist <= 16; the tile size is the other half of that bound. */
|
|
static_assert(kPcMaxHist < kPcBT, "the conv history must fit inside tile 0 for the fused write-back");
|
|
|
|
/* expf rather than __expf: the op is bound by memory, not the transcendental, and the oracle uses
|
|
* std::exp. The instruction-bound GDN conv makes the opposite trade. */
|
|
__device__ __forceinline__ float pc_silu(float z) { return z / (1.0f + expf(-z)); }
|
|
|
|
/* SILU is ple_conv's activation; causal_conv1d (LFM2's short convolution) is the same window with
|
|
* no activation, no residual and dilation one. */
|
|
template <bool SILU>
|
|
__global__ __launch_bounds__(kPcThreads) void ple_conv_kernel(
|
|
const uint16_t* __restrict__ x, const uint16_t* __restrict__ w,
|
|
uint16_t* __restrict__ cs, const int32_t* __restrict__ cu,
|
|
const uint16_t* __restrict__ resid, const int32_t* __restrict__ sidx,
|
|
const int32_t* __restrict__ hini, const int32_t* __restrict__ nacc,
|
|
uint16_t* __restrict__ y, uint32_t n, uint32_t wid, uint32_t dil, uint32_t hist,
|
|
uint32_t xld, uint32_t rld, uint32_t yld, uint32_t wld,
|
|
long long cs_slot, long long cs_ch, long long cs_tok, long long state_len) {
|
|
|
|
const uint32_t c = blockIdx.x * kPcThreads + threadIdx.x;
|
|
if (c >= n) return;
|
|
const uint32_t s = blockIdx.z;
|
|
const int32_t bos = cu[s];
|
|
const int32_t slen = cu[s + 1] - bos;
|
|
if (slen <= 0) return;
|
|
const int32_t t0 = (int32_t)(blockIdx.y * kPcBT);
|
|
if (t0 >= slen) return;
|
|
const int32_t t1 = min(t0 + (int32_t)kPcBT, slen);
|
|
|
|
const int32_t slot = sidx ? sidx[s] : (int32_t)s;
|
|
if (slot < 0) return;
|
|
/* A cold slot's window is zeros: a fresh sequence on a recycled slot would otherwise convolve
|
|
* the previous sequence's tail into its first `hist` tokens. */
|
|
const bool warm = cs && (!hini || hini[s] != 0);
|
|
const long long off = nacc ? (long long)nacc[s] - 1 : 0;
|
|
|
|
/* This channel's taps, read once for the whole tile. */
|
|
float wt[kPcMaxW];
|
|
#pragma unroll
|
|
for (uint32_t j = 0; j < kPcMaxW; ++j) wt[j] = j < wid ? bf16_to_f32(w[(size_t)c * wld + j]) : 0.0f;
|
|
|
|
const uint16_t* __restrict__ xc = x + (size_t)bos * xld + c;
|
|
const uint16_t* __restrict__ rc = resid ? resid + (size_t)bos * rld + c : nullptr;
|
|
uint16_t* __restrict__ dst = cs ? cs + (size_t)slot * cs_slot + (size_t)c * cs_ch : nullptr;
|
|
const uint16_t* __restrict__ hc = warm ? dst + off * cs_tok : nullptr;
|
|
uint16_t* __restrict__ yc = y + (size_t)bos * yld + c;
|
|
|
|
for (int32_t t = t0; t < t1; ++t) {
|
|
float acc = 0.0f;
|
|
#pragma unroll
|
|
for (uint32_t j = 0; j < kPcMaxW; ++j) {
|
|
if (j < wid) {
|
|
const int32_t src = t - (int32_t)hist + (int32_t)(j * dil);
|
|
const float v = src >= 0 ? bf16_to_f32(xc[(size_t)src * xld])
|
|
: (hc ? bf16_to_f32(hc[(src + (int32_t)hist) * cs_tok]) : 0.0f);
|
|
acc += v * wt[j];
|
|
}
|
|
}
|
|
const float r = rc ? bf16_to_f32(rc[(size_t)t * rld]) : 0.0f;
|
|
yc[(size_t)t * yld] = f32_to_bf16(r + (SILU ? pc_silu(acc) : acc));
|
|
}
|
|
|
|
/* The window this step leaves, in the same launch with no barrier. History is read only where
|
|
* `t - hist + j*dilation < 0`, i.e. by tokens below `hist` (9, against a 32-token tile), so
|
|
* tile 0 is the only block touching state[slot][c]. One thread owns the whole channel there, so
|
|
* its reads precede its writes in program order. At decode the op's cost is the dispatch itself
|
|
* (flat from M=1 to M=8), so a second launch would roughly double it.
|
|
*
|
|
* The layout is libref/ref_ple.cpp's, chosen by `num_accepted`. Present, this is a decode step
|
|
* whose drafts a verify may reject: the history read shifts down by one and every input of the
|
|
* step follows it, slot i holding position i + 1 of (window read ++ step), so a next step that
|
|
* kept k tokens reads at k - 1. Absent, every token commits and the last `hist` inputs land at
|
|
* offset zero. The two agree at one token. Slots past `state_len` are not written; the manager
|
|
* sizes the window hist + n_spec, enough for a step of 1 + n_spec tokens.
|
|
*
|
|
* Values are copied as bf16 bits, the same tensor's bytes on both sides. The step's rows come
|
|
* from the read-only `x`, so other tiles reading them is no hazard. Every history value is
|
|
* loaded before the first store. */
|
|
if (!dst || blockIdx.y != 0) return;
|
|
uint16_t keep[kPcMaxHist];
|
|
if (nacc) {
|
|
#pragma unroll
|
|
for (uint32_t i = 0; i + 1 < kPcMaxHist; ++i)
|
|
if (i + 1 < hist) keep[i] = hc ? hc[(size_t)(i + 1) * cs_tok] : (uint16_t)0;
|
|
#pragma unroll
|
|
for (uint32_t i = 0; i + 1 < kPcMaxHist; ++i)
|
|
if (i + 1 < hist) dst[(size_t)i * cs_tok] = keep[i];
|
|
for (int32_t t = 0; t < slen && (long long)hist - 1 + t < state_len; ++t)
|
|
dst[(size_t)(hist - 1 + (uint32_t)t) * cs_tok] = xc[(size_t)t * xld];
|
|
return;
|
|
}
|
|
#pragma unroll
|
|
for (uint32_t i = 0; i < kPcMaxHist; ++i) {
|
|
if (i < hist) {
|
|
const int32_t src = slen - (int32_t)hist + (int32_t)i;
|
|
keep[i] = src >= 0 ? xc[(size_t)src * xld]
|
|
: (hc ? hc[(src + (int32_t)hist) * cs_tok] : (uint16_t)0);
|
|
}
|
|
}
|
|
#pragma unroll
|
|
for (uint32_t i = 0; i < kPcMaxHist; ++i)
|
|
if (i < hist) dst[(size_t)i * cs_tok] = keep[i];
|
|
}
|
|
|
|
enum { PC_X = 0, PC_W, PC_CS, PC_CU, PC_RESID, PC_CIDX, PC_HINIT, PC_NACC, PC_Y };
|
|
/* causal_conv1d's operands: ple_conv's without `resid`. */
|
|
enum { CC_X = 0, CC_W, CC_CS, CC_CU, CC_CIDX, CC_HINIT, CC_NACC, CC_Y };
|
|
|
|
int conv_launch(const RadArgs* a, RadStream s, bool silu, const RadTensor* x, const RadTensor* w,
|
|
const RadTensor* cs, const RadTensor* cu, const RadTensor* resid,
|
|
const RadTensor* cidx, const RadTensor* hini, const RadTensor* nacc,
|
|
const RadTensor* y) {
|
|
if (!x || !w || !cu || !y) return HALO_NO(RAD_E_INVAL);
|
|
if (x->dtype != RAD_BF16 || w->dtype != RAD_BF16 || y->dtype != RAD_BF16)
|
|
return HALO_NO(RAD_E_DTYPE);
|
|
if (resid && resid->dtype != RAD_BF16) return HALO_NO(RAD_E_DTYPE);
|
|
if (cs && cs->data && cs->dtype != RAD_BF16) return HALO_NO(RAD_E_DTYPE);
|
|
if (cu->dtype != RAD_I32) return HALO_NO(RAD_E_DTYPE);
|
|
if (cidx && cidx->dtype != RAD_I32) return HALO_NO(RAD_E_DTYPE);
|
|
/* `has_init` must be int32 (RadBatch::ctx_lens, like every derived buffer): read as bytes, a
|
|
* ctx_len of 512 has a zero low byte and the history would be dropped. Anything else is
|
|
* refused. */
|
|
if (hini && hini->dtype != RAD_I32) return HALO_NO(RAD_E_DTYPE);
|
|
if (nacc && nacc->dtype != RAD_I32) return HALO_NO(RAD_E_DTYPE);
|
|
|
|
const long long n = halo_geti_or(a, "n", 0);
|
|
const long long wid = halo_geti_or(a, "width", 0);
|
|
const long long dil = halo_geti_or(a, "dilation", 1);
|
|
if (n <= 0 || wid <= 0 || dil <= 0) return HALO_NO(RAD_E_SHAPE);
|
|
if (wid > kPcMaxW) return HALO_NO(RAD_E_UNSUPPORTED);
|
|
const long long hist = (wid - 1) * dil;
|
|
if (hist > kPcMaxHist) return HALO_NO(RAD_E_UNSUPPORTED);
|
|
|
|
long long T = 0, ty = 0, tr = 0, wrows = 0;
|
|
const long long xld = halo_rows_pitch(x, n, &T);
|
|
const long long yld = halo_rows_pitch(y, n, &ty);
|
|
const long long rld = resid ? halo_rows_pitch(resid, n, &tr) : 0;
|
|
const long long wld = halo_rows_pitch(w, wid, &wrows);
|
|
if (xld < 0 || yld < 0 || wld < 0 || (resid && rld < 0)) return HALO_NO(RAD_E_STRIDE);
|
|
/* The row count comes from the operands, and they must agree: `M` is ranged, so the arg holds
|
|
* the band's upper bound and a grid sized by it would run off the arena. */
|
|
if (T <= 0 || ty != T || (resid && tr != T)) return HALO_NO(RAD_E_SHAPE);
|
|
if (wrows < n) return HALO_NO(RAD_E_SHAPE);
|
|
|
|
const long long N = halo_numel(cu) - 1;
|
|
if (N <= 0) return HALO_NO(RAD_E_SHAPE);
|
|
if (!halo_contig(cu)) return HALO_NO(RAD_E_STRIDE);
|
|
|
|
/* [n_slots, n, state_len]. A state too shallow for the deepest tap is refused here; the
|
|
* rollback offset cannot be checked without reading `num_accepted` on the host, which is why
|
|
* the manager sizes the window hist + n_spec. */
|
|
long long cs_slot = 0, cs_ch = 0, cs_tok = 0, state_len = 0;
|
|
const bool have_cs = cs && cs->data && hist > 0;
|
|
if (have_cs) {
|
|
if (cs->rank != 3) return HALO_NO(RAD_E_SHAPE);
|
|
if (halo_dim(cs, 1) < n || halo_dim(cs, 2) < hist) return HALO_NO(RAD_E_SHAPE);
|
|
cs_slot = halo_stride(cs, 0);
|
|
cs_ch = halo_stride(cs, 1);
|
|
cs_tok = halo_stride(cs, 2);
|
|
state_len = halo_dim(cs, 2);
|
|
}
|
|
|
|
const uint32_t cb = (uint32_t)((n + kPcThreads - 1) / kPcThreads);
|
|
const uint32_t tb = (uint32_t)((T + kPcBT - 1) / kPcBT);
|
|
const auto kernel = silu ? ple_conv_kernel<true> : ple_conv_kernel<false>;
|
|
hipLaunchKernelGGL(kernel, dim3(cb, tb, (uint32_t)N), dim3(kPcThreads), 0, (hipStream_t)s,
|
|
(const uint16_t*)halo_addr(x), (const uint16_t*)halo_addr(w),
|
|
have_cs ? (uint16_t*)halo_addr(cs) : nullptr,
|
|
(const int32_t*)halo_addr(cu),
|
|
resid ? (const uint16_t*)halo_addr(resid) : nullptr,
|
|
cidx ? (const int32_t*)halo_addr(cidx) : nullptr,
|
|
hini ? (const int32_t*)halo_addr(hini) : nullptr,
|
|
nacc ? (const int32_t*)halo_addr(nacc) : nullptr,
|
|
(uint16_t*)halo_addr(y), (uint32_t)n, (uint32_t)wid, (uint32_t)dil,
|
|
(uint32_t)hist, (uint32_t)xld, (uint32_t)rld, (uint32_t)yld, (uint32_t)wld,
|
|
cs_slot, cs_ch, cs_tok, state_len);
|
|
return hipGetLastError() == hipSuccess ? RAD_OK : HALO_NO(RAD_E_DEVICE);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
extern "C" int halo_rad_ple_conv(const RadArgs* a, RadStream s) {
|
|
return conv_launch(a, s, true, halo_opt(a, PC_X), halo_opt(a, PC_W), halo_opt(a, PC_CS),
|
|
halo_opt(a, PC_CU), halo_opt(a, PC_RESID), halo_opt(a, PC_CIDX),
|
|
halo_opt(a, PC_HINIT), halo_opt(a, PC_NACC), halo_opt(a, PC_Y));
|
|
}
|
|
|
|
extern "C" int halo_rad_causal_conv1d(const RadArgs* a, RadStream s) {
|
|
if (halo_geti_or(a, "dilation", 1) != 1) return HALO_NO(RAD_E_INVAL);
|
|
return conv_launch(a, s, false, halo_opt(a, CC_X), halo_opt(a, CC_W), halo_opt(a, CC_CS),
|
|
halo_opt(a, CC_CU), nullptr, halo_opt(a, CC_CIDX), halo_opt(a, CC_HINIT),
|
|
halo_opt(a, CC_NACC), halo_opt(a, CC_Y));
|
|
}
|