radiance 1.0.11

- The n-gram embedding table (Qwen3.8-Flash-Next's per-layer embedding) can be gathered on the
  card. libr4d gains a row for embed_lookup_q whose output is the host gather's to the bit, and
  --ngram-placement uses it: ram keeps a pinned copy in RAM that the cards read in place over the
  link, so a step has no host work in it; vram puts the whole table on every card that holds it;
  disk reads it from the container on the host, as before. auto takes the first of the three that
  holds the table and prints why it passed over the others. Without a device kernel for the gather,
  ram is the locked copy the host gather reads and vram is refused, as in 1.0.10.
- The pinned copy is not charged to RLIMIT_MEMLOCK; the host gather's locked copy still is, so
  --ulimit memlock=-1 matters only on a run without the cards.
- The idea and a first kernel for the device gather came from Code000.
This commit is contained in:
Deadcode committed 2026-10-05 16:34:37 +02:00
1 parent e466fa07e2
commit 469441d90f
24 files changed
+848 -247

No files matched your search

+24
View File
@@ -1614,6 +1614,16 @@ static const RadOperandSpec oEmbed[] = {
{ "wte", RAD_OPD_WEIGHT, 0 },
{ "x", RAD_OPD_OUT, 0 },
};
/* The quantised gather's: libref's list (ref_registry.cpp), which the loader holds every plugin
* serving the op to -- a one-element `scale`, absent for a table stored plain, and `ahead`, the
* next prompt's ids for a host reader that fetches rows from a file. */
static const RadOperandSpec oEmbedQ[] = {
{ "tokens", RAD_OPD_IN, 0 },
{ "wte", RAD_OPD_WEIGHT, 0 },
{ "scale", RAD_OPD_WEIGHT, 1 },
{ "x", RAD_OPD_OUT, 0 },
{ "ahead", RAD_OPD_IN, 1 },
};
/* PLE's hashed n-gram ids. `state` is a rolling window of committed ids -- RAD_KV_CONV's shape and
* ple_conv's contract -- except that a cold window is EOS and not zero, because zero is a real
* token id. */
@@ -1821,6 +1831,11 @@ static const RadOpSchema kSchemas[] = {
"[vocab_offset, vocab_offset + n_vocab) -- which is what makes the table shardable "
"across the vocabulary, the symmetry lm_head already had. Ids stay GLOBAL; summing the "
"ranks reconstructs x, so the caller follows this with an exact all_reduce."),
SCHEMA("embed_lookup_q", pEmbed, oEmbedQ,
"the same gather from a table quantised with ONE scale for all of it: x[m] = "
"wte[id] * scale[0], an absent scale being one. Padding and bounds behave exactly as "
"embed_lookup's. `ahead` is the next prompt's ids, for a reader that fetches rows ahead "
"of the step; a kernel that reads its table in place ignores it."),
SCHEMA("ple_gate", pPleGate, oPleGate,
"PLE's gate. K = grouped_rmsnorm(k) * (w_key + wadd) and Q likewise over `q`, one rsqrt "
"per n-wide stream and one gain across all hc*n; s[c] = sum_d K[c][d]*Q[c][d] / sqrt(n); "
@@ -3137,6 +3152,15 @@ static const RadKernelInfo kKernels[] = {
nullptr, nullptr, r4d_rad_embed_lookup, nullptr, nullptr, nullptr,
r4d_shape_embed_lookup, nullptr, nullptr, r4d_rad_embed_lookup_describe },
{ "embed_lookup_q_bf16", "embed_lookup_q", "vocab",
"quantised embedding gather, four entries a thread",
"any n_embd and n_vocab; a negative or out-of-range id writes a zero row",
"i32 tokens, an E4M3 table with a bf16 or f32 scale or a plain bf16 one, bf16 output",
RAD_DOMAIN_DEVICE, R4D_PRIO_ONLY,
ROW(cBf16Row), NOTUNE,
nullptr, nullptr, r4d_rad_embed_lookup_q, nullptr, r4d_rad_layout_embed_q, nullptr,
r4d_shape_embed_lookup_q, nullptr, nullptr, r4d_rad_embed_lookup_q_describe },
{ "ple_gate_bf16", "ple_gate", "norm",
"PLE's dot-product gate, one workgroup a (row, stream) pair",
"n up to 4096 -- every reduction is over one stream's n and lives in a workgroup",