radiance 1.2.4

- EmbeddingGemma 2 (google/embeddinggemma-2): text, image, video and audio embeddings on the
  card (libr4d) and on the CPU (libavx); prompt_name, Matryoshka dimensions, image budgets,
  mixed content parts and the messages form on /v1/embeddings
- #43: on serves that lend the activation arena to the experts (Qwen3.8-Flash-Next with
  expert_tiered), every image after the first read its rows from the wrong place -- garbage
  replies, or an earlier request's image. Fixed
- the Qwen vision towers' attention resolves on the card again (broken on main after 1.2.3,
  never released)
- #42: a warning at startup when amdgpu cwsr_enable is 0, and a stalled queue is reported as
  slow or stuck; the guide covers the GPU-hang-and-reset chain
This commit is contained in:
Deadcode committed 2026-10-07 22:42:45 +02:00
1 parent 05af4db458
commit 7d840861af
76 files changed
+8324 -467

No files matched your search

+51
View File
@@ -13,6 +13,7 @@ into the id an architecture plugin claims.
| `arch/qwen35_fp8` | `qwen35` | `fp8_e4m3` | the same, block-scaled FP8 weights and activations |
| `arch/qwen35moe_fp8` | `qwen35moe` | `fp8_e4m3` | `qwen35_fp8` with the feed-forward routed |
| `arch/qwen4exp_fp8` | `qwen4exp` | *(empty)* | Qwen4-Exp (Qwen3.8-Flash-Next), a bf16 checkpoint quantised at convert |
| `arch/embgemma2` | `embeddinggemma2` | *(empty)* | EmbeddingGemma 2: a bidirectional encoder with Gemma 4's vision tower and audio conformer, pooled to one vector |
This document is the geometry of each, and the handful of readings that are **arithmetically
silent** — wrong in a way that produces fluent output and no error anywhere.
@@ -395,3 +396,53 @@ N = 160 — wide enough that formats which differ by less than that rank in any
graded statistic that has thousands of samples rather than hundreds (the mean |delta| over the
logits row, or the per-position KL of `radiance --kld-ref`), and confirm any ordering at N ≥ 160
before acting on it.
---
# `embeddinggemma2` — an embedding model
`arch/embgemma2` declares a POOLED output (`rad_declare_pooled`) and no logits, which makes the
program an embedding program: the engine runs it with no sampler and no KV cache, carries every
input whole in one step, and returns each sequence's pooled row on `/v1/embeddings`
([GUIDE §5.6](GUIDE.md)). One card (`--tp 1`).
```
text 24 layers, hidden 512, ffn 2048 (gelu-tanh, gated), vocab 262144
layer_types: five sliding (|i-j| <= 512, 4 x 256, 2 kv heads, theta 1e4) then one full
(4 x 512, 1 kv head, theta 1e6), four times; BIDIRECTIONAL everywhere, scale 1
q, k RMS-normed with a gain, v without; sandwich norms with plain gains
per-layer inputs: the embedding projected to 24 x 512 and normed, gating a 512 bottleneck
a learned scalar a layer on the residual; mean over every token, then 512 -> 768
vision Gemma 4's: 16 layers of 768 (12 x 64), a learned row/column table, a two-block 2-D rotary
(x on the first half of a head, y on the second, theta 100), 3 x 3 mean pooling * sqrt(768),
an unscaled RMS norm and 768 -> 512; up to 280 soft tokens an image by default
audio Gemma 4's USM conformer: two stride-2 3 x 3 convolutions over (time, mel), 12 blocks
(half-weight feed-forwards, local attention 11 back with a relative-position term and a
softcap of 50, a gated depthwise causal convolution), clipped linears; 1024 -> 1536 ->
embedder -> 512; 4 frames (40 ms) a token, clips cut at 30 s
```
The traps:
- **The embedding scale is the bf16 of sqrt(512)**, 22.625, because the reference stores it as a
bf16 buffer. sqrt(512) itself is off by one part in 800 on every embedding.
- **A media row replaces its placeholder's embedding before the per-layer inputs are projected.**
The per-layer input of an image token is computed from its image row, not from the placeholder
id's embedding.
- **The vision rotary is two independent neox rotaries**, one over each half of a head (`qk_norm_rope`
mode `blocks`). `rope` mode `axial` pairs across the halves and is a different function.
- **The vision pooler stores the mean in bf16 before scaling it by sqrt(768)** (`pool_rows`), and
the processor lays each 3 x 3 window's patches out consecutively so the pooler is a mean of nine
consecutive rows; attention and both position terms read each patch's own coordinates.
- **The audio subsampler masks its input to the clip's real frames before each convolution**: the
second convolution reads the first one's output at frame 2t's validity (`conv2d`'s `valid`
operand, stride 2), which zeroes the one row past the real ones that the zero padding alone
would not.
- **The audio attention reaches 11 rows back, not 12.** The config says `attention_context_left`
13 and the chunked layout fetches 12 keys behind each block, but the mask transformers applies
keeps a key only when `0 <= q - k < context_left - 1`. Twelve back drifts a few percent a block
and leaves rows at cosine 0.6 by the last one.
- **An audio clip's tokens are ceil(real frames / 4)**, real frames being those whose last sample
is a real one; the processor stages exactly those plus zero frames to whole rows, which
reproduces every row the reference keeps.
+44 -2
View File
@@ -1096,7 +1096,8 @@ for a model that takes no images or video.
| `--video-min-pixels N`, `--video-max-pixels N` | container's | the same for a video's sampled frames together |
| `--video-fps F` | container's, else 2 | frames sampled per second of video |
| `--video-min-frames N`, `--video-max-frames N` | container's, else 4 and 768 | the fewest and most frames sampled from a video |
| `--video-max-frame-tokens N` | container's, else 768 | the most prompt tokens one frame may become; 0 is no cap |
| `--video-max-frame-tokens N` | container's, else 768 | the most prompt tokens one frame may become; 0 is no cap. A token-budget processor (Gemma 4's) takes 70, 140, 280, 560 or 1120 |
| `--image-tokens N` | container's | a token-budget processor's image budget (Gemma 4's: 70, 140, 280, 560, 1120); a request's `image_tokens` overrides it. The pixel-band flags are refused on such a model |
| `--max-source-pixels N` | 67108864 | the largest image or frame the decoder accepts, before any resize |
**Quality measurement** — instead of serving; see [TOOLS.md](TOOLS.md#the-kl-mode)
@@ -1304,6 +1305,45 @@ curl -s http://localhost:8000/detokenize -H 'Content-Type: application/json' \
`/tokenize` takes `prompt` **or** `messages`, not both.
**An embedding model** (EmbeddingGemma 2) serves `/v1/embeddings` and nothing else; completions and
chat answer 501. One input is one vector, and an input is never split: it has to fit one step
(`--max-num-batched-tokens`), and a longer one is refused with `context_length_exceeded`.
```sh
# text, a batch of texts, or token ids
curl -s http://localhost:8000/v1/embeddings -H 'Content-Type: application/json' \
-d '{"input":["first document","second document"]}'
# the model's named prompt in front ("query" -> "task: search result | query: ")
curl -s http://localhost:8000/v1/embeddings -H 'Content-Type: application/json' \
-d '{"input":"what is the capital of France?","prompt_name":"query"}'
# Matryoshka: the first 256 dimensions, renormalised
curl -s http://localhost:8000/v1/embeddings -H 'Content-Type: application/json' \
-d '{"input":"hello","dimensions":256}'
# one vector for text and media together: content parts, in order
curl -s http://localhost:8000/v1/embeddings -H 'Content-Type: application/json' \
-d '{"input":[{"type":"text","text":"a photo of "},
{"type":"image_url","image_url":{"url":"data:image/png;base64,..."}}],
"image_tokens":560}'
# or the chat form, rendered through the model's template
curl -s http://localhost:8000/v1/embeddings -H 'Content-Type: application/json' \
-d '{"messages":[{"role":"user","content":[{"type":"input_audio",
"input_audio":{"data":"<base64 wav>","format":"wav"}}]}]}'
```
`input` is a string, an array of token ids, one array of content parts, or a batch of any of
those. A content part is `text`, `image_url`, `video_url`, `input_audio` (wav, mp3, flac, ogg,
opus, m4a, aac, webm or aiff, base64) or `audio_url`; media comes as `data:` URLs, never fetched.
An image becomes up to 280 tokens by default (`--image-tokens`, or a request's `image_tokens`: 70,
140, 280, 560 or 1120), a video one frame a second, at most 32 frames of 140 tokens
(`--video-fps`, `--video-max-frames`, `--video-max-frame-tokens`), and audio 25 tokens a second,
cut at 30 seconds. `prompt_name` takes the names the model's sentence-transformers configuration
states (`query`, `document`, `Retrieval-query`, `STS`, ...) and applies to text and content-part
inputs; a model that states a default prompt applies it when the request names none.
### 5.7 Request fields
| field | notes |
@@ -1334,7 +1374,8 @@ curl -s http://localhost:8000/detokenize -H 'Content-Type: application/json' \
| `response_format` | chat only. Mutually exclusive with `grammar` |
| `grammar` | a GBNF grammar directly. On chat it passes through the chat template and a template that drops it makes the request a refusal — see §5.5 |
| `echo` | `/v1/completions` only |
| `encoding_format` | `/v1/embeddings` only: `float` or `base64`. `dimensions` is refused — the embedding width is fixed |
| `encoding_format` | `/v1/embeddings` only: `float` or `base64` |
| `dimensions`, `prompt_name`, `image_tokens` | `/v1/embeddings` only (an embedding model, §5.6). `dimensions` truncates to the first N and renormalises; it cannot exceed the model's width |
Any field the request omits keeps the deployment default (§4.9). A field the request names wins.
@@ -1604,6 +1645,7 @@ released until it does.
| `out of memory` / `the carve reserved N of address space and the card would not back it` | Something else is holding VRAM | Check with `rocm-smi`; stop the other process. The budget is stated before allocation, so the log says what it asked for |
| `pool allocation refused` with `backing allocation of … refused` on the second card, after the first card's pools succeeded | The VRAM budget is measured before any rank allocates. A card that refuses its weights pool lost that memory to another process in between (the line below the refusal says how much is free now). A refused `host_pool` is pinned memory: **every rank pins its own `--host-pool-mib`**, so `--tp 2` pins it twice, and the amdgpu driver caps pinned memory system-wide at `ttm.pages_limit`, half of RAM by default | Stop the other process (`rocm-smi --showpids`). For the host pool, keep `--tp` × `--host-pool-mib` under the cap the refusal names, or raise it with the kernel parameter `ttm.pages_limit` |
| `host_pool: backing allocation of … refused: rad_dev_alloc(…): locking piece K of N`, and `failed to pin userptr` in `journalctl -k` | The IOMMU would not DMA-map one piece of the pinned host pool. Pinned host memory is locked in pieces of at most 1 GiB because an Intel VT-d host in scalable mode was seen to refuse any single pin above about 2.5 GiB; a piece failing means this machine refuses smaller pins still, or a total its IOMMU will not map | Keep IOMMU translation on: `iommu=pt` lets every pin through but on that host also removed peer access between the cards, which moves every all-reduce onto the slower host-memory path. Report the kernel version, the IOMMU mode and the refusal line |
| `a synchronisation has waited 5 s` naming a kernel, then `no queue has advanced`, then `HW Exception … GPU Hang` and a reset in `journalctl -k` (`MES failed to respond to msg=REMOVE_QUEUE`, `MODE1 reset`) | The card stopped running the queue. The kernel named is where it stopped, not necessarily why. The driver resets the whole card, VRAM included, and the engine is aborted. The usual cause is compute wave save/restore being off: the driver evicts a process's queues whenever host memory the card maps is moved under memory pressure, and with `cwsr_enable=0` it cannot preempt a running queue, so the eviction waits for a queue a serve never lets drain. A voltage offset or other clock instability is the other cause seen on R9700s. If the stall line says the queues **advanced**, the wait was long rather than stuck, and nothing is wrong | `cat /sys/module/amdgpu/parameters/cwsr_enable` must print `1` (the engine warns at startup when it is `0`); set `amdgpu.cwsr_enable=1`, rebuild the initramfs and reboot. Remove any `OD_VDDGFX_OFFSET` (`pp_od_clk_voltage`). A reset puts the power cap, fan curve and voltage offset back to firmware defaults, so re-apply them before every start rather than once at boot. Keep the devcoredump under `/sys/class/drm/card*/device/devcoredump/data`; a reboot loses it. `docker inspect` shows exit code 0 for a container Docker has already restarted, which says nothing about how the old process ended |
| `--draft-model is not implemented` | This engine loads its drafter from the container | `rad-convert --draft-model DIR` at conversion time |
| `context_length_exceeded` on a request | The **prompt alone** does not fit the context. `max_tokens` is clamped rather than refused, so this fires only when there is no room left to generate at all | Shorten the prompt by the number of tokens the message names, or raise `--max-model-len` if the model allows it |
| `unknown option '--foo'` and the engine exits | Deliberate. A typo in a budget flag is the difference between the plan you asked for and one the planner invented | Check `radiance --help` |
+95 -6
View File
@@ -158,7 +158,7 @@ adding a kernel plugin; "refused at load" names one op and leaves you to find th
| op | params | operands |
|---|---|---|
| `rmsnorm` | `M`(range) `n` `eps`:f64 `dtype` `wadd`:f64/opt | `x`, `w`w → `y` |
| `rmsnorm` | `M`(range) `n` `eps`:f64 `dtype` `wadd`:f64/opt `mult`:f64/opt | `x`, `w`w? → `y` (no gain operand: a gain of one) |
| `rmsnorm_add` | `M`(range) `n` `eps`:f64 `dtype` `wadd`:f64/opt | `x`, `residual`, `w`w → `y`, `residual_out` |
| `hc_enter` | `M`(range) `n` `hc` `dtype` | `x` → `h` |
| `hc_read` | `M`(range) `n` `hc` `lowrank` `eps`:f64 `dtype` `wadd`:f64/opt `inject`/opt `group`/opt `rotate`/opt `mix`/opt | `h`, `w`w, `mix_down`w, `mix_up`w, `inject_w`w? → `x`, `inj`?, `q`?, `scale`?, `rq`?, `rscale`? |
@@ -168,6 +168,15 @@ adding a kernel plugin; "refused at load" names one op and leaves you to find th
| `add` | `M`(range) `n` `dtype` | `a`, `b` → `y` |
| `mul` | `M`(range) `n` `dtype` | `a`, `b` → `y` |
| `silu_mul` | `M`(range) `n` `dtype` | `gate_up` → `y` (splits `[M,2n]` into gate·up) |
| `mul_weight` | `M`(range) `n` `dtype` `scalar`/opt | `x`, `w`w → `y` (w one element or one row) |
| `act_mul` | `M`(range) `n` `act` `dtype` | `a`, `b` → `y` (act(a)·b, two operands) |
| `seg_mean` | `M`(range) `n` `dtype` | `x`, `cu_seqlens` → `y` (one mean row a segment) |
| `pool_rows` | `M`(range) `n` `k` `mult`:f64/opt `dtype` | `x` → `y` (one mean row a window of k rows) |
| `relu` | `M`(range) `n` `dtype` | `x` → `y` |
| `clamp` | `M`(range) `n` `dtype` | `x`, `lo`w, `hi`w → `y` |
| `conv2d` | `M`(range) `width` `cin` `cout` `kh` `kw` `stride` `pad` `cu_div`/opt `valid_stride`/opt `dtype` | `x`, `w`w, `cu_seqlens`, `valid`? → `y` |
| `conv1d_dw` | `M`(range) `n` `k` `cu_div`/opt `dtype` | `x`, `w`w, `cu_seqlens` → `y` |
| `rel_sinusoid` | `M`(range) `n` `max_timescale`:f64/opt `dtype` | → `y` |
| `gelu` / `silu` | `M`(range) `n` `dtype` | `x` → `y` |
| `cast` | `M`(range) `n` `from` `to` | `x` → `y` |
| `softmax` | `M`(range) `n` `dtype` | `x` → `y` |
@@ -224,6 +233,54 @@ attention-zero rank's block (`docs/TP3.md`) is one `fill` of its output wire bef
A wire shared across layers cannot be zeroed once a step, and a memset knows neither the row pitch
nor the dtype; this does.
**`mul_weight`** is a learned gain on an activation: `w` is a WEIGHT of one element, a scalar for
the whole output -- Gemma 4's per-layer `layer_scalar` on the residual stream -- or of one row,
broadcast down the rows (a per-channel layer scale). Its own op rather than a form of `mul`
because an operand is a weight or an activation by its schema, and `mul`'s `b` is an activation.
`scalar` 1 states the one-element form; kernels read the form off the operand, and the parameter
is what lets a shape description (rad-kbench's) build the right weight.
**`act_mul`** is `silu_mul` with its two halves in two operands, so the multiplier can be any
tensor -- the two column slices of a fused `gate_up`, or a gate and a separate per-layer input
(EmbeddingGemma 2's per-layer-embedding block multiplies `gelu_tanh(gate(x))` by one). `act` is
`silu`, `gelu` (exact erf), `gelu_tanh` or `sigmoid` (a GLU's gate: `a` the gate half, `b` the
value half); the activation is rounded to `y`'s dtype before the product, which is what the
unfused pair stores.
**`seg_mean`** is a sentence embedding's mean pooling over a ragged batch: row `s` of `y` is the
mean of `x`'s rows `[cu[s], cu[s+1])`, summed in double and rounded once. `M` is the step's token
count and bands the op; the segment count is `cu_seqlens`' length less one. An empty segment is a
zero row.
**`pool_rows`** is a vision pooler over windows its processor laid out consecutively: row `r` of `y`
is the mean of `x`'s rows `[r*k, r*k + k)`, summed in f32 and rounded to `y`'s dtype, then times
`mult` and rounded again (the unfused pair stores the mean). `M` is the input row count and a
multiple of `k`.
**`rmsnorm`'s `mult`** scales the normed row before its one rounding: a residual branch weighted by
a constant -- Gemma 4's audio feed-forward adds half of its output -- with no second pass. For a
power of two it is exactly the reference's norm-then-scale, since scaling by one commutes with the
rounding.
**The audio tower's operators** (Gemma 4's USM conformer):
- **`relu`** is `max(x, 0)` at each operand's own row pitch.
- **`clamp`** is `min(max(x, lo), hi)` with `lo` and `hi` WEIGHTS of one element each -- a clipped
linear's input or output range, which the checkpoint states per projection.
- **`conv2d`** convolves over (time, width) with channels innermost: element `(t, w, c)` of `x` is
at row `t`, column `w * cin + c`, and `w` is PyTorch's `[cout, cin, kh, kw]`. Each `cu_seqlens`
segment -- rows `[cu[s] / cu_div, cu[s+1] / cu_div)` -- is convolved on its own with zero padding
`pad` at its edges on both axes, so two clips in one pass never see each other, and its output
rows start at `cu[s] / (cu_div * stride)` (a segment whose start does not divide is refused).
With the optional `valid`, input row `t` reads as zeros unless `valid[t * valid_stride] != 0`:
the frame mask the subsampler multiplies in before each convolution. f32 sum, one rounding.
- **`conv1d_dw`** is a causal depthwise convolution over time, `y[t, c] = sum_j w[c, 0, j] *
x[t - (k - 1) + j, c]`, with the rows before the segment's start reading as zeros.
- **`rel_sinusoid`** writes the sinusoidal relative-position table, row `d` for distance `d`:
`sin(d * inv[i])` over the first half and `cos(d * inv[i])` over the second, `inv[i] = exp(i *
-log(max_timescale) / max(n/2 - 1, 1))`, each step in f32 as the reference's torch expressions
are, then rounded.
## Quantisation and rotation
| op | params | operands |
@@ -369,11 +426,22 @@ that folds dequantisation into its epilogue still receives them.
| op | params | operands |
|---|---|---|
| `attn_paged` | `q_len`(range) `head_dim` `gqa` `block_size`/der `causal` `window` `q_dtype` `kv_dtype` `scale`:f64/opt `max_ctx`/opt `n_head`/opt `max_seqs`/opt | `q`, `kv_cache`, `block_table`, `seqused`, `k_descale`?, `v_descale`?, `cu_seqlens`? → `out` |
| `attn_dense` | `M`(range) `head_dim` `gqa` `causal` `dtype` `scale`:f64/opt `max_seqlen`/opt | `q`, `k`, `v`, `cu_seqlens` → `out` |
| `attn_dense` | `M`(range) `head_dim` `gqa` `causal` `dtype` `scale`:f64/opt `max_seqlen`/opt `window`/opt | `q`, `k`, `v`, `cu_seqlens` → `out` |
| `attn_local_rel` | `M`(range) `head_dim` `n_head` `left` `right` `softcap`:f64 `cu_div`/opt `dtype` | `q`, `k`, `v`, `relk`, `pds`w, `cu_seqlens` → `out` |
| `kv_store` | `M`(range) `head_dim` `n_head_kv` `block_size` `kv_dtype` `k_scale`:f64/opt `v_scale`:f64/opt | `k`, `v`, `slot_mapping`, `kv_cache`:inout |
| `rope` | `M`(range) `head_dim` `n_head` `n_head_kv` `theta`:f64 `scale`:f64 `mode` `rotary_dim`/opt `sections`/opt `yarn_factor`:f64/opt `yarn_low`:f64/opt `yarn_high`:f64/opt `yarn_magnitude`:f64/opt | `qkv`:inout, `positions` |
| `rope_table` | `M`(range) `rot` `theta`:f64 `scale`:f64 `dtype` `yarn_factor`:f64/opt `yarn_low`:f64/opt `yarn_high`:f64/opt `yarn_magnitude`:f64/opt | `positions` → `cos_sin` |
| `qk_norm_rope` | `M`(range) `head_dim` `n_head` `n_head_kv` `theta`:f64 `eps`:f64 `scale`:f64/opt `mode`/opt `rotary_dim`/opt `wadd`:f64/opt | `qkv`:inout, `positions`, `q_w`w, `k_w`w |
| `qk_norm_rope` | `M`(range) `head_dim` `n_head` `n_head_kv` `theta`:f64 `eps`:f64 `scale`:f64/opt `mode`/opt `rotary_dim`/opt `wadd`:f64/opt `v_norm`/opt `sections`/opt `comps`/opt | `qkv`:inout, `positions`, `q_w`w, `k_w`w |
**`attn_local_rel`** is Gemma 4's audio attention: local, with a relative-position term and a
softcap. Query row `i` of a segment sees the key rows `j` of the same segment with `0 <= i - j <=
left` (`right` must be 0). Per head, `qf = q * (head_dim^-0.5 / ln 2) * softplus(pds)` -- softplus
rounded to `pds`'s dtype, as the reference evaluates it on the parameter -- and `logit = qf . k *
(ln(1 + e) / ln 2) + qf . relk[i - j]`, then `softcap * tanh(logit / softcap)`, a softmax over the
visible keys and the weighted sum of `v`, all in f32 and rounded once. `relk` is `[left + 1,
n_head * head_dim]`, row `d` the projected position for distance `d`. The reference computes this
in 12-query blocks over 24-key windows with a Transformer-XL shift; every key outside the window
carries a `-1e9` logit there, so the sliding form is the same function.
`attn_paged` is the ranged op whose band is `q_len`, not `M`: one query row at decode, up to 64 at
a speculative verify, thousands in a prefill chunk, and libr4d has a different kernel for each
@@ -388,11 +456,24 @@ row each — is what the scheduler builds whenever prefill and decode coexist, a
satisfy the uniform form. `q_len` is then the batch MAXIMUM, which is what selects the band; the
per-sequence lengths come from `cu_seqlens` alone.
`attn_dense` is the vision tower's: non-causal, nothing paged, `cu_seqlens` bounding one image per
entry so a whole batch is one launch. `q`, `k` and `v` may each be `[tokens, heads, head_dim]` or
`attn_dense` is the vision tower's and an encoder's: nothing paged, `cu_seqlens` bounding one
image or one input per entry so a whole batch is one launch. `window` is `attn_paged`'s rule over a
segment's own positions -- causal, key `j` is visible to query `i` when `i - j < window`;
non-causal, when `|i - j| < window` -- and 0 is no window. A bidirectional encoder's sliding layer
of radius `r` (`|i - j| <= r`) is `window = r + 1`. `q`, `k` and `v` may each be `[tokens, heads, head_dim]` or
`[tokens, heads * head_dim]`, and the second form may be a column slice of a fused projection read
at that projection's row pitch -- which is how a tower's `[q|k|v]` row reaches it without a copy.
**`qk_norm_rope`'s `v_norm`** set to 1 also RMS-norms every v head of the fused row with a UNIT
gain and does not rotate it: Gemma 4's value norm, which has no weight to name.
**`qk_norm_rope`'s `blocks` mode** rotates each section as its own block of channels: section `c`
is `sections[c]` pairs over the next `2 * sections[c]` channels, paired `(start + j, start +
sections[c] + j)` -- NeoX inside the block -- and turned by position component `comps[c]` (default
`c`) at `theta^(-j / sections[c])`. The sections fill `rotary_dim` exactly and `positions` is
`[C, M]`. It is Gemma 4's vision rotary: x over the first half of each head and y over the second,
each half a complete rotary of its own; `mode` `axial` of `rope` pairs across the halves instead.
**`rope`'s multi-component modes.** `mrope`, `imrope` and `axial` rotate with NeoX pairing and let
several position components drive different frequencies. `positions` is then `[C, M]`,
component-major, and `sections` names how many of the `rotary_dim / 2` frequencies each component
@@ -823,7 +904,7 @@ form exists, as for `ar_hc_write`.
| op | params | operands |
|---|---|---|
| `embed_lookup` | `M`(range) `n_embd` `n_vocab` `dtype` `vocab_offset`/opt `wscale`:f64/opt | `tokens`, `wte`w → `x` |
| `embed_lookup` | `M`(range) `n_embd` `n_vocab` `dtype` `vocab_offset`/opt `wscale`:f64/opt `mult`:f64/opt | `tokens`, `wte`w → `x` |
| `embed_lookup_q` | `M`(range) `n_embd` `n_vocab` `dtype` `vocab_offset`/opt `wscale`:f64/opt | `tokens`, `wte`w, `scale`w? → `x`, `ahead`? |
| `logits_gemm` | `M`(range) `n_vocab` `n_embd` `dtype` | `x`, `lm_head`w → `logits` |
| `ngram_ids` | `M`(range) `heads` `ngram` `eos` | `tok`, `state`:inout, `cu`, `mult`w, `vocab_sizes`w, `offsets`w, `cache_idx`?, `has_init`?, `num_accepted`? → `ids`, `ahead_ids`? |
@@ -880,6 +961,14 @@ bf16 would matter, because `libref` is the oracle for every op here and its bf16
float, which is not guaranteed to return a NaN payload unchanged. At u8 every value is 0..255,
float carries it exactly, and oracle and kernel agree bit for bit on any payload at all.
### `embed_lookup`'s `mult`
Every gathered row multiplied by `mult` and rounded once to `x`'s dtype; absent, the gather is a
plain copy. Gemma scales its embedding by `sqrt(hidden)` held in a bf16 buffer, so the plugin
passes that value rounded to bf16 (22.625 at a hidden of 512, not 22.6274) and the product is the
reference's to the bit. `wscale` is not this: it is the scale `embed_lookup_q`'s layout quantises
with, and `embed_lookup` reads none.
### `embed_lookup`'s `vocab_offset`
`vocab_offset` (optional, default 0) is the first vocabulary row this rank holds. With it,