Archived
radiance 1.13.0
New models: - Tencent Hy-Memory (HYV3) from its BF16, FP8 and GGUF checkpoints, with its native tool calls - M2XFP4: metadata-augmented MXFP4 weights for Qwen3.8-27B and its DFlash2 drafter (top-1 89.1% -> 92.4% against plain MXFP4), its quantiser and recipe, and ParoQuant's M2XFP4 checkpoints - Gemma 4 E2B/E4B audio input; NVIDIA-Nemotron-3.5-Bolt-E4B in int8 and 4-bit, on two cards by default; Ornith-1.5-122B compose files Speed: - Weight reads beside the decode all-reduces (qwen35_fp8, gemma3; --weight-prefetch, on by default): the 27B MXFP4 with DFlash2 61.2 -> 67.9 tok/s at c1, TranslateGemma 27B +13% - Head-256 split-KV decode attention at 256 workgroups and without bank conflicts (27B: +3-5% a step at 25-41K context), and the prefill KV split for small launches (a short turn over a long context decodes the other sequences 27% faster in that step) - MXFP4 decode gate_up, activation and fp8 quantiser in one launch (27B, Gemma 3 up to 64 rows: TranslateGemma +2-5% at 2-8 streams) - ParoQuant int4/int5 tiled GEMMs 6-9% faster - Speculation: a step's tokens are sent before the drafter's passes end, no step waits behind one that ends its requests, and the MTP head's first draft no longer collapses after short chats in the prefix cache Features: - --kv-resident N: KV streaming for a context bigger than VRAM (qwen4exp_fp8, GLM-5.3) - MiniMax-H3: reference media and keyframe conditioning with the VAE encoders - Krea 2 rebalance presets balanced, detail and subtle - The dashboard's request history; a stall watch that reports a frozen step's thread and stack - rad-tune at the served configuration, collectives measured as the exchange; Gemma 4 E2B/E4B's per-layer embeddings read ahead off the step path - A GPTQ calibration tap and recipe for Gemma 4 31B's w4a8 container Fixes: - The two-rank all-reduce checks that a peer's push has landed before reducing it - z-lab's DFlash drafter on Gemma 4 31B keeps drafting after a prefix-cache hit - MiniMax-H3's modulation rows Changes: Plugin ABI 31: out-of-tree plugins must be rebuilt. RADIANCE_PREFETCH_BESIDE is --weight-prefetch now; RADIANCE_NO_HUGE_PAGES, RADIANCE_IDS_EARLY, RADIANCE_ATTN_BAND_SPLIT, R4D_PREFILL_SPLITS, RAD_PLE_TIMING and RAD_PLE_CACHE_ROWS are gone.
This commit is contained in:
commit
6645337f69
198 files changed
+20904
-3240
No files matched your search
+51
-123
@@ -1,47 +1,21 @@
|
||||
/* avx_kvstream.cpp -- kv_resolve: the residency map between a streamed KV group's block ids and
|
||||
* the ring slots its pool holds (docs/OPS.md "kv_resolve", docs/KV-STREAMING.md §3.4).
|
||||
*
|
||||
* libref/ref_kvstream.cpp is the contract, and this file follows it line by line: the same
|
||||
* refusals in the same order, the same epoch, the same ascending miss order, the same victim from
|
||||
* the same CLOCK sweep over the same two-bit heat counter, so the same blocks land in the
|
||||
* same slots. That is the part a residency
|
||||
* map cannot get "close" on: `sel` becomes the attention's addressing, and two implementations
|
||||
* that agreed on residency but disagreed on a victim would read different KV for the same query.
|
||||
* libref/ref_kvstream.cpp is the contract, followed step for step: the same refusals in the same
|
||||
* order, the same epoch, miss order and CLOCK sweep over the same heat counter, so the same blocks
|
||||
* land in the same slots. A victim cannot be "close": `sel` becomes the attention's addressing.
|
||||
* A file of its own, as in libref, because the op belongs to no indexer: it moves bytes and keeps
|
||||
* state across calls.
|
||||
*
|
||||
* Why its own file rather than a section of avx_qsa.cpp: the op sits beside `qsa_select` in
|
||||
* docs/OPS.md but is not part of the indexer -- it walks no scores and rotates nothing, it moves
|
||||
* bytes and owns state across calls (epoch, hand, heat counters). libref keeps the same split
|
||||
* (ref_qsa.cpp / ref_kvstream.cpp), so the two libraries' files diff against each other.
|
||||
* The rewrite of a `sel` row (a gather of `res[b]`) and the block copy (a whole number of 16-byte
|
||||
* lanes at every cache layout) are vector work. The lookup/claim pass, the claim gather and the
|
||||
* sweep are serial by nature: two lanes naming one absent block would both claim it, two naming
|
||||
* one slot would race on its epoch, and the sweep's moving hand is the placement. They cost the
|
||||
* selection and the slots, never `blocks`, and the copies dominate a miss.
|
||||
*
|
||||
* ============================== what is and is not vector work ==============================
|
||||
*
|
||||
* The phases that can run wide do: the rewrite of a `sel` row (a gather of `res[b]` with the
|
||||
* negative results left in place) and the block copy (one block is a whole number of 16-byte lanes
|
||||
* at every cache layout, docs/OPS.md). The passes that cannot are the lookup/claim pass, the claim
|
||||
* gather and the CLOCK sweep, and none of them is a missed opportunity:
|
||||
*
|
||||
* the map is its own set (phase 2). Two lanes of one vector naming the same absent block would
|
||||
* both read -1 and both claim it, which is exactly the double claim -2 exists to prevent, and
|
||||
* two lanes naming the same resident slot would race on its epoch. The pass is one load and one
|
||||
* store per entry and is bounded by the selection, not by the cache. The claim gather and the
|
||||
* revert are the same pass twice more (`lookups` entries each) for the same reason: the list is a
|
||||
* fact about the selection, and the whole point of this form is that `blocks` -- the id space --
|
||||
* never enters a launch's cost.
|
||||
*
|
||||
* the sweep is a serial second-chance walk with a moving hand whose result is the placement
|
||||
* itself. Its cost is one pass over the slots per miss, and a miss is a cold block: the copies
|
||||
* dominate.
|
||||
*
|
||||
* No OpenMP anywhere: the op carries state from call to call (ctl's epoch, hand and counters), so
|
||||
* two of its launches must never overlap and one launch is a single serial unit of work. This is
|
||||
* why its row is absent from libr4d's concurrent prefix table; libavx's rows make no concurrency
|
||||
* promise at all.
|
||||
*
|
||||
* Scratch is the arena the other kernels use (avx_common.h), not RadArgs::scratch: the miss list
|
||||
* and the claim list are per-call temporaries, and the arena is already the plugin's answer for
|
||||
* one. The layout is `int32 miss_block[slots]`, `int32 miss_slot[slots]` -- what a device row
|
||||
* declares through RadKernelInfo::scratch -- followed by `int32 claim[lookups]`, the gathered claim
|
||||
* set this file needs only because it has no workgroup to sort in.
|
||||
* No OpenMP: the op's state makes one launch a serial unit, and two launches must never overlap.
|
||||
* Scratch is the arena (avx_common.h): `miss_block[slots]`, `miss_slot[slots]`, then
|
||||
* `claim[lookups]`, the gathered claim set this form sorts in place of a workgroup.
|
||||
*/
|
||||
#include "avx_common.h"
|
||||
#include "avx_vec.h"
|
||||
@@ -91,17 +65,11 @@ void kv_copy_block(uint8_t* dst, const uint8_t* src, int64_t n) {
|
||||
if (i < n) std::memcpy(dst + i, src + i, (size_t)(n - i));
|
||||
}
|
||||
|
||||
/* The claim list: every distinct block the selection claims, in block-id order. A claim exists only
|
||||
* where an entry names a block -- the lookup pass left it `-2` -- so the list is gathered from the
|
||||
* SELECTION, whose length is `lookups = sum_q nsel[q]`: a property of the call. It is deliberately
|
||||
* not a walk of `res` over `blocks`, which is the group's whole id space and says nothing about how
|
||||
* big one launch is. The map stays the dedup set: the first entry naming a claim marks it `-3`, so a
|
||||
* block several rows name enters the list once, and the marks are restored before the sweep sees the
|
||||
* map.
|
||||
*
|
||||
* The caller sorts the list; `cap` is the buffer's length and is `lookups` at least, because a
|
||||
* distinct claim costs at least one entry, so every claim is written. The contract needs the first
|
||||
* `slots` of that ascending order and nothing past them. */
|
||||
/* The claim list: every distinct block the selection claimed (left -2 by the lookup pass), in
|
||||
* selection order, gathered from the `lookups` entries rather than a walk of `res` over the id
|
||||
* space. The map stays the dedup set: the first entry naming a claim marks it -3, and the marks
|
||||
* are restored before the sweep. `cap` is at least `lookups`, so every claim fits; the caller
|
||||
* sorts the list and the contract needs only its first `slots`. */
|
||||
int64_t kv_claims(int32_t* res, int32_t* out, int64_t cap,
|
||||
const int32_t* sel, const int32_t* nsel, int64_t M, int64_t pitch) {
|
||||
int64_t n = 0;
|
||||
@@ -118,11 +86,9 @@ int64_t kv_claims(int32_t* res, int32_t* out, int64_t cap,
|
||||
return n;
|
||||
}
|
||||
|
||||
/* Every claim the sweep could not place goes back to -1: the block is not resident, and the next
|
||||
* call may claim it again. A `res` entry still -2 here is by definition such a claim (a placed one
|
||||
* holds its slot), and it is named by at least one selection entry, so one pass over the selection
|
||||
* reaches all of them -- `lookups` entries instead of `blocks` map entries. The write is idempotent,
|
||||
* so entries that repeat a block are harmless. */
|
||||
/* Every claim the sweep could not place (still -2) goes back to -1, so a later call may claim it
|
||||
* again. Each is named by a selection entry, so one pass over the selection reaches all of them;
|
||||
* the write is idempotent. */
|
||||
void kv_relax_claims(int32_t* res, const int32_t* sel, const int32_t* nsel, int64_t M,
|
||||
int64_t pitch) {
|
||||
for (int64_t q = 0; q < M; ++q) {
|
||||
@@ -132,14 +98,9 @@ void kv_relax_claims(int32_t* res, const int32_t* sel, const int32_t* nsel, int6
|
||||
}
|
||||
}
|
||||
|
||||
/* The rewrite: entry i becomes the slot holding its block, and an entry whose block could not be
|
||||
* placed becomes slot 0 -- a defined address inside the ring, because leaving the block id would
|
||||
* make the attention dereference past it. ctl[3] is what marks the table unusable ("Overflow" in
|
||||
* docs/OPS.md).
|
||||
*
|
||||
* The gather is safe by construction: the validation pass refused any entry outside [0, blocks)
|
||||
* before a byte was written. An entry at or past nsel[q] is never passed in, so `qsa_select`'s -1
|
||||
* padding survives. */
|
||||
/* The rewrite: each entry below nsel[q] becomes its block's slot, or slot 0 for a block that
|
||||
* could not be placed (the id would be an address past the ring; ctl[3] marks the table unusable).
|
||||
* The gather is safe: validation refused every entry outside [0, blocks). */
|
||||
void kv_rewrite_row(int32_t* row, int64_t n, const int32_t* res) {
|
||||
int64_t i = 0;
|
||||
#if AVX_LEVEL >= 3
|
||||
@@ -148,9 +109,8 @@ void kv_rewrite_row(int32_t* row, int64_t n, const int32_t* res) {
|
||||
const __m512i b = _mm512_loadu_si512((const void*)(row + i));
|
||||
const __m512i s = _mm512_mask_i32gather_epi32(zero, (__mmask16)0xFFFF, b,
|
||||
(const void*)res, 4);
|
||||
/* A gather that lands on a negative is a block this call could not place (-1) or one it
|
||||
* just claimed (-2): slot 0, not the id, exactly as the scalar tail writes it. Clamping
|
||||
* says that for the whole vector; masking the store instead would leave the id in place. */
|
||||
/* A negative gather (-1 unplaced, -2 claimed) becomes slot 0, as the scalar tail writes it:
|
||||
* clamping the whole vector, since a masked store would leave the id in place. */
|
||||
_mm512_storeu_si512((void*)(row + i), _mm512_max_epi32(s, zero));
|
||||
}
|
||||
#elif AVX_LEVEL >= 2
|
||||
@@ -159,7 +119,7 @@ void kv_rewrite_row(int32_t* row, int64_t n, const int32_t* res) {
|
||||
for (; i + 8 <= n; i += 8) {
|
||||
const __m256i b = _mm256_loadu_si256((const __m256i*)(row + i));
|
||||
const __m256i s = _mm256_mask_i32gather_epi32(zero, res, b, all, 4);
|
||||
/* s > -1 is s >= 0; a negative lane becomes 0 ("Overflow"), never the block id it holds. */
|
||||
/* s > -1 is s >= 0; a negative lane becomes 0, never the block id. */
|
||||
const __m256i ok = _mm256_cmpgt_epi32(s, all);
|
||||
_mm256_storeu_si256((__m256i*)(row + i), _mm256_blendv_epi8(zero, s, ok));
|
||||
}
|
||||
@@ -173,22 +133,8 @@ void kv_rewrite_row(int32_t* row, int64_t n, const int32_t* res) {
|
||||
} /* namespace */
|
||||
|
||||
/* ------------------------------------------------------------------ kv_resolve */
|
||||
/* One call: bump the epoch; one lookup per distinct block (a hit stamps the slot with the epoch and
|
||||
* bumps its heat counter, an absent block becomes a claim and joins the miss list once); place one
|
||||
* victim per miss -- the block's own slot when its id fits the ring and that slot is free (a
|
||||
* context shorter than the ring maps block id to slot), otherwise a free slot first, then CLOCK from
|
||||
* the hand over the two-bit heat counter, which never takes a slot this call has stamped; re-point
|
||||
* both maps; copy each missed block from the mirror; rewrite every valid entry. `nsel` and the
|
||||
* attention's length are untouched:
|
||||
* a selection entry is an address, not a count.
|
||||
*
|
||||
* `kv_cache` is the RAD_KV operand the attention and `kv_store` take, and it is INOUT rather than
|
||||
* OUT: only the slots a miss lands in are written and every other slot of the ring must survive
|
||||
* for the blocks still resident there.
|
||||
*
|
||||
* An entry of a miss the sweep could not place is rewritten to slot 0, not left holding its block
|
||||
* id: on device the id is an address past the ring that `attn_paged` dereferences unchecked, and a
|
||||
* measured overflow must produce wrong numbers the caller discards (ctl[3]), not a fault. */
|
||||
/* One call, as libref's steps 1-7. `kv_cache` is inout: only the slots a miss lands in are
|
||||
* written, and every other slot keeps its resident block. */
|
||||
AVX_KERNEL(kv_resolve) {
|
||||
if (!rad_args_have(a, 8)) return RAD_E_INVAL;
|
||||
const RadTensor *sel = &a->t[0], *nsel = &a->t[1], *res = &a->t[2], *sblk = &a->t[3];
|
||||
@@ -200,8 +146,7 @@ AVX_KERNEL(kv_resolve) {
|
||||
if (M <= 0) return RAD_E_SHAPE;
|
||||
if (blocks <= 0 || slots_decl <= 0 || pitch <= 0 || bbytes <= 0) return RAD_E_SHAPE;
|
||||
|
||||
/* The map and the counts are one format, written by one op and read by the writer and the
|
||||
* sweep: i32, dense. */
|
||||
/* The maps and counts are one format: i32, dense. */
|
||||
const RadTensor* const state[] = { sel, nsel, res, sblk, sst, ctl };
|
||||
for (const RadTensor* t : state)
|
||||
if (t->dtype != RAD_I32) return RAD_E_DTYPE;
|
||||
@@ -210,9 +155,8 @@ AVX_KERNEL(kv_resolve) {
|
||||
if (sel->stride[1] != 1 || sel->stride[0] != pitch) return RAD_E_STRIDE;
|
||||
if (numel(nsel) < M || nsel->stride[0] != 1) return RAD_E_SHAPE;
|
||||
if (numel(res) < blocks || res->stride[0] != 1) return RAD_E_SHAPE;
|
||||
/* The operand states the ring and the parameter is its declared ceiling, as `sel` states `M`
|
||||
* (libref/ref_kvstream.cpp, "The parameters"): the pool is planned after declare, so a ring the
|
||||
* engine sized smaller (--kv-resident) arrives as a shorter `slot_block`. */
|
||||
/* The operand states the ring, the parameter its declared ceiling: the pool is planned after
|
||||
* declare, so a ring --kv-resident sized smaller arrives as a shorter `slot_block`. */
|
||||
const int64_t slots = numel(sblk);
|
||||
if (slots < 1 || slots > slots_decl || sblk->stride[0] != 1) return RAD_E_SHAPE;
|
||||
if (sst->shape[0] < slots || sst->stride[1] != 1 || sst->stride[0] < 2) return RAD_E_STRIDE;
|
||||
@@ -220,8 +164,7 @@ AVX_KERNEL(kv_resolve) {
|
||||
if (host->rank < 2 || pool->rank < 2) return RAD_E_SHAPE;
|
||||
if (host->shape[0] < blocks || pool->shape[0] < slots) return RAD_E_SHAPE;
|
||||
|
||||
/* One block of one layer: the mirror's row and the pool's slot are the same bytes, and
|
||||
* `block_bytes` is both pitches -- the length of every copy. */
|
||||
/* The mirror's row and the pool's slot are both `block_bytes`, every copy's length. */
|
||||
int64_t hdense = 0, pdense = 0;
|
||||
if (kv_row_bytes(host, &hdense) != bbytes ||
|
||||
hdense * rad_dtype_bytes(host->dtype, 1) != bbytes)
|
||||
@@ -240,8 +183,8 @@ AVX_KERNEL(kv_resolve) {
|
||||
/* The counters are read and written as u64 inside an i32 block. */
|
||||
if (((uintptr_t)C & 7u) != 0) return RAD_E_STRIDE;
|
||||
|
||||
/* ---- everything that can refuse, before anything is written; the entry count is summed here
|
||||
* so the counter and the claim list's length need no second look at `nsel` ---- */
|
||||
/* ---- everything that can refuse, before anything is written; the entry count summed here sizes
|
||||
* the counter and the claim list ---- */
|
||||
int64_t lookups = 0;
|
||||
for (int64_t q = 0; q < M; ++q) {
|
||||
const int64_t n = NS[q];
|
||||
@@ -251,11 +194,9 @@ AVX_KERNEL(kv_resolve) {
|
||||
if (row[i] < 0 || row[i] >= blocks) return RAD_E_INVAL;
|
||||
lookups += n;
|
||||
}
|
||||
/* The map's own domain, over the whole of it. This is a state fault the contract refuses
|
||||
* (`-2` is never left by a call; a slot index outside the ring would address past it), not a
|
||||
* fallback: an entry the map holds and no selection entry names can only be found by looking
|
||||
* at the map, so this pass is `blocks` long in the reference and here alike. Everything that
|
||||
* acts on a claim is bounded by the selection, as above. */
|
||||
/* The map's own domain, over the whole map: a state fault the contract refuses, and only a
|
||||
* look at the map can find an entry no selection names. Everything acting on a claim is
|
||||
* bounded by the selection. */
|
||||
for (int64_t b = 0; b < blocks; ++b)
|
||||
if (R[b] < -1 || R[b] >= slots) return RAD_E_INVAL; /* -2 is never left by a call */
|
||||
for (int64_t s = 0; s < slots; ++s)
|
||||
@@ -273,8 +214,7 @@ AVX_KERNEL(kv_resolve) {
|
||||
const int32_t b = row[i];
|
||||
const int32_t s = R[b];
|
||||
if (s >= 0) {
|
||||
/* The epoch stamps the slot; the heat counter gains one step, once a slot a call
|
||||
* (libref's step 2), so the counter measures calls that wanted the block. */
|
||||
/* Stamp the slot and bump its heat once a slot a call (libref's step 2). */
|
||||
if (ST[s * stp] != epoch) {
|
||||
ST[s * stp] = epoch;
|
||||
ST[s * stp + 1] = kv_heat_up(ST[s * stp + 1]);
|
||||
@@ -296,25 +236,18 @@ AVX_KERNEL(kv_resolve) {
|
||||
|
||||
/* ---- 4. one victim per miss: identity, a free slot, then CLOCK, from the hand, never a slot
|
||||
* this call uses ---- */
|
||||
/* Identity first: a block whose id fits the ring and whose own slot is free goes there, so a
|
||||
* context shorter than the ring gets res[b] = b and the attention's run of adjacent ids reads
|
||||
* adjacent slots of one layer's stripe (libref's step 4; +2.07% at 16k, §26). It takes only a
|
||||
* free slot and does not move the hand, so it never evicts and the fallback below is the old
|
||||
* policy exactly, from the hand it would always have seen.
|
||||
*
|
||||
* Free before live: the ring's empty region fills before any resident block is evicted (see
|
||||
* libref's step 4). The free scan has no side effect when it finds nothing, so a full ring
|
||||
* takes the same CLOCK victim it always took. The count is what keeps a full ring from paying
|
||||
* that scan per miss: a placement makes a free slot live and an eviction re-points a live one,
|
||||
* so a zero count holds for the rest of the call. */
|
||||
/* Identity first (libref's step 4): a context shorter than the ring gets res[b] = b, so the
|
||||
* attention's adjacent ids read adjacent slots. It takes only a free slot and leaves the hand
|
||||
* alone. Then free slots before any resident block; the free scan changes nothing when it
|
||||
* finds nothing, and a zero free count holds for the rest of the call, so a full ring does not
|
||||
* pay the scan per miss. */
|
||||
int64_t free_left = 0;
|
||||
for (int64_t s = 0; s < slots; ++s)
|
||||
if (SB[s] < 0 && ST[s * stp] != epoch) ++free_left;
|
||||
int64_t hand = C[1];
|
||||
int64_t placed = 0;
|
||||
/* More claims than the ring can hold means some miss was left unplaced by construction -- the
|
||||
* list here is the first `slots` of the claim set, so the sweep cannot discover it by running
|
||||
* out of misses -- and libref latches exactly that. */
|
||||
/* More claims than slots: some miss is unplaced by construction (the list is clipped at `slots`,
|
||||
* so the sweep cannot find out by running dry), and libref latches exactly that. */
|
||||
bool overflow = nclaims > slots;
|
||||
for (int64_t k = 0; k < nmiss; ++k) {
|
||||
const int32_t b = miss_block[k];
|
||||
@@ -348,8 +281,7 @@ AVX_KERNEL(kv_resolve) {
|
||||
}
|
||||
}
|
||||
if (victim < 0) {
|
||||
/* Every slot of the ring is stamped with this call's epoch: nothing left to take, and
|
||||
* taking a slot this call filled would break the table it is about to hand out. */
|
||||
/* Every slot is stamped by this call: taking one would break the table it hands out. */
|
||||
overflow = true;
|
||||
break;
|
||||
}
|
||||
@@ -376,22 +308,18 @@ AVX_KERNEL(kv_resolve) {
|
||||
for (int64_t q = 0; q < M; ++q) kv_rewrite_row(SE + q * pitch, NS[q], R);
|
||||
|
||||
/* ---- the bookkeeping ---- */
|
||||
/* Distinct blocks, counted from the slots this call stamped: a hit or a placed miss leaves the
|
||||
* call's epoch in its slot, and the misses it could not place are the rest of the union. Entry
|
||||
* counts would overcount, because many of a launch's rows share swaths of the history. */
|
||||
/* Distinct blocks: the slots this call stamped, plus the misses it could not place. Entry counts
|
||||
* would overcount, since rows share history. */
|
||||
int64_t used = 0;
|
||||
for (int64_t s = 0; s < slots; ++s)
|
||||
if (ST[s * stp] == epoch) ++used;
|
||||
/* The union is over DISTINCT blocks, so it is the slots this call stamped plus the claims it
|
||||
* could not place -- exactly libref's count, and now that the whole claim set is known rather
|
||||
* than a list clipped at `slots`, an overflow reports the union it selected too. */
|
||||
/* libref's union, including a call that overflowed, since the whole claim set is known. */
|
||||
const int64_t uni = used + nclaims - placed;
|
||||
C[0] = epoch;
|
||||
C[1] = (int32_t)hand;
|
||||
C[2] = (int32_t)placed;
|
||||
if (overflow) C[3] = 1;
|
||||
/* The measured sizes: this call's selection union, the part of it that had to be copied in, and
|
||||
* the depth of its claim list. */
|
||||
/* The maxima: the union, the part copied in, and the claim list's depth. */
|
||||
if (uni > C[10]) C[10] = (int32_t)uni;
|
||||
if (placed > C[11]) C[11] = (int32_t)placed;
|
||||
if (nclaims > C[12]) C[12] = (int32_t)nclaims;
|
||||
|
||||
Reference in new issue
Block a user