radiance 1.3.0

- #47: llama-server's request fields, routes and sampler order, and /props (with baKon's model
  entry: max_model_len, root and capabilities on /v1/models, and /v1/models/:id)
- new APIs: Anthropic's Messages API (/v1/messages), OpenAI's Responses API (/v1/responses),
  llama-server's /completion and /infill, logprobs (OpenAI's logprobs and top_logprobs, up to
  20; llama-server's n_probs), OpenAI's legacy `functions`, and X-Api-Key beside the bearer key
- #4: --model takes a Hugging Face repo id (owner/name), fetched before startup into
  ~/.cache/radiance/hf or --download-dir and checked for changes at every start (redxherring)
- #46: --tp 3 --tp-wire wht6 serves -- a three-rank two-shot all-reduce with uneven shards and
  the tiered-int8 wire over it (baKon); scripts/cardclock.py names what holds each card's clock
  under load (baKon)
- CPU-only serving works again; --kernels names the kernel libraries to load; a model the
  loaded libraries cannot fully serve refuses at startup instead of failing its first request;
  --vram-kv-mib and --vram-weights-mib are gone (the split is automatic)
- --embedding-placement ram is the default, and `auto` is gone
- #40: Swift 1.5 recipes; rad-convert reads which shard holds a tensor from the index
- #53: the pinned host pool gets huge pages where shmem THP is off; #57: a crash on video with
  an odd frame width is fixed
This commit is contained in:
Deadcode committed 2026-10-08 18:22:08 +02:00
1 parent 6a2ee986d6
commit 89cee7ce41
107 files changed
+6849 -1091

No files matched your search

+6
View File
@@ -410,6 +410,11 @@ std::vector<Case> build_cases() {
"sample_argmax" })
add(op, { HI("M", 5), HI("n_vocab", 517) });
add("sample_topk", { HI("M", 5), HI("n_vocab", 517), HI("vocab_off", 0) });
/* k 7 and 20 (OpenAI's top_logprobs bound) against 517: the one-pass set starts full after
* seven columns, and an offset shard reports global ids. */
for (int64_t k : { 7, 20 })
add("sample_logprobs", { HI("M", 5), HI("n_vocab", 517), HI("k", k), HI("vocab_off", 0) });
add("sample_logprobs", { HI("M", 3), HI("n_vocab", 517), HI("k", 5), HI("vocab_off", 1000) });
for (const char* op : { "sample_topp", "sample_minp", "sample_typical", "sample_xtc",
"sample_pick", "sample_merge_topk" })
add(op, { HI("M", 5), HI("n_cand", 12) });
@@ -495,6 +500,7 @@ std::vector<Case> build_cases() {
speed("logits_gemm", { HI("M", 1), HI("n_vocab", 32000), HI("n_embd", 2048),
HS("dtype", "bf16") }, (double)32000 * 2048 * 2, 2.0 * 32000 * 2048);
speed("sample_argmax", { HI("M", 1), HI("n_vocab", 32000) }, (double)32000 * 4, 0);
speed("sample_logprobs", { HI("M", 1), HI("n_vocab", 32000), HI("k", 20) }, (double)32000 * 4, 0);
speed("sample_topk", { HI("M", 1), HI("n_vocab", 32000), HI("vocab_off", 0) }, 0, 0);
/* Decode attention over a real context: 16 query heads in groups of 4, 2048 keys already in
* the cache. This is the shape a decode step spends its time in. */
+1 -1
View File
@@ -116,7 +116,7 @@ int avx_isa_force(int level);
X(sample_penalties) X(sample_dry) X(sample_temp) X(sample_topk) \
X(sample_topp) X(sample_minp) X(sample_typical) X(sample_xtc) \
X(sample_merge_topk) X(sample_mask) X(sample_pick) X(sample_argmax) \
X(dflash_select)
X(sample_logprobs) X(dflash_select)
/* The table one ISA level fills. One member per op, same order as AVX_OP_LIST. A missing
* definition is a link error against the level's own table definition in avx_table.cpp. */
+8
View File
@@ -450,6 +450,9 @@ static const RadParamSpec pTopk[] = { P_INT("M"), P_INT("n_vocab"), P_INT
static const RadOperandSpec oTopk[] = { OPD("logits"), OPD("params"),
OUT("cand_idx"), OUT("cand_val"), OUT_O("pairs") };
static const RadOperandSpec oArgmax[] = { OPD("logits"), OPD("params"), OUT("token") };
static const RadParamSpec pLogprobs[] = { P_INT("M"), P_INT("n_vocab"), P_INT("k"),
P_INTO("vocab_off") };
static const RadOperandSpec oLogprobs[] = { OPD("logits"), OPD("params"), OUT("stats") };
static const RadOperandSpec oNarrow[] = { INOUT("cand_idx"), INOUT("cand_val"), OPD("params") };
static const RadOperandSpec oPick[] = { OPD("cand_idx"), OPD("cand_val"), OPD("params"),
OUT("token") };
@@ -636,6 +639,9 @@ static const RadOpSchema kSchemas[] = {
"stream has to come out of a host reference, a device kernel and a rerun." },
{ "sample_merge_topk", ARR(pMCand), ARR(oMerge), "the vocab-parallel candidate merge." },
{ "sample_argmax", ARR(pMVocab), ARR(oArgmax), "greedy, ties to the lower token id." },
{ "sample_logprobs", ARR(pLogprobs), ARR(oLogprobs),
"the raw logits' max, sum of exp(l - max) and k largest (id, logit) pairs, for a row with "
"RAD_SP_LOGPROBS." },
{ "dflash_select", ARR(pDflashSelect), ARR(oDflashSelect),
"a greedy walk over a candidate lattice: score[l, c] = unary[l, c] + sum_r pred[pid(l)][r] * "
"hp[l][r] * succ[cand[l, c]][r], pid(0) the anchor and pid(l) the walk's own previous pick. "
@@ -878,6 +884,8 @@ SIMPLE("avx_sample_mask", "sample_mask", "sample", "grammar bitmask application"
SIMPLE("avx_sample_pick", "sample_pick", "sample", "seeded inverse-CDF draw", DT_FLOAT,
L(sample_pick)),
SIMPLE("avx_sample_argmax", "sample_argmax", "sample", "greedy pick", DT_FLOAT, L(sample_argmax)),
SIMPLE("avx_sample_logprobs", "sample_logprobs", "sample", "the raw distribution's summary",
DT_FLOAT, L(sample_logprobs)),
SIMPLE("avx_dflash_select", "dflash_select", "draft",
"DFlash2's greedy walk over the candidate lattice",
"i32 candidates and tokens, float unary and codebooks", L(dflash_select)),
+94
View File
@@ -650,6 +650,100 @@ AVX_KERNEL(sample_argmax) {
return RAD_OK;
}
/* ------------------------------------------------------------------ sample_logprobs */
/* The raw distribution's summary for a row with RAD_SP_LOGPROBS -- max, sum of exp(l - max), and
* the k largest as (id, logit) pairs, descending, ties to the lower id -- libref's contract
* (ref_sample.cpp). A row without the flag is not written.
*
* ONE PASS FOR THE k LARGEST, not k passes of topk_next_f32: `k` is the deployment's width (the
* largest top_logprobs any request may ask for), and k full sweeps of a 248K row would cost k times
* the argmax. The set is seeded with the row's first k columns, kept sorted, and the rest of the
* row is compared a vector at a time against its smallest value; a lane strictly above it is
* inserted. Strictly, because the scan runs in increasing id, and an equal value further along has
* the higher id and loses the tie. After the first few thousand columns almost no vector has such
* a lane, so the pass costs what the maximum does.
*
* The sum is f32 in four vector accumulators. Its terms are all in (0, 1] and the relative error
* of the sum is what a logprob carries (log of it), so f32 is ample next to libref's double. */
AVX_KERNEL(sample_logprobs) {
if (!rad_args_have(a, 3)) return RAD_E_INVAL;
const RadTensor *lg = &a->t[0], *pr = &a->t[1], *st = &a->t[2];
const int64_t n_vocab = p_int(a, "n_vocab", lg->rank >= 2 ? lg->shape[lg->rank - 1] : 0);
const int64_t k = p_int(a, "k", 0);
const int64_t voff = p_int(a, "vocab_off", 0);
if (n_vocab <= 0 || k <= 0) return RAD_E_SHAPE;
const int64_t M = numel(lg) / n_vocab;
const int64_t w = 2 + 2 * k;
if (M <= 0 || numel(st) < M * w) return RAD_E_SHAPE;
Rows R;
AVX_TRY(rows_of_params(pr, M, &R));
AVX_PARALLEL_FOR_IF(M * n_vocab >= AVX_PAR_MIN)
for (int64_t m = 0; m < M; ++m) {
if (!(R.p[m].flags & RAD_SP_LOGPROBS)) continue;
float* buf = scratch_f32((size_t)n_vocab + 2 * (size_t)k);
const float* v = in_row(lg, rowoff(lg, m, n_vocab), n_vocab, buf);
float* tv = buf + n_vocab; /* the set's values, descending */
int32_t* ti = (int32_t*)(tv + k); /* and their ids */
const float mx = row_max(v, n_vocab);
float sum = 0.0f;
{
const vf vmx = vf_set1(mx);
vf s0 = vf_zero(), s1 = vf_zero(), s2 = vf_zero(), s3 = vf_zero();
int64_t i = 0;
for (; i + 4 * VF_N <= n_vocab; i += 4 * VF_N) {
s0 = vf_add(s0, vf_exp(vf_sub(vf_loadu(v + i), vmx)));
s1 = vf_add(s1, vf_exp(vf_sub(vf_loadu(v + i + VF_N), vmx)));
s2 = vf_add(s2, vf_exp(vf_sub(vf_loadu(v + i + 2 * VF_N), vmx)));
s3 = vf_add(s3, vf_exp(vf_sub(vf_loadu(v + i + 3 * VF_N), vmx)));
}
for (; i + VF_N <= n_vocab; i += VF_N) s0 = vf_add(s0, vf_exp(vf_sub(vf_loadu(v + i), vmx)));
sum = vf_hsum(vf_add(vf_add(s0, s1), vf_add(s2, s3)));
for (; i < n_vocab; ++i) sum += std::exp(v[i] - mx);
}
/* Insert (x, id) into the sorted set of n entries, the set at most k long. */
int64_t n = 0;
auto insert = [&](float x, int32_t id) {
int64_t j = n < k ? n++ : k - 1;
while (j > 0 && x > tv[j - 1]) { tv[j] = tv[j - 1]; ti[j] = ti[j - 1]; --j; }
tv[j] = x;
ti[j] = id;
};
const int64_t seed = std::min(k, n_vocab);
for (int64_t i = 0; i < seed; ++i) insert(v[i], (int32_t)i);
int64_t i = seed;
#if AVX_LEVEL > 0
for (; i + VF_N <= n_vocab; i += VF_N) {
const vf x = vf_loadu(v + i);
#if AVX_LEVEL == 3
unsigned msk = (unsigned)_mm512_cmp_ps_mask(x, vf_set1(tv[k - 1]), _CMP_GT_OQ);
#else
unsigned msk = (unsigned)_mm256_movemask_ps(_mm256_cmp_ps(x, vf_set1(tv[k - 1]), _CMP_GT_OQ));
#endif
/* Lanes in increasing id; the bar can rise after each insertion. */
while (msk) {
const int lane = __builtin_ctz(msk);
msk &= msk - 1;
if (v[i + lane] > tv[k - 1]) insert(v[i + lane], (int32_t)(i + lane));
}
}
#endif
for (; i < n_vocab; ++i)
if (v[i] > tv[k - 1]) insert(v[i], (int32_t)i);
const int64_t sb = rowoff(st, m, w), ss = laststride(st);
stt(st, sb, mx);
stt(st, sb + ss, sum);
for (int64_t j = 0; j < k; ++j) {
stt(st, sb + (2 + 2 * j) * ss, j < n ? (float)(ti[j] + voff) : -1.0f);
stt(st, sb + (3 + 2 * j) * ss, j < n ? tv[j] : -INFINITY);
}
}
return RAD_OK;
}
/* ------------------------------------------------------------------ sample_merge_topk */
/* THE VOCAB-PARALLEL MERGE. lm_head is vocab-sharded, so each rank runs top-k over ITS OWN shard
* and the candidate sets are all-gathered -- k * world_size pairs, 2 KiB at k=64 and world_size=4,