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.
143 lines
6.6 KiB
Plaintext
143 lines
6.6 KiB
Plaintext
// embed_lookup over an IQR table (r4d_iqr.h's embed_off): the gather decodes each requested row
|
|
// from its codes, so VRAM holds the table at its codes' width.
|
|
//
|
|
// ref_embed_lookup's contract (r4d_model_bf16.hip's embed_lookup_kernel): x[m] is the table's row
|
|
// tok[m] - vocab_offset, a zero row for an id outside this rank's rows, times `mult` with one
|
|
// rounding. A row's value is the form's int8 value times its (row, 128) scale in f32, the 128-wide
|
|
// Hadamard undone in f32 on a rotated table (libquant's butterfly order: span 1, 2, .., 64, each
|
|
// pair (a, b) to (a + b, a - b)), rounded to bf16 to nearest even: the values the table's bf16
|
|
// widening at load produced, bit for bit.
|
|
|
|
#include "r4d.h"
|
|
#include "r4d_args.h"
|
|
#include "r4d_emit.h"
|
|
#include "r4d_fp8_wmma.h"
|
|
#include "r4d_iqr.h"
|
|
#include "r4d_iqr_dec.h"
|
|
|
|
namespace {
|
|
|
|
using namespace r4d_iqr;
|
|
using namespace r4d_iqr_dev;
|
|
|
|
/* `n` <= 16 bits of a byte stream from bit `o`. */
|
|
__device__ __forceinline__ uint32_t bits_at(const uint8_t* p, uint64_t o, uint32_t n) {
|
|
const uint8_t* b = p + (o >> 3);
|
|
const uint32_t w = (uint32_t)b[0] | (uint32_t)b[1] << 8 | (uint32_t)b[2] << 16;
|
|
return (w >> (o & 7u)) & ((1u << n) - 1u);
|
|
}
|
|
|
|
template <uint32_t KIND, uint32_t B, uint32_t LV, uint32_t L, uint32_t LRB, uint32_t SC, uint32_t ROT>
|
|
__global__ __launch_bounds__(128) void iqr_embed_kernel(const int32_t* __restrict__ tok,
|
|
const uint8_t* __restrict__ W,
|
|
uint16_t* __restrict__ x, uint32_t n_embd,
|
|
int32_t n_vocab, int32_t vocab_off,
|
|
uint32_t x_ld, float mult) {
|
|
constexpr Form f{ KIND, B, LV, L, LRB, SC, 0, ROT };
|
|
__shared__ float s_v[128];
|
|
const uint32_t m = blockIdx.x, g = blockIdx.y, t = threadIdx.x, k = g * 128u + t;
|
|
const int32_t id = tok[m] - vocab_off;
|
|
uint16_t* dst = x + (size_t)m * x_ld + k;
|
|
if (id < 0 || id >= n_vocab) {
|
|
*dst = 0;
|
|
return;
|
|
}
|
|
const EmbedOff o = embed_off(f, n_vocab, n_embd);
|
|
const uint32_t nkb = n_embd / 128u, r = (uint32_t)id;
|
|
auto code = [&](uint32_t row, uint32_t col) {
|
|
return bits_at(W + (size_t)row * o.codes_row, (uint64_t)col * B, B);
|
|
};
|
|
const int8_t* aux = (const int8_t*)(W + o.aux);
|
|
int32_t v;
|
|
if constexpr (KIND == kTable) {
|
|
v = aux[code(r, k)];
|
|
} else if constexpr (KIND == kGrid) {
|
|
v = aux[code(r, k >> LV) * (1u << LV) + (k & ((1u << LV) - 1u))];
|
|
} else if constexpr (KIND == kZero) {
|
|
v = (int32_t)code(r, k) - (int32_t)((const uint8_t*)aux)[(size_t)r * nkb + g];
|
|
} else if constexpr (KIND == kSigned) {
|
|
v = (int32_t)(code(r, k) << (32u - B)) >> (32u - B);
|
|
} else {
|
|
/* The trellis: row r's state is its last ceil(L/B) codes in its column, the run's 256
|
|
* rows wrapping (the launch refuses another run). */
|
|
constexpr uint32_t C = (L + B - 1) / B, run = 256u;
|
|
const uint32_t r0 = r / run * run;
|
|
uint32_t st = 0;
|
|
#pragma unroll
|
|
for (uint32_t q = C; q-- > 0;) {
|
|
const uint32_t rr = r0 + (r - r0 + run - q) % run;
|
|
st = ((st << B) | code(rr, k)) & ((1u << L) - 1u);
|
|
}
|
|
v = aux[st];
|
|
}
|
|
/* The row's scale as bf16 bits: its own, or its block's on a tcq_rb grid, against which the
|
|
* value is rint(v * own / B). */
|
|
uint32_t own;
|
|
if constexpr (SC == kBf16) {
|
|
own = ((const uint16_t*)(W + o.sc))[(size_t)r * nkb + g];
|
|
} else {
|
|
const float s2 = ((const float*)(W + o.s2))[SC == kE4m3Row ? r : 0u];
|
|
own = bf16_bits(s2 * e4m3((W + o.sc)[(size_t)r * nkb + g]));
|
|
}
|
|
uint32_t sb = own;
|
|
if constexpr (LRB != 0) {
|
|
sb = ((const uint16_t*)(W + o.blk))[(size_t)(r >> LRB) * nkb + g];
|
|
const float so = __uint_as_float(own << 16), sbf = __uint_as_float(sb << 16);
|
|
v = sbf > 0.0f ? (int32_t)rintf(__fmul_rn((float)v, __fdiv_rn(so, sbf))) : 0;
|
|
}
|
|
float val = __fmul_rn((float)v, __uint_as_float(sb << 16));
|
|
if constexpr (ROT != 0) {
|
|
s_v[t] = val;
|
|
__syncthreads();
|
|
#pragma unroll
|
|
for (uint32_t h = 1; h < 128u; h <<= 1) {
|
|
const float a = s_v[t & ~h], b = s_v[t | h];
|
|
const float y = (t & h) ? __fsub_rn(a, b) : __fadd_rn(a, b);
|
|
__syncthreads();
|
|
s_v[t] = y;
|
|
__syncthreads();
|
|
}
|
|
val = s_v[t];
|
|
}
|
|
uint32_t bits = bf16_bits(val);
|
|
if (mult != 1.0f) bits = f32_to_bf16(__uint_as_float(bits << 16) * mult);
|
|
*dst = (uint16_t)bits;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
enum { EL_TOK = 0, EL_WTE, EL_X };
|
|
|
|
extern "C" int r4d_rad_embed_lookup_iqr(const RadArgs* a, RadStream stream) {
|
|
const RadTensor* tok = r4d_opt(a, EL_TOK);
|
|
const RadTensor* wte = r4d_opt(a, EL_WTE);
|
|
const RadTensor* x = r4d_opt(a, EL_X);
|
|
if (!tok || !wte || !x) return R4D_NO(RAD_E_INVAL);
|
|
if (tok->dtype != RAD_I32 || x->dtype != RAD_BF16 || !is_weight_dtype(wte->dtype))
|
|
return R4D_NO(RAD_E_DTYPE);
|
|
if (!r4d_contig(tok)) return R4D_NO(RAD_E_STRIDE);
|
|
const long long n_embd = r4d_geti_or(a, "n_embd", 0), n_vocab = r4d_geti_or(a, "n_vocab", 0);
|
|
const long long voff = r4d_geti_or(a, "vocab_offset", 0);
|
|
if (n_embd <= 0 || n_embd % 128 || n_vocab <= 0 || voff < 0) return R4D_NO(RAD_E_SHAPE);
|
|
long long M = 0;
|
|
const long long x_ld = r4d_rows_pitch(x, n_embd, &M);
|
|
if (x_ld < 0) return R4D_NO(RAD_E_STRIDE);
|
|
if (M <= 0 || r4d_numel(tok) < M) return R4D_NO(RAD_E_SHAPE);
|
|
const float mult = (float)r4d_getf(a, "mult", 1.0);
|
|
const uint32_t kw = kernel_word(wte->dtype & kWordMask);
|
|
const Form f = form(wte->dtype & kWordMask);
|
|
/* The run, which the kernel assumes, is libquant's tcq_rows = 256. */
|
|
if (f.kind == kTrellis && f.lrun != 8u) return R4D_NO(RAD_E_SHAPE);
|
|
const dim3 grid((uint32_t)M, (uint32_t)(n_embd / 128));
|
|
int rc = RAD_E_UNSUPPORTED;
|
|
#define R4D_IQR_EGO(k, b, lv, l, lrb, sc, r) \
|
|
if (kw == word(Form{ k, b, lv, l, lrb, sc, 0, r })) \
|
|
rc = R4D_EMIT(stream, (iqr_embed_kernel<k, b, lv, l, lrb, sc, r>), grid, dim3(128), 0, \
|
|
(const int32_t*)tok->data, (const uint8_t*)wte->data, (uint16_t*)x->data, \
|
|
(uint32_t)n_embd, (int32_t)n_vocab, (int32_t)voff, (uint32_t)x_ld, mult); \
|
|
else
|
|
R4D_IQR_EMBED_FORMS(R4D_IQR_EGO) { return R4D_NO(RAD_E_UNSUPPORTED); }
|
|
#undef R4D_IQR_EGO
|
|
return rc == RAD_OK && hipGetLastError() == hipSuccess ? RAD_OK : R4D_NO(RAD_E_DEVICE);
|
|
}
|