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.
218 lines
8.2 KiB
C++
218 lines
8.2 KiB
C++
/* tests/halo_emu (from tests/r4d_emu/test_kda.cpp): kda_update (halo_kda.hip) on the host SIMT emulator, held to libref's kda_update
|
|
* (from $RADIANCE_HOME, which ctest sets) over the output and the whole state buffer, in all four
|
|
* modes: prefill per candidate and anchored, verify per candidate and anchored (after the replay
|
|
* of the accepted prefix). Cold starts, an unseated sequence, an empty sequence and an unwritten
|
|
* slot are mixed in, so a byte the reference leaves alone must stay as it was. The kernel's lane
|
|
* reductions sum in another order than libref's loops: f32 state within 2e-5 + 2e-5 |x|, bf16
|
|
* output within one rounding step. */
|
|
#include "rad_abi.h"
|
|
#include "rad_plugin.h"
|
|
#include "halo_plugin.h"
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <dlfcn.h>
|
|
#include <random>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
static RadTensor tens(void* p, uint32_t dt, std::vector<int64_t> shape) {
|
|
RadTensor t{};
|
|
t.data = p;
|
|
t.dtype = dt;
|
|
t.rank = (uint32_t)shape.size();
|
|
int64_t st = 1;
|
|
for (int i = (int)shape.size() - 1; i >= 0; --i) {
|
|
t.shape[i] = shape[i];
|
|
t.stride[i] = st;
|
|
st *= shape[i];
|
|
}
|
|
return t;
|
|
}
|
|
static uint16_t f2b(float f) {
|
|
uint32_t u;
|
|
std::memcpy(&u, &f, 4);
|
|
return (uint16_t)((u + 0x7fffu + ((u >> 16) & 1u)) >> 16);
|
|
}
|
|
|
|
/* libref's kda_update, through the plugin's own exports, or null. */
|
|
static RadLaunchFn load_libref() {
|
|
const char* home = std::getenv("RADIANCE_HOME");
|
|
if (!home || !*home) return nullptr;
|
|
const std::string p = std::string(home) + "/kernels/libref.so";
|
|
void* h = dlopen(p.c_str(), RTLD_NOW | RTLD_LOCAL);
|
|
if (!h) return nullptr;
|
|
auto open = (int (*)(void))dlsym(h, "rad_plugin_open"); /* as the loader does */
|
|
if (open && open() < 0) return nullptr;
|
|
auto cnt = (int (*)(void))dlsym(h, "rad_kernel_count");
|
|
auto at = (const RadKernelInfo* (*)(int))dlsym(h, "rad_kernel_at");
|
|
if (!cnt || !at) return nullptr;
|
|
for (int i = 0; i < cnt(); ++i) {
|
|
const RadKernelInfo* k = at(i);
|
|
if (k && k->op && !std::strcmp(k->op, "kda_update")) return k->launch;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
static float bf16_value(uint16_t b) {
|
|
const uint32_t u = (uint32_t)b << 16;
|
|
float f;
|
|
std::memcpy(&f, &u, 4);
|
|
return f;
|
|
}
|
|
|
|
struct Case {
|
|
const char* name;
|
|
const char* mode;
|
|
bool anchor;
|
|
int64_t width;
|
|
std::vector<int> cu, idx, accepted, init;
|
|
std::vector<std::pair<int64_t, float>> counts;
|
|
};
|
|
|
|
int main() {
|
|
const RadLaunchFn reference = load_libref();
|
|
if (!reference) {
|
|
std::printf("FAIL libref's kda_update not loadable (set RADIANCE_HOME)\n");
|
|
return 1;
|
|
}
|
|
std::mt19937 rng(41);
|
|
std::uniform_real_distribution<float> u(-1.f, 1.f);
|
|
const int64_t H = 2, D = 128, slots = 16, tokens = 9;
|
|
std::vector<float> state0((size_t)(slots * H * D * D)), alog((size_t)H), bias((size_t)(H * D));
|
|
for (auto& v : state0) v = u(rng);
|
|
for (auto& v : alog) v = 0.5f * u(rng);
|
|
for (auto& v : bias) v = u(rng);
|
|
std::vector<uint16_t> in[5];
|
|
for (int i = 0; i < 5; ++i) {
|
|
in[i].resize((size_t)(tokens * H * (i == 4 ? 1 : D)));
|
|
for (auto& v : in[i]) v = f2b((i >= 3 ? 2.f : 1.f) * u(rng));
|
|
}
|
|
const std::vector<Case> cases = {
|
|
{ "prefill, per candidate",
|
|
"prefill",
|
|
false,
|
|
1,
|
|
{ 0, 4, 4, 9 },
|
|
{ 3, 4, -1 },
|
|
{ 1, 1, 1 },
|
|
{ 0, 1, 1 },
|
|
{} },
|
|
{ "prefill, anchored",
|
|
"prefill",
|
|
true,
|
|
2,
|
|
{ 0, 5, 9 },
|
|
{ 1, 2, 3, 4 },
|
|
{ 1, 1 },
|
|
{ 1, 0 },
|
|
{} },
|
|
{ "verify, per candidate",
|
|
"verify",
|
|
false,
|
|
4,
|
|
{ 0, 4, 7, 9 },
|
|
{ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, -1 },
|
|
{ 3, 2, 1 },
|
|
{ 1, 0, 1 },
|
|
{} },
|
|
{ "verify, anchored",
|
|
"verify",
|
|
true,
|
|
4,
|
|
{ 0, 4, 7, 9 },
|
|
{ 1, 9, 5, 9, 2, 9, 6, 9, 3, 9, 7, 9 },
|
|
{ 3, 2, 1 },
|
|
{ 1, 1, 0 },
|
|
{ { 5, 4.f }, { 6, 3.f }, { 7, 0.f } } },
|
|
};
|
|
int fails = 0, checks = 0;
|
|
for (const Case& c : cases) {
|
|
std::vector<float> start = state0;
|
|
for (const auto& sc : c.counts)
|
|
for (int64_t h = 0; h < H; ++h) start[(size_t)((sc.first * H + h) * D * D)] = sc.second;
|
|
const int64_t seqs = (int64_t)c.cu.size() - 1;
|
|
std::vector<int> idx = c.idx, cu = c.cu, acc = c.accepted, init = c.init;
|
|
auto run = [&](RadLaunchFn launch, std::vector<uint16_t>& out, std::vector<float>& state) {
|
|
out.assign((size_t)(tokens * H * D), 0x7777);
|
|
state = start;
|
|
RadTensor t[13] = { tens(in[0].data(), RAD_BF16, { tokens, H, D }),
|
|
tens(in[1].data(), RAD_BF16, { tokens, H, D }),
|
|
tens(in[2].data(), RAD_BF16, { tokens, H, D }),
|
|
tens(in[3].data(), RAD_BF16, { tokens, H, D }),
|
|
tens(in[4].data(), RAD_BF16, { tokens, H }),
|
|
tens(alog.data(), RAD_F32, { H }),
|
|
tens(bias.data(), RAD_F32, { H * D }),
|
|
tens(state.data(), RAD_F32, { slots, H, D, D }),
|
|
tens(idx.data(), RAD_I32, { seqs, c.width }),
|
|
tens(cu.data(), RAD_I32, { seqs + 1 }),
|
|
tens(acc.data(), RAD_I32, { seqs }),
|
|
tens(init.data(), RAD_I32, { seqs }),
|
|
tens(out.data(), RAD_BF16, { tokens, H, D }) };
|
|
RadParam p[10]{};
|
|
p[0] = { "heads", RAD_P_INT, H };
|
|
p[1] = { "head_k", RAD_P_INT, D };
|
|
p[2] = { "head_v", RAD_P_INT, D };
|
|
p[3].key = "lower_bound";
|
|
p[3].kind = RAD_P_F64;
|
|
p[3].dval = -5;
|
|
p[4].key = "scale";
|
|
p[4].kind = RAD_P_F64;
|
|
p[4].dval = 1.0 / std::sqrt(128.0);
|
|
p[5].key = "l2_eps";
|
|
p[5].kind = RAD_P_F64;
|
|
p[5].dval = 1e-6;
|
|
p[6].key = "mode";
|
|
p[6].kind = RAD_P_STR;
|
|
p[6].sval = c.mode;
|
|
p[7].key = "state_form";
|
|
p[7].kind = RAD_P_STR;
|
|
p[7].sval = c.anchor ? "anchor" : "per_candidate";
|
|
p[8].key = "dtype";
|
|
p[8].kind = RAD_P_STR;
|
|
p[8].sval = "bf16";
|
|
RadArgs a{};
|
|
a.t = t;
|
|
a.n_t = 13;
|
|
a.p = p;
|
|
a.n_p = 9;
|
|
return launch(&a, nullptr);
|
|
};
|
|
std::vector<uint16_t> ref_out, out;
|
|
std::vector<float> ref_state, state;
|
|
++checks;
|
|
if (run(reference, ref_out, ref_state) != RAD_OK ||
|
|
run(halo_rad_kda_update, out, state) != RAD_OK) {
|
|
std::printf("FAIL %s: refused\n", c.name);
|
|
++fails;
|
|
continue;
|
|
}
|
|
bool written = false;
|
|
for (size_t i = 0; i < ref_out.size(); ++i) written = written || ref_out[i] != 0x7777;
|
|
size_t bad = 0;
|
|
double out_err = 0, state_err = 0;
|
|
for (size_t i = 0; i < out.size(); ++i) {
|
|
if (out[i] == ref_out[i]) continue;
|
|
const float x = bf16_value(out[i]), y = bf16_value(ref_out[i]);
|
|
const double e = std::fabs((double)x - y);
|
|
out_err = std::max(out_err, e);
|
|
if (!std::isfinite(x) || ref_out[i] == 0x7777 || out[i] == 0x7777 ||
|
|
e > 1e-6 + 0.008 * std::fabs(y))
|
|
++bad;
|
|
}
|
|
for (size_t i = 0; i < state.size(); ++i) {
|
|
if (state[i] == ref_state[i]) continue;
|
|
const double e = std::fabs((double)state[i] - ref_state[i]);
|
|
state_err = std::max(state_err, e);
|
|
if (!std::isfinite(state[i]) || e > 2e-5 + 2e-5 * std::fabs(ref_state[i])) ++bad;
|
|
}
|
|
std::printf("%-24s output max %.3g, state max %.3g%s\n", c.name, out_err, state_err,
|
|
!written ? " NO OUTPUT" : bad ? " FAIL" : "");
|
|
if (!written || bad) ++fails;
|
|
}
|
|
std::printf("kda_update against libref: %d of %d within bounds\n", checks - fails, checks);
|
|
return fails ? 1 : 0;
|
|
}
|