radiance 1.9.0

New models:
- LTX-2.5 (base and distilled): video with a stereo soundtrack from text or from text and a first
  frame, on one card, with its duration head, tiled VAE decoding, the diffusion decoder and the x2
  latent upsampler
- Krea 2 Raw and Turbo, and FLUX.3 [klein] and its base: text to image, and for FLUX.3 edits from up
  to ten reference pictures, on one card
- GLM-5.3-Flash from AMD's Quark MXFP4 export, on eight cards (John McDonough, Nunze)
- Gemma 3 / TranslateGemma 27B with an optional DFlash2 drafter (mici81)

Engine:
- --kv-cache-dtype fp8_v4 and k6_v4 for Gemma 3 and Qwen3.8-Flash-Next (mici81)
- the rotated int8 trunk (i8a8h) for Qwen3.8-27B (eddie168168)
- eight-rank all-reduce bands, weighted shards and pieces (Nunze); --host-headroom-mib (sfjes)
- the dashboard shows the single-stream decode floor and its most recent window (Memoria)

Fixes: prefix-cache reservations kept until their save lands (baKon), tool calls in Responses
namespaces (#119), system messages merged when a template refuses several (#137), a prefill
continued with no open step (#127), calibration of a Gram accumulation (#122), JSON Schema patterns
read unanchored (davetha), GLM-style tool calls, the KV floor counting every sequence's state.
Plugin ABI 24.
This commit is contained in:
Deadcode committed 2026-10-19 21:58:07 +02:00
1 parent 778cbf315e
commit 685ec5bd85
136 files changed
+18917 -3821

No files matched your search

+205 -13
View File
@@ -21,10 +21,14 @@ plugin claims.
| `arch/gemma3` | `gemma3` | *(empty)* | Gemma 3 dense text (TranslateGemma 27B) from the bf16 checkpoint: sliding-window and global attention at one head geometry, GemmaRMSNorm, GELU ffn; linears bf16, or int8, MXFP4 or asymmetric int4 over an activation scaled per (row, 128), as the recipe stores them. Optional DFlash2 drafter (`rad-convert --draft-model`) |
| `arch/gemma4` | `gemma4` | *(empty)* | Gemma 4 text from Google's bf16 checkpoint (the 26B-A4B MoE and the dense sizes without per-layer embeddings) with z-lab's DFlash drafter; routed experts bf16 or block fp8 |
| `arch/qwenimage21` | `qwenimage21` | *(empty)* | Qwen-Image 2.1 and 2.1-Turbo, an image generator, from the diffusers pipeline directory; DiT and text encoder bf16 or block fp8 |
| `arch/krea2` | `krea2` | *(empty)* | Krea 2 Raw and Turbo, an image generator: Qwen3-VL-4B's tapped layers through a text-fusion transformer, a 12.9B single-stream DiT and Wan 2.1's VAE, from the diffusers pipeline directory; bf16 or block fp8 |
| `arch/flux3` | `flux3` | *(empty)* | FLUX.3 [klein] and its base, an image generator and editor: Qwen3-VL-4B's tapped layers, a 5.6B three-mode DiT over the text, up to ten reference pictures and the image, FLUX.2's VAE; bf16 or block fp8 |
| `arch/flux3distilled` | `flux3distilled` | *(empty)* | the same plugin under the name FLUX.3 [klein]'s step-distilled release gives itself (`Flux3DistilledModularPipeline`; its base is a `Flux3ModularPipeline`) |
| `arch/qwen3asr_bf16` | `qwen3asr` | *(empty)* | Qwen3-ASR: a Whisper-style audio encoder over a dense Qwen3 decoder, speech to text |
| `arch/minimaxmusic3` | `minimaxmusic3` | *(empty)* | MiniMax-Music3, songs from a description and lyrics: a Qwen3-8B frame model, a depth decoder, a flow-matching DiT and a DAC vocoder, from the diffusers pipeline directory, bf16 |
| `arch/breeze` | `breeze` | *(empty)* | Breeze-TTS-2, speech from text and a description of the voice: a T5Gemma 2 text encoder, a Qwen3 backbone with a 16-codebook depth decoder and the Qwen3-TTS 12 Hz codec, from the release directory, bf16, one card |
| `arch/minimaxh3` | `minimaxh3` | *(empty)* | MiniMax-H3, a video with its stereo soundtrack from text: Qwen3-VL-32B's language model as the text encoder, a 33B single-stream diffusion transformer, a tiled ViT video decoder and a BigVGAN audio decoder, from the diffusers pipeline directory; linears block fp8 (`data/recipes/minimax-h3-fp8.recipe`) |
| `arch/ltx2` | `ltx2` | *(empty)* | LTX-2.5 (base and distilled), a video with its stereo soundtrack from text or from text and a first frame: Gemma 4's language model and two text connectors, the duration head, a dual-stream audio-video DiT with four-way guidance, the causal video VAE (tiled past the default canvas) or the diffusion decoder, the audio VAE with a BigVGAN vocoder and bandwidth extension, the x2 latent upsampler; bf16 or block fp8, one card |
The traps below are readings that are wrong without any error: the model produces fluent output.
@@ -195,7 +199,7 @@ Three groups, which is why hybrid KV groups are first-class:
| group | kind | geometry |
|---|---|---|
| full attention | `RAD_KV_FULL` | 16 layers, head_dim 256, 4 KV heads; block size from the resolved kernel. `--kv-cache-dtype fp8_v4` / `k6_v4` (`qwen35_fp8` only) declare it at head_dim 200 / 176, the bytes of a token's quantised row over two (docs/OPS.md) |
| full attention | `RAD_KV_FULL` | 16 layers, head_dim 256, 4 KV heads; block size from the resolved kernel. `--kv-cache-dtype fp8_v4` / `k6_v4` (`qwen35_fp8`; `qwen4exp_fp8` too) declare it at head_dim 200 / 176, the bytes of a token's quantised row over two (docs/OPS.md) |
| GDN recurrent state | `RAD_KV_LINEAR` | 48 layers, 48 states of 128 x 128 |
| GDN conv state | `RAD_KV_CONV` | 48 layers, 2*16 + 48 = 80 heads x 128 = 10240 channels, a rolling `conv_width - 1 + n_spec` window |
@@ -301,6 +305,11 @@ plugin reads each weight's encoding from the container and declares the op that
- bf16: every norm gain, `A_log`, `dt_bias`, `conv1d`, `in_proj_a` and `in_proj_b` (48 rows is not
a whole scale block), the router, `shared_expert_gate` and `embed_tokens`.
**The attention cache takes `--kv-cache-dtype fp8_v4` or `k6_v4`.** The QSA layers' cache (and the
MTP head's layer, which shares it) is then declared at head_dim 200 or 176, a token's quantised row
over two, and read by the gqa12 rows (gqa6 with 4-token pages at four ranks) of those layouts
(docs/OPS.md). The indexer's key cache and tail keep their widths.
`data/recipes/qwen4exp-w4nl64-i8-hc8m.recipe` is the served choice: four-bit codebook experts with
ten protected experts left bf16, int8 block linears and lm_head, E4M3 mixing and MTP fc matrices,
and the n-gram table at one fixed E4M3 scale.
@@ -488,26 +497,25 @@ and 8.
- The indexer is replicated whole.
- The vocabulary is row-sharded, 19360 rows a rank at eight; the embedding's all-reduce is exact.
- The f32 projections (the router's 288 x 4096, the index head gates' 32 x 4096, each
connection's mHC projection of 24 x 16384) are replicated. From a pass of
`RADIANCE_GLM_TP_SPLIT_ROWS` rows (default 256; 0 never), each rank computes a disjoint part
connection's mHC projection of 24 x 16384) are replicated. From a pass of 256 rows
(`kGlmTpSplitRows`, `arch/common/rad_tp_split.h`), each rank computes a disjoint part
with the replicated kernel and an `all_gather` joins the parts, so every value is
bit-identical: the router and the head gates split their output columns, the mHC projection
its 16384-wide input into eight 2048-column chunks, whose partials `mhc_pre_finish` completes
on every rank. Below the threshold, as in decode, the collective costs more than it saves.
**MoE decode fusions.** Three, each byte-identical to the launches it replaces, on unless its
variable is `0`; any value but `0` or `1` refuses the start.
**MoE decode fusions.** Three, each byte-identical to the launches it replaces, declared
wherever a loaded library serves the fused op (the separate launches otherwise):
| variable | one launch for | where it applies |
| fusion | one launch for | where it applies |
|---|---|---|
| `RADIANCE_GLM_ROUTER_FUSE` | `router_sigmoid_topk`, `moe_scatter` and the shared gate's `fill`: `router_sigmoid_topk_scatter` | passes of up to 128 rows (`M * top_k` <= 1024, one workgroup's sort); 84 launches fewer a trunk decode step, 2 a draft pass |
| `RADIANCE_GLM_SWIGLU_QUANT` | `swiglu_clamped` and `quant_act_fp8`: `swiglu_clamped_quant_fp8` | the routed and shared arms and the three dense layers; 87 fewer a trunk step, 2 a draft pass |
| `RADIANCE_GLM_GATHER_INVERSE` | none: the sort writes each slot's row (`moe_scatter_inv`) and the gather reads it (`moe_gather_inv`) instead of searching `sorted` | every MoE pass |
| router | `router_sigmoid_topk`, `moe_scatter` and the shared gate's `fill`: `router_sigmoid_topk_scatter` | passes of up to 128 rows (`M * top_k` <= 1024, one workgroup's sort); 84 launches fewer a trunk decode step, 2 a draft pass |
| SwiGLU | `swiglu_clamped` and `quant_act_fp8`: `swiglu_clamped_quant_fp8` | the routed and shared arms and the three dense layers; 87 fewer a trunk step, 2 a draft pass |
| gather inverse | none: the sort writes each slot's row (`moe_scatter_inv`) and the gather reads it (`moe_gather_inv`) instead of searching `sorted` | every MoE pass |
With all three at `0` the graph and the launches are those
`glm53_without_fusion_switches_is_the_pinned_graph_and_steps` pins. Paired on the eight R9700s
below, greedy text at a fixed draft depth of 3 is identical with and without them, and eight
agent streams decode 456 tok/s against 452, one 144 against 140.
`glm53_moe_decode_fusions_replace_their_launches_where_they_fit` counts the launches. Paired on
the eight R9700s below, greedy text at a fixed draft depth of 3 is identical with and without
them, and eight agent streams decode 456 tok/s against 452, one 144 against 140.
**Measured** on eight R9700s (gfx1201, 32 GB; four on PCIe Gen5 x16, four on Gen5 x8) at TP8 with
the flags of `deploy/compose/glm53-flash.yaml` (32768 tokens of context, eight sequences, MTP with
@@ -870,6 +878,96 @@ its 8 steps.
---
# `krea2`: Krea 2 Raw and Turbo, an image generator
`arch/krea2` declares a generator in the core's JOINT_STEP layout: the conditioning pass leaves
each lane's text rows (after the text fusion and `txt_in`) in its store, and every denoising step
runs them with the image, since every row is modulated by the step's timestep and nothing can be
cached as keys. Served on `/v1/images/generations` ([GUIDE §5.6](GUIDE.md)); it takes no reference
pictures, so `/v1/images/edits` answers 501.
```
text Qwen3-VL-4B's language model over the prompt in Qwen-Image's template, the template's
system turn dropped; TWELVE taps, hidden_states[2, 5, .., 35] (the outputs of layers 1,
4, .., 34) before any final norm; the layers past the last tap are not converted
fusion two blocks attending across a token's twelve taps (twelve consecutive rows), a learned
Linear(12, 1) over them (mix_rows), two blocks attending across the tokens, txt_in
DiT 28 single-stream blocks over [text | image]; gqa 48 query heads to 12, a sigmoid output
gate, q and k RMS-normed, three-axis rotary (text at the origin, an image token at
(0, row, column)); six modulation rows a block = ONE timestep projection shared by all
blocks + each block's learned table (table_add), gates without tanh
norms every RMS norm zero-centred: the gain is 1 + w, in f32
VAE Qwen-Image's (Wan 2.1's causal 3-D convolutions on one frame), 16 channels at 8x; a token
is 2 x 2 latents (64 values), 16 pixels a side
schedule Raw: 28 steps, the resolution-shifted schedule of its scheduler config, guidance 4.5 in
the card's terms against an empty negative prompt; Turbo: 8 steps at a fixed shift
(mu 1.15), no guidance. Raw or Turbo is read from the pipeline and scheduler config
```
Traps:
- **Guidance is in the card's terms**: `cond + s (cond - uncond)`, which the core runs as
`uncond + (s + 1)(cond - uncond)` (RadGenDecl::cfg_original). Read as diffusers' usual
`uncond + s (...)` the picture is under-guided by one.
- **The taps are layer outputs, not inputs.** `hidden_states[i]` is the output of layer i - 1;
an off-by-one shifts all twelve and gives a plausible, wrong picture.
- **The text rows are a token's twelve taps, then the tokens.** The first two fusion blocks attend
within a token (twelve rows), the last two across tokens; swapping the order of the rows swaps
which attention sees what.
Against diffusers' pipeline in bf16 on a tiny random-weight pipeline of the same layout (256x256,
from the same latents, mean absolute difference in 8-bit levels): Turbo 0.6, Raw guided 2.2 in an
all-bf16 container. Block fp8 moves the random model's Raw picture by 8.5 levels, which is the
quantisation's: the container's codes decoded to bf16 on the host give the same picture.
---
# `flux3`: FLUX.3 [klein] and its base, an image generator and editor
`arch/flux3` declares a JOINT_STEP generator over three modes: the text, the reference pictures'
latents and the image. The conditioning pass leaves each lane's text rows (after
`context_embedder`) and reference rows (VAE-encoded by the generator's own encoder and embedded) in
its store; every step runs the three modes' early blocks and then the joint blocks. Served on
`/v1/images/generations` and `/v1/images/edits` with up to ten reference pictures.
```
text Qwen3-VL-4B-Instruct's language model over the prompt in its chat template, right-padded
to a multiple of 80 tokens; the padding takes part (each padding token at position 1,
attending to the prompt alone: attn_cross with valid_cu); EIGHT taps hidden_states[4, 8,
.., 32] side by side, 20480 values a token, through context_embedder
DiT parallel blocks, h += gate (attn(n) + mlp(n)), n a LayerNorm without affine times
(1 + scale) plus shift; 5 early blocks a mode, each mode on its own, then 28 joint blocks
over [text | pictures | image] an entry; each mode its own modulation (text and pictures
at t = 0, the image at the step's), separately for the early and the joint blocks
rotary four axes (t, h, w, l): text along l, the image at (0, h/2, w/2, 0), reference k at
l = -(1 + k)
flow map the step-distilled release adds the embedding of the time the step goes TO to every
mode's timestep embedding (transformer config flow_map)
VAE FLUX.2's: 32 channels at 8x, GroupNorm(32) and a single-head mid-block attention; a token
is 2 x 2 latents (128 values), normalised by the VAE's BatchNorm running statistics
(chan_stats with var 1: sqrt(running_var + eps))
schedule [klein]: 16 steps, no guidance; base: 50 steps, guidance 3.5 against an empty negative
prompt; both a constant shift of 6.93
refs at most ten, each shrunk (never enlarged) to 1024 x 1024 pixels of area
```
Traps:
- **The padding is part of the prompt.** The pipeline pads to a multiple of 80 and the padding
tokens' states reach the DiT; dropping them, or letting them attend to each other, changes every
text row the image attends to.
- **GroupNorm over 128 channels in 32 groups** is four channels a group, which group_norm runs at
4-channel chunks; a kernel that needs 8 refuses the VAE.
- **The prompt upsampler is not run.** diffusers' modular pipeline can rewrite the prompt with a
separate LLM first; radiance reads the prompt as given, as the pipeline does with that block
removed.
Against diffusers' modular pipeline in bf16 on a tiny random-weight pipeline of the same layout
(256x256, from the same latents, mean absolute difference in 8-bit levels, GPU): [klein] 1.17, the
base guided 2.30, an edit with one reference picture 1.16.
---
# `qwen3asr`: speech to text
`model_type: qwen3_asr` (`Qwen3ASRForConditionalGeneration`), served from the checkpoint as it
@@ -1207,3 +1305,97 @@ output denormalised, folded back into patch rows (patch_fold), then the video
The node runs the network on whole clips here (its temporal chunking is off in the example
workflows); every rank runs it whole, its weights in VRAM on each.
---
# `ltx2`: LTX-2.5, video with sound
`arch/ltx2` declares a video generator (`rad_declare_video_generator`, schedule form 1) on the
passes of `core/gen/video_driver.h`: VCOND once per request (the text encoder over the prompt and
the negative prompt, the connectors into the lane's text rows, the first frame encoded for image to
video), VSTEP once per evaluation, VDECODE and ADECODE once per video, VUPSCALE between the two
stages of the distilled recipe. Served on `/v1/videos` ([GUIDE §5.16](GUIDE.md)), one card, bf16 or
block fp8. The checkpoint is the diffusers `LTX2Pipeline` directory, with `latent_upsampler/`,
`duration_head/` and `diffusion_decoder/` read when they are there.
```
text Gemma 4's language model over "<bos>{prompt}<eos>" (no template), LEFT-padded to 1024
rows; every layer's output is kept (the embeddings, each layer's but the last, the final
norm of the last), each RMS-normed per layer and flattened channel-major per token.
Gemma 4 scores q.k at scale 1: the q and k norms' gains carry the 1/sqrt(head_dim)
connector per modality a projection of that stack to its width (video 4096, audio 2048), the
1024 rows past the prompt's tokens filled from 128 learnable registers, eight
bidirectional blocks with a split rotary over the row index
DiT 48 dual-stream blocks: video 4096 (32 x 128) over 1 x 1 patches of 128 channels (32
pixels a latent, 8 frames a latent frame + the first), audio 2048 (32 x 64) over 25
latents a second (8 channels x 16 mel bins); a block's video stream runs self-attention,
cross-attention to its text, attention to the soundtrack and a feed-forward, the
soundtrack's the same against the video; every attention gated per head
(2 sigmoid(logit)), q and k RMS-normed across all heads; per-block tables + the step's
timestep projection (table_add), the cross-modal ones shift-first
rotary split over (t, y, x) at the patches' MIDPOINTS for the video, the time midpoint for the
audio (rope_split, max 20 2048 2048 and 20)
guidance up to four evaluations a step -- the prompt, the negative prompt, the prompt with block
28's self-attentions bypassed (STG), the prompt without the cross-modal attentions --
combined on the clean estimates with a rescale (ltx_guide); base defaults video
(cfg 3, stg 1, modality 3, rescale 0.7), audio (7, 1, 3, 0.7); distilled: one, unguided
VAE causal 3-D decoder, four up blocks of residual blocks with depth-to-space and
PerChannelRMSNorm (pixel_norm div), 4 x 4 pixel patches out; a frame larger than
960 x 544 in diffusers' tiles (16 latents every 14: tile_grid, tile_crop, a tile store,
tile_stitch's blends to bytes), a smaller one whole; its encoder takes the first frame
for image to video
ddec the diffusion decoder, a request's `decoder` "diffusion": the latent with its last frame
twice more (NATTEN's border needs them), stages of 4 6 4 2 neighbourhood-attention blocks
(2048 1024 512 512 wide, windows 3x7x7 3x7x7 3x5x5 3x5x5, pre-norm, a 3-D gptj rotary
over the voxel coordinates in 8 12 12 pairs, SwiGLU 4x) with pixel-shuffle upsamples
(1x2x2, 2x1x1, 2x2x2, 2x2x2); the first three over the whole video, then per tile of the
feature grid (_tile_intervals: 96 cells every 88, 40 every 28) the fourth and one x0 step
at timestep 1 from the seed's noise (stream 2 + the tile) over 4 x 4 pixel patches: 8
diffusion blocks of 256 (11x11x11 windows) conditioned on the fourth stage's output, the
norms modulated by the timestep's shared table plus each block's own, each attending a
head at a time (one head's q|k|v is a quarter of all four's); tile_stitch blends the
tiles' overlaps into the frames
audio a causal 2-D decoder to a stereo log-mel spectrogram at 16 kHz, a BigVGAN vocoder to 16
kHz, a bandwidth extender (its own vocoder over the waveform's log-mel spectrogram plus a
sinc-resampled skip, bwe_up) to 48 kHz; the vocoders in f32
length the duration head (VCOND, when the container has it): each connector's prompt rows
projected to 256 with a modality embedding, one learned query over all 2048 (four heads
of 64, no mask), a tanh-GELU MLP to ln(seconds) -- read back by the core, which shapes a
request that named no length from it (RadVideoGenDecl::duration_out)
schedule base: 30 steps of FlowMatchEuler, exponential dynamic shift 0.95..2.05 over 1024..4096
tokens, shift_terminal 0.1; distilled: its 8 trained sigmas (1.0 .. 0.421875), and with
the upsampler the two-stage recipe -- the 8 at half size, the latent upsampler, both
latents re-noised to 0.909375 with stream 1 of their seeds (flow_renoise), the stage-2
sigmas 0.909375, 0.725, 0.421875 at the full size
```
Traps:
- **The noise is radiance's.** The video's latent is stream 0 of the seed in packed (f, y, x)
order; the soundtrack's the seed with its top bit flipped; the second stage's re-noise is stream
1 of each. Parity against diffusers means handing it the same tensors: the latents, and for the
first-frame pipeline and the re-noise its `randn_tensor` patched to return them.
- **A distilled schedule is read as given.** diffusers stretches explicit sigmas to a scheduler
config's `shift_terminal`; a distilled pipeline whose scheduler config kept the base model's 0.1
would run different sigmas there, and the plugin runs the trained ones.
- **The vocoder's dilations are nested lists** (`[[1, 3, 5], ...]`); the metadata reader flattens
them row-major. Dropped, every resnet runs at dilation 1 and the soundtrack is noise.
- **The first frame goes through H.264 at CRF 18 before the encoder**, as the pipeline does for
LTX-2.5 (33 for the Gemma 3 generations). In the two-stage recipe the first frame of the
UPSCALED latent is the one kept clean, as diffusers' image pipeline keeps it, not a re-encode
at the full size.
- **A tile's crop reads the latent after earlier tiles have decoded.** The buffer planner orders
liveness by declaration, which has one crop before the decoder; the latent is a persistent buffer
so the decoder's scratch cannot take its memory between tiles. Before that, every tile but the
first decoded garbage and the first one partly.
- **The MP4 is not a parity instrument.** H.264 at CRF 18 in yuv420p moves a random-weight
model's frames by about 40 levels on its own; compare the frames before encoding (the op
oracle's patch_pix8 output).
Against diffusers' pipelines in bf16 on a tiny random-weight pipeline of the same layout (256x256,
17 frames, from the same latents), the first frame's row sums agree to within 0.2% at 2 unguided
and 4 guided steps, for image to video, single-stage distilled and the distilled two-stage recipe
with and without a first frame; diffusers on CUDA and on the CPU differ from each other by up to 0.1%.
On an R9700 (libr4d) the same five renders land within 0.15% of diffusers' CUDA rows, every op
agreeing with its host reference under the op oracle. Block fp8 moves the random model's rows by
0.2 to 0.4% (the card's fp8a8 GEMMs, the CPU's fp8 codes widened to bf16).
+9 -2
View File
@@ -130,19 +130,26 @@ the cards the engine runs on.
| `flashnext-tp1.yaml` | `qwen3.8-next-flash-fp8-iq4r-moe.rad` | The same on one card: a 42 GiB pinned host pool for the experts that do not fit, 4096-token prefill steps, 4 sequences |
| `flashnext-bf16.yaml` | `qwen3.8-flash-next-bf16.rad` | Qwen3.8-Flash-Next in bf16, streamed from the disk tier. A reference, not a production server |
| `qwen3.6-35b-a3b.yaml` | `qwen3.6-35b-a3b-fp8.rad` | Qwen3.6-35B-A3B, FP8 |
| `ornith-1.5-35b-a3b.yaml` | `ornith-1.5-35b-a3b-fp8.rad` | Ornith-1.5-35B-A3B, FP8, MTP, vision |
| `qwen3.8-27b-fp8.yaml` | `qwen3.8-27b-fp8.rad` | Qwen3.8-27B FP8 with its DFlash2 drafter and vision tower |
| `qwen3.8-27b-mxfp4.yaml` | `qwen3.8-27b-mxfp4.rad` | Qwen3.8-27B with AMD's Quark AWQ-MXFP4 trunk, its DFlash2 drafter and vision tower |
| `qwen3.8-27b-paro.yaml` | `qwen3.8-27b-paro-int4.rad` | Qwen3.8-27B ParoQuant int4 (learned rotations) with its DFlash2 drafter and vision tower, on one card; the int5 and MXFP4 containers serve from it too |
| `qwen3.8-27b-bf16.yaml` | `qwen3.8-27b-bf16.rad` | Qwen3.8-27B in bf16 |
| `gemma4-31b-w4a8.yaml` | `gemma4-31b-w4a8.rad` | Gemma 4 31B, int4 trunk with int8 activations, its assistant head as the MTP drafter, vision tower |
| `gemma4-31b-heretic-ara-w4a8.yaml` | `gemma4-31b-heretic-ara-w4a8.rad` | The same for Gemma 4 31B heretic-ara (refusals removed) |
| `translategemma-27b.yaml` | `translategemma-27b-mxfp4-gptq.rad` | TranslateGemma 27B MXFP4 with its chat template (`gemma3.jinja`) |
| `glm53-flash.yaml` | `glm53-flash-mxfp4.rad` | GLM-5.3-Flash, MXFP4 experts and block-FP8 attention, on eight cards |
| `minicpm5-2b.yaml` | `minicpm5-2b-fp8.rad` | MiniCPM5-2B FP8 with its DSpark drafter |
| `minicpm5-2b-bf16.yaml` | `minicpm5-2b-bf16.rad` | MiniCPM5-2B in bf16 with its DSpark drafter |
| `embeddinggemma2.yaml` | `embeddinggemma2-bf16.rad` | EmbeddingGemma 2 in bf16: text, image, video and audio embeddings on one card (`RADIANCE_GPU`) |
| `qwen-image-2.1.yaml` | `qwen-image-2.1-fp8.rad` | Qwen-Image 2.1 as block fp8 on two cards: OpenAI's images API, generation and edits |
| `qwen-image-2.1-turbo.yaml` | `qwen-image-2.1-turbo-fp8.rad` | Qwen-Image 2.1 Turbo, the same in 8 steps |
| `krea-2-turbo.yaml`, `krea-2-raw.yaml` | `krea-2-turbo-fp8.rad`, `krea-2-raw-fp8.rad` | Krea 2 Turbo and Raw as block fp8: text to image on one card (`RADIANCE_GPU`) |
| `flux-3-klein.yaml` | `flux-3-klein-fp8.rad` | FLUX.3 [klein] as block fp8: generation and edits on one card (`RADIANCE_GPU`); the base container serves the same way |
| `qwen3-asr-1.7b.yaml` | `Qwen3-ASR-1.7B-hf/` (the checkpoint) | Qwen3-ASR 1.7B: `/v1/audio/transcriptions` and live `/v1/realtime`, on one card (`RADIANCE_GPU`) |
| `minimax-h3.yaml` | `minimax-h3-fp8.rad` | MiniMax-H3 as block fp8: video with its stereo soundtrack on `/v1/videos`, two cards and about 39 GiB of pinned host memory |
| `fasth3.yaml` | `fasth3-8-step-v2-fp8.rad` | FastVideo's FastH3 8-Step V2, the same in eight steps |
| `ltx-2.5.yaml` | `ltx-2.5-distilled-fp8.rad` | LTX-2.5 distilled as block fp8: video with its stereo soundtrack on `/v1/videos`, one card (`RADIANCE_GPU`), the text encoder in pinned host memory; the base container serves the same way |
| `minimax-music3.yaml` | `minimax-music3-bf16.rad` | MiniMax-Music3 in bf16: songs from lyrics and a description on `/v1/audio/speech` |
| `breeze-tts2.yaml` | `breeze-tts2-bf16.rad` | Breeze-TTS-2 in bf16: speech on `/v1/audio/speech` and live over `/v1/audio/speech/stream`, on one card (`RADIANCE_GPU`) |
@@ -163,7 +170,7 @@ docker compose -f flashnext.yaml down # stop
```
Every model listens on the same port and most take both cards (`flashnext-tp1.yaml`,
`qwen3.8-27b-paro.yaml` and `embeddinggemma2.yaml` take one), so run one at a time: `down` one
before `up` on another. The server runs as the host user given in `.env`. `/health`, `/ping` and
`qwen3.8-27b-paro.yaml` and the files that read `RADIANCE_GPU` take one, `glm53-flash.yaml`
eight), so run one at a time: `down` one before `up` on another. The server runs as the host user given in `.env`. `/health`, `/ping` and
the dashboard page answer without the API key, and the health check fetches `/health` with
busybox's `wget`.
+114 -25
View File
@@ -276,9 +276,13 @@ and runs.
| `lfm2_bf16` | LiquidAI LFM2 and LFM2-VL in bf16, including d1 (§5.13) |
| `embgemma2` | EmbeddingGemma 2, an embedding model (§5.6) |
| `qwenimage21` | Qwen-Image 2.1 and 2.1-Turbo, an image model (§5.6) |
| `krea2` | Krea 2 Raw and Turbo, an image model from text (§5.6) |
| `flux3`, `flux3distilled` | FLUX.3 [klein] and its base, an image model that also edits (§5.6); one plugin under the two names the releases give themselves |
| `qwen3asr_bf16` | Qwen3-ASR, speech to text from the checkpoint as it ships (§5.14) |
| `minimaxmusic3` | MiniMax-Music3, songs from a description and lyrics (§5.15) |
| `breeze` | Breeze-TTS-2, speech from text and an optional description of the voice (§5.15) |
| `minimaxh3` | MiniMax-H3 and FastH3, video with its stereo soundtrack from text (§5.16) |
| `ltx2` | LTX-2.5, video with its stereo soundtrack from text or a first frame (§5.16) |
**4. Falling back to the reference library is fatal.** If any op resolves to `libref`, the engine
refuses to start and names the ops, because serving from it is orders of magnitude slower with nothing
@@ -393,6 +397,27 @@ rad-convert /srv/models/Qwen/Qwen-Image-2.1 -o qwen-image-2.1-fp8.rad \
rad-convert /srv/models/Qwen/Qwen-Image-2.1-Turbo -o qwen-image-2.1-turbo-fp8.rad \
--recipe data/recipes/qwen-image-2.1-fp8.recipe
# Krea 2 Raw or Turbo, and FLUX.3 [klein] or its base, image models (§5.6): the diffusers pipeline
# directory; fp8 blocks for the text encoder and the DiT. Krea 2 takes a recipe either way (or
# krea-2-bf16.recipe), since the release stores its embedders and modulations f32
rad-convert /srv/models/krea/Krea-2-Turbo -o krea-2-turbo-fp8.rad \
--recipe data/recipes/krea-2-fp8.recipe
rad-convert /srv/models/black-forest-labs/flux-3-image-klein -o flux-3-klein-fp8.rad \
--recipe data/recipes/flux-3-klein-fp8.recipe
# LTX-2.5, video with sound (§5.16): the diffusers pipeline directory, latent_upsampler/ included
# for the distilled release's two-stage recipe; fp8 blocks for the text encoder, the connectors and
# the DiT, or bf16 (both recipes keep the vocoders f32, which they run in)
rad-convert /srv/models/Lightricks/LTX-2.5-Diffusers -o ltx-2.5-fp8.rad \
--recipe data/recipes/ltx-2.5-fp8.recipe
# Its full (SFT) DiT, transformer_full/, is guided and takes the base schedule back: a folder whose
# transformer/ links to it, and the scheduler's shifting turned on as the release's README does
mkdir ltx-2.5-full && ln -s /srv/models/Lightricks/LTX-2.5-Diffusers/* ltx-2.5-full/
rm ltx-2.5-full/transformer ltx-2.5-full/transformer_full
ln -s /srv/models/Lightricks/LTX-2.5-Diffusers/transformer_full ltx-2.5-full/transformer
rad-convert ltx-2.5-full -o ltx-2.5-full-fp8.rad --recipe data/recipes/ltx-2.5-fp8.recipe \
--set scheduler.use_dynamic_shifting=1 --set scheduler.shift_terminal=0.1
# MiniMax-Music3, songs (§5.15): the diffusers pipeline directory is the checkpoint (language model,
# depth decoder, condition encoder, DiT, vocoder, tokenizer); bf16 throughout (21 GB, one card or two)
rad-convert /srv/models/MiniMaxAI/MiniMax-Music3 -o minimax-music3-bf16.rad \
@@ -729,9 +754,10 @@ are first-seen, so steps wait on the drive. `ram` copies the table into host mem
so a step has no host work. `vram` puts all of it on every card. `ram` needs the table's size free
after the pinned host pools and the prefix cache's host tier, with `--host-headroom-mib` to spare
(default 4 GiB), under every memory cgroup the process sits in, and refuses the start otherwise.
`auto` takes the first of `vram`, `ram` and `disk` that holds the table. Without a device kernel for the gather (no libr4d) the table is
read on the host: `vram` is refused, and `ram` is a copy in locked huge pages, which also needs a
memlock limit that large (`--ulimit memlock=-1` in Docker, `LimitMEMLOCK=infinity` under systemd).
`auto` takes the first of `vram`, `ram` and `disk` that holds the table. Without a device kernel
for the gather (no libr4d) the table is read on the host: `vram` is refused, and `ram` is a copy in
locked huge pages, which also needs a memlock limit that large (`--ulimit memlock=-1` in Docker,
`LimitMEMLOCK=infinity` under systemd).
**`--weights-disk-tier`** serves a model larger than the card and the host pool together, with every
step paced by the drive. A routed expert that fits neither lives only in the container. Before each
@@ -792,8 +818,10 @@ widths.
`fp8_v4` and `k6_v4` narrow the trunk's attention cache further, in groups of 32 dimensions with an
f16 scale each: `fp8_v4` keeps K in E4M3 and stores V as int4, `k6_v4` stores K as int6 too. A token
then costs 25/32 or 22/32 of what fp8 costs, and a drafter's cache stays fp8. libr4d has their
kernels for Qwen3.8-27B's attention (head_dim 256, gqa 6), so the plugin offers them there and the
server refuses them, naming the plugin, anywhere else. On two R9700s at the serve flags of
kernels for Qwen3.8-27B's attention (head_dim 256, gqa 6) and Qwen3.8-Flash-Next's (head_dim 256,
gqa 12 over 4-token pages, gqa 6 a rank at four ranks), so `qwen35_fp8` and `qwen4exp_fp8` offer
them there and the server refuses them, naming the plugin, anywhere else. Flash-Next's QSA indexer
keeps its own key cache, so its share of a token does not shrink. On two R9700s at the serve flags of
`qwen3.8-27b-mxfp4.yaml` with `--max-num-batched-tokens 2048` and 12 GiB a card left to another
engine, against the bf16 model on 17 long log-analysis documents (60 368 scored positions):
@@ -1229,6 +1257,13 @@ radiance --model m.rad --chat-template-kwargs @template-vars.json
startup with the template's message.
- `/tokenize` renders `messages` with the same variables.
**System messages.** Many templates raise unless a conversation has one system message, first; the
Chat Completions API allows any number anywhere. A conversation the template refuses that has a
system message after the first message, or more than one, is rendered again with its system
messages merged, in order and separated by a blank line, into one at the head; the first such
request logs a warning. Anything else a template refuses is a 400 on `messages` in the template's
own words.
**`--reasoning-effort`** is the default for chat requests that set none, passed to the chat template
verbatim, so the legal set is the template's. Qwen3.8 takes `xhigh|medium|low` and defaults to
`xhigh`, which on a short task can spend the whole token budget inside `<think>` and return empty
@@ -1345,7 +1380,7 @@ still verified by the adapter, so output is exact and only the acceptance rate c
| flag | default | |
|---|---|---|
| `--gpu-headroom-mib N` | 96 | VRAM left unclaimed on every card |
| `--kv-cache-dtype T` | bf16 | `bf16`, `fp8`, or on Qwen3.8-27B `fp8_v4` or `k6_v4` (§4.4) |
| `--kv-cache-dtype T` | bf16 | `bf16`, `fp8`, or on Qwen3.8-27B and Qwen3.8-Flash-Next `fp8_v4` or `k6_v4` (§4.4) |
| `--host-pool-mib N` | 0 | pinned host tier (weights) |
| `--host-headroom-mib N` | 4096 | host RAM left free for the system when startup pins host memory — kept for the unpooled allocations, staging and page cache (§4.3) |
| `--embedding-placement WHERE` | ram | `ram` or `vram`: the token embedding pinned in host memory beside `--host-pool-mib` and read in place, or on the card (§4.3) |
@@ -1721,7 +1756,7 @@ becomes up to 280 tokens by default (`--image-tokens`, or a request's `image_tok
`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.
**An image model** (Qwen-Image 2.1 or 2.1-Turbo) serves OpenAI's images API only; completions, chat
**An image model** (Qwen-Image 2.1 or 2.1-Turbo, Krea 2, FLUX.3 [klein]) serves OpenAI's images API only; completions, chat
and embeddings answer 501. OpenAI images clients (Open WebUI, the OpenAI SDKs) work unchanged; the
picture always comes back in the response. The engine sizes the step, batch and context for an image
model itself (`--max-num-batched-tokens` and `--max-model-len` from the model's largest pass,
@@ -1785,6 +1820,15 @@ area (its latent rows replace its vision tokens). One card holds the fp8 contain
container. A request the cache can never hold is a 400 naming the rows it needed. The models are
under Qwen's research license, non-commercial.
**Krea 2 and FLUX.3 [klein]** take the same fields with their own defaults. Both make RGB pictures
(`background: transparent` is a 400), 1024x1024 by default, sides rounded down to multiples of 16,
up to 2048x2048 (16384 latent tokens). Krea 2 Raw runs 28 steps at guidance 4.5 against an empty
negative prompt and Turbo 8 steps unguided; Krea 2 reads only text, so `/v1/images/edits` answers
501. FLUX.3 [klein] runs 16 steps unguided and its base 50 at guidance 3.5; both edit from up to ten
pictures, each shrunk to 1024x1024 of area when larger. The guidance scale is `guidance_scale` or
`true_cfg_scale` (one of them), in the model card's terms. FLUX.3's pipeline can rewrite a prompt
with a separate language model first; radiance reads the prompt as given.
### 5.7 Request fields
| field | notes |
@@ -1912,8 +1956,12 @@ llama-server (`chat_template_kwargs`, `top_k`, ...). The answer is a response ob
stream with every event's `output_index`, `content_index` and `sequence_number`, opening with
`response.created` and `response.in_progress` at once, as OpenAI's and vLLM's do: they report the
response object, not output. A reply cut at
`max_output_tokens` is `incomplete`. Function tools are offered to the model; built-in tools (web
search, file search, computer use) and freeform custom tools are left out, as in llama-server.
`max_output_tokens` is `incomplete`. Function tools are offered to the model, and so are the
function tools a `namespace` groups (Codex sends every MCP server's tools that way), named
`<namespace>__<name>`: the reply's `function_call` item carries `namespace` and `name` apart, and a
`function_call` input item or a `tool_choice` naming a namespace is joined back the same way. Two
tools that would share a name are refused. Built-in tools (web search, file search, computer use)
and freeform custom tools are left out, as in llama-server.
Responses are not stored, so `previous_response_id` is refused: send the conversation as `input`.
What a response object cannot carry is refused: `n` other than 1, and logprobs (`include` naming
`message.output_text.logprobs`, `top_logprobs`, `logprobs`, `n_probs`), which
@@ -2362,7 +2410,7 @@ and the session goes on.
### 5.16 Video: `/v1/videos`
A video generation model (MiniMax-H3) answers OpenAI's video jobs: `POST /v1/videos` queues a video
A video generation model (MiniMax-H3, LTX-2.5) answers OpenAI's video jobs: `POST /v1/videos` queues a video
with its stereo soundtrack and answers at once with the video object; `GET /v1/videos/{id}` reports
its `status` (`queued`, `in_progress`, `completed`, `failed`) and `progress` (0 to 100);
`GET /v1/videos/{id}/content` downloads the MP4 once it is completed (`?variant=thumbnail` gives the
@@ -2427,6 +2475,54 @@ The MP4 holds H.264 video (yuv420p, BT.709) and AAC audio at 32 kHz stereo. A fi
for an hour (`expires_at`), at most 32 of them. MiniMax-H3's license excludes use in the EU, the UK,
the Republic of Korea and the USA without a separate license from MiniMax.
**LTX-2.5** takes the same jobs with its own limits, and starts from a picture as well as from text:
```sh
radiance --model ltx-2.5-fp8.rad --vision-tower-placement ram
# image to video: the picture is the first frame (a file in the form, or a data: URL in JSON)
curl -s http://localhost:8000/v1/videos -F 'prompt=the fox turns and runs into the trees' \
-F 'size=768x512' -F 'seconds=5' -F 'input_reference=@fox.png'
```
- **`prompt`** is read as written (no template), at most 1024 tokens; **`negative_prompt`** is
what guidance steers away from, empty by default.
- **`seconds`** is rounded up to steps of 8 frames at 24 a second, from 17 frames (0.71 s) to 161
(6.7 s). Left out (or `"auto"`), the release's duration head chooses the length the prompt
implies, as diffusers does when `num_frames` is omitted: its prediction held to 1 to 20 seconds,
rounded to frames and down to the 8-frame steps, then to the 161 frames this server makes. The
video object says `"seconds": "auto"` until the prompt is read, then the length chosen. A
container without the head makes 121 frames (5.04 s). **`size`**: both sides multiples of 32 from 256, at most
1920 x 1088 pixels of area, at most 3:1; 960x544 by default, the release's own. A step carries at
most 121 frames at 1920x1088 (a longer video at that size is refused). Up to 960 x 544 of area
the VAE decodes each frame whole, as the pipeline does by default; a larger frame is decoded in
diffusers' tiles (`vae.enable_tiling()`: 512 pixels every 448) and blended where they overlap,
as the release's two-stage README does at 1920x1088.
- **`input_reference`** is the first frame, resized and cropped to `size` and put through H.264
at CRF 18 first, as the model was trained.
- **`decoder`** picks how the latents become frames: `vae` (the default, the convolutional VAE that
diffusers' LTX2Pipeline decodes with) or `diffusion`, the release's diffusion decoder (the
README's "Decode with the diffusion decoder"): four stages of neighborhood-attention blocks, then
one denoising step from noise over 4 x 4 pixel patches, run in its own tiles (768 pixels every
704, 80 frames every 56) as diffusers' `enable_tiling()` runs it. It draws its noise from the
request's seed, so a seed repeats its video. Frames of at most 960 x 544 of area.
- The base model runs 30 steps (`num_inference_steps`, at most 64), each up to four evaluations:
**`guidance_scale`** against the negative prompt, **`stg_scale`** against the model with block
28's self-attentions bypassed, **`modality_scale`** against the model without its cross-modal
attentions, and **`guidance_rescale`**, by default 3, 1, 3 and 0.7 for the video. The
soundtrack's own four are the same fields prefixed `audio_` (7, 1, 3, 0.7). A scale of 1 (0 for
`stg_scale`) drops its evaluation, so `{"guidance_scale": 1, "stg_scale": 0, "modality_scale":
1, ...}` runs one evaluation a step.
- The distilled release runs its 8 trained steps unguided, and only those; with its latent
upsampler in the container, **`latent_upscale`** 2 (sides multiples of 64) runs them at half the
size, enlarges the clean latent, re-noises it and refines at the full size in 3 more. `size` is
the output's: the release's README recipe is `"size": "1920x1088", "latent_upscale": 2` (its first
stage at 960x544).
The MP4's soundtrack is 48 kHz stereo. LTX-2.5 runs on one card; `--tp` above 1 is refused. Its
Gemma 4 text encoder (13 GiB in fp8) does not fit a 32 GB card beside the DiT: serve it with
`--vision-tower-placement ram`, which keeps it in pinned host memory and reads it once a prompt.
## 6. Operation
### 6.1 The dashboard
@@ -2464,18 +2560,13 @@ take twice as long as its neighbour — so nothing is compared until 32 have bee
averaged. A single slow step moves neither figure.
The percentage, `now X% of best`, is the page's own live window read against the
floor. `now` is the mean of the steps that completed in the last poll (~500 ms);
the figure is that mean as a fraction of `best`, so ~99% is the fastest the lane
has done and anything slower reads a percentage of it (a step at 80% of the
floor's speed reads "80% of best"). It is capped at ~99, shown with a tilde: `now` is a ~500 ms mean
while `best` is a 32-step window mean, so a fast stretch shorter than a window can
read faster than the recorded floor. That is "at your best", not a new record —
the engine only lowers `best` on a completed 32-step window, and a sub-window blip
is not one. The cap is 99 rather than 100 because a 500 ms window that briefly beats the floor is
not a sustained record; 100% would claim a floor the window cannot confirm and would read as a
bug, while ~99% says "at your best" without overclaiming. At higher concurrency the figure is keyed to that concurrency (`@c8`)
and read against the fastest step seen at that concurrency, because a batched step
is a different measurement and would report a batch arriving as a slowdown.
floor: the mean of the steps that completed in the last poll (~500 ms) as a
fraction of `best`, so a step at 80% of the floor's speed reads "80% of best". A
fast stretch shorter than a window can beat the 32-step floor without being a new
record, so the figure is capped and the fastest reads `~99%`. At higher
concurrency it is keyed to that concurrency (`@c8`) and read against the fastest
step seen there, because a batched step is a different measurement and would
report a batch arriving as a slowdown.
The gap between them is normal, and it is not degradation. `best` is the most
favorable moment the lane has hit; `recent` is what it is doing now. On a healthy
@@ -2657,7 +2748,7 @@ is the part of a log to paste into an issue. Its sections:
warning is also printed as a `W` line of its own.
```
I STARTUP REPORT -- radiance 1.8.1
I STARTUP REPORT -- radiance 1.9.0
I CONFIGURATION -- every option, the value in force, and where it came from
I --model /models/flashnext.rad [command line]
I --tp 2 [command line]
@@ -2754,8 +2845,6 @@ reductions running on fewer blocks: Qwen3.8-27B's 41k-token prefill 9.5 s uncapp
| `RADIANCE_CALIB_DIR` | where an engine run writes calibration data for a recipe's `gptq calib=DIR` |
| `RADIANCE_CALIB_TOKENS` | with `RADIANCE_CALIB_DIR`, the tokens the calibration tap accumulates before it writes and switches itself off (default 65536) |
| `RADIANCE_G3_CALIB_LAYERS` | `lo:hi`: `arch/gemma3`'s calibration tap over layers lo to hi - 1 only, to take a large model's Grams in passes (docs/ARCHITECTURES.md) |
| `RADIANCE_GLM_TP_SPLIT_ROWS` | `arch/glm5next` under tensor parallelism: the pass height from which the router, the index head gates and the mHC projection split their f32 work over the ranks and gather it, bit-identical to the replicated form (default 256; `0` or a value that does not parse never splits) |
| `RADIANCE_GLM_ROUTER_FUSE`, `RADIANCE_GLM_SWIGLU_QUANT`, `RADIANCE_GLM_GATHER_INVERSE` | `arch/glm5next`'s MoE decode fusions, each byte-identical to the launches it replaces: unset, empty or `1` on, `0` off, any other value refuses the start. For comparing, not for deployment (docs/ARCHITECTURES.md) |
| `RADIANCE_PROFILE_EVERY` | with `--profile-ops`, dump the per-op table every N steps (default 32) |
| `RADIANCE_LOG_STEPS` | log one line per step: its phase, sequences, and each one's token count and context (§4.5) |
| `RADIANCE_AR8_SHARD_WEIGHTS`, `RADIANCE_AR8_PIECES` | the eight-rank two-shot's shard weights (`auto`, the default, reads the PCIe links; `off`; or eight integers) and piece count, with `RADIANCE_AR8_SHARD_WEIGHTS_MIN_ELEMS` and `RADIANCE_AR8_PIECES_MIN_ELEMS` for the message size each starts at (§4.7) |
+212 -30
View File
@@ -373,7 +373,7 @@ kernels with its chunk-sum order, so the pair is byte-identical to `mhc_pre` (`r
and two from 32, where the weight rows are 16-byte and the residual rows 8-byte aligned; the
finish forms the 4x4 mixing on one wave and collapses the row over the workgroup; `mhc_post` at
`hc` 4 writes eight columns of every stream a thread on 16-byte rows. Every form gives the bytes
of the scalar kernels it replaces.
of the scalar kernels that serve the rows it cannot read.
### Gemma 4's audio tower
@@ -518,7 +518,7 @@ form by `M`, `N` and `K`; on rows that are not 16-byte aligned it takes the 16x6
are byte-identical (`tests/r4d_emu/test_fp8f32.cpp`). The grouped row takes equal-width parity
tables (`N_odd = N`, `K_odd = K`), token or sorted activations, and stacked planes or pointer
tables, and runs expert-major: a block per (column span, expert) takes every row of its expert,
each element keeping the row-tile form's sequence.
each element keeping the 16x64 tile's sequence.
**`group` has different meanings in this table.** A kernel that reads it the other way is wrong,
not slow. `libref/ref_quant.cpp` is the definition.
@@ -772,6 +772,8 @@ bytes).
|---|---|---|
| `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 `window`/opt `cu_div`/opt `block`/opt `window_right`/opt | `q`, `k`, `v`, `cu_seqlens` → `out` |
| `attn_cross` | `M`(range) `head_dim` `gqa` `causal` `dtype` `scale`:f64/opt | `q`, `k`, `v`, `cu_seqlens`, `cu_k` → `out` |
| `attn_na3d` | `M`(range) `head_dim` `kt` `kh` `kw` `dtype` `scale`:f64/opt | `q`, `k`, `v`, `geom` → `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 `ladder`/opt `llama3_factor`:f64/opt `llama3_low`:f64/opt `llama3_high`:f64/opt `llama3_orig`:f64/opt | `qkv`:inout, `positions` |
@@ -801,6 +803,24 @@ with `window_right = r + 1` (non-causal only: key `j` visible when `i - j < wind
`[tokens, heads * head_dim]`, and the second form may be a column slice of a fused projection read
at its row pitch, so a tower's `[q|k|v]` row needs no copy.
**`attn_cross`** is `attn_dense` with each entry's keys a run of their own: entry `s`'s queries
are rows `[cu_seqlens[s], cu_seqlens[s+1])` of `q`, its keys and values rows `[cu_k[s], cu_k[s+1])`
of `k` and `v`, and with `causal` a query sees key `j` of its run when `j <= i`, both counted from
their run's start. A query that sees no key is zero. It is a video's rows reading their prompt
(cross attention), and a padded prompt whose padding rows see only the prompt (`cu_k` the
prompt's rows, `cu_seqlens` the prompt and its padding: every padding row sees every prompt row
and none of the padding, as a masked padding token does in the reference).
**`attn_na3d`** is 3-D neighborhood attention, NATTEN's `na3d` (LTX-2.5's diffusion decoder). The
rows of `q`, `k`, `v` and `out` are the voxels of the volume `geom` = `(T, H, W)` (i32 on the
device), `(t, i, j)` row-major, each `[rows, heads head_dim]` at its own row pitch (column slices of
a fused projection). A query sees the keys of a `kt x kh x kw` window, each extent at most its axis,
centred on it and shifted inward at the border: along an axis of `L` and window `n` it starts at
`clamp(c - n / 2, 0, L - n)`, so it always holds `n` keys. Per head, in f32: each score the dot over
`d` ascending times `scale` (default `1 / sqrt(head_dim)`), the window's keys in raster order, the
softmax as `attn_cross` takes it, the output rounded to its dtype. Rows past `T H W` are not
written. libr4d serves `head_dim` 64.
**`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 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)`
@@ -918,8 +938,11 @@ The group is declared at `RAD_F8E4M3` with head_dim the row's bytes / 2, so the
as it does for fp8, and the cache operand's last extent is the row. The ops take the model's
head_dim. libr4d's rows are `kv_store_fp8v4` / `kv_store_k6v4`,
`qk_norm_rope_gate_kv_store_fp8v4` / `_k6v4` (byte-identical to the prologue and the store, as at
the other widths), and `attn_prefill_h256_gqa6_{fp8v4,k6v4}` and `attn_decode_h256_gqa6_{fp8v4,k6v4}`,
which widen the codes to f16 in a tile's staging. `r4d_selftest` holds the stores to an exactly
the other widths), `attn_prefill_h256_gqa6_{fp8v4,k6v4}` and `attn_decode_h256_gqa6_{fp8v4,k6v4}`,
which widen the codes to f16 in a tile's staging, and the same kernels at Qwen3.8-Flash-Next's
ratios over 4-token pages: `attn_{prefill,decode,decode_gq}_h256_gqa12_{fp8v4,k6v4}` and
`attn_{prefill,decode,decode_gq}_h256_gqa6_bs4_{fp8v4,k6v4}`, the `decode_gq` rows with the output
gate and quantiser in the split-KV merge. `r4d_selftest` holds the stores to an exactly
representable set and the attention rows to its inline oracle.
### `qk_norm_rope_gate` (device-only)
@@ -976,6 +999,9 @@ says which (`libref/ref_gen.cpp`).
| `ln_mod_quant_fp8` | `M`(range) `n` `eps`:f64 `group` `gated` `dtype` | `y`?, `g`?, `s`, `cu_seqlens`, `x`:inout → `q`, `scale`, `z`? |
| `timestep_embed` | `M`(range) `n` `scale`:f64 `max_period`:f64 `round`/opt `dtype` | `t` → `y` |
| `gather_rows2` | `M`(range) `n` `dtype` | `a`, `b`, `idx` → `y` |
| `table_add` | `M`(range) `n` `L` `dtype` | `x`, `t`w → `y` |
| `mix_rows` | `M`(range) `n` `k` `dtype` | `x`, `w`w → `y` |
| `chan_stats` | `M`(range) `n` `mode` `var`/opt `eps`:f64/opt `dtype` | `x`, `mean`w, `s`w → `y` |
| `lane_gather` | `M`(range) `n` `stride` `dtype` | `src`, `lane`, `cu_seqlens` → `y` |
| `lane_store` | `M`(range) `n` `stride` `dtype` | `src`, `lane`, `dst`:inout |
| `randn_lanes` | `M`(range) `n` `stride` `dtype` | `flags`, `seed`, `lane`, `cu_seqlens`, `dst`:inout |
@@ -1007,8 +1033,20 @@ source into every listed lane (a repainted picture's latent into each of its ima
store would round it, so the bytes are the three ops'.
- `timestep_embed`: `[cos | sin]` of `t' * f_i`, `f_i = exp(-ln(max_period) * i / (n/2))` in f32,
`t' = scale * t`; with `round` 1, `t' = scale * bf16(bf16(t * scale) / scale)`, the value
diffusers' pipeline hands its transformer. `t` is f32 `[M]`.
diffusers' pipeline hands its transformer; with `round` 2, `t' = scale * bf16(t)` (a pipeline
that hands the transformer `t` in bf16 and scales it inside, Krea 2's); with `round` 3,
`t' = bf16(scale * bf16(t))` (the scaling also in bf16, FLUX's). `t` is f32 `[M]`.
- `gather_rows2`: `y[i] = idx[i] >= 0 ? a[idx[i]] : b[-1 - idx[i]]`, zeros past either source.
- `table_add`: `y[r, l n + c] = x[r, c] + t[l, c]` for each of `L` rows of the weight `t` `[L, n]`,
the sum f32 and rounded once: a modulation shared by every block plus each block's own learned
table (Krea 2, LTX-2), every block's rows in one launch, read at `l n` of each `y` row.
- `chan_stats`: a latent through per-channel statistics a VAE keeps as weights, `mean` and `s`
`[n]`: `std` is `s`, or with `var` 1 `sqrt(s + eps)` (a BatchNorm's running variance, FLUX's VAE),
each statistic rounded to `y`'s dtype as the reference casts it; `mode` `denorm` is
`y = rd(rd(x std) + mean)` and `norm` is `y = rd(rd(x - mean) / std)`.
- `mix_rows`: `y[r, c] = sum_i w[i] x[r k + i, c]` over `i < k`, f32 in ascending `i` and rounded
once: a `Linear(k, 1)` across `k` consecutive rows (Krea 2's text fusion folds a token's twelve
tapped encoder layers, laid out as consecutive rows, into one).
- `randn_lanes`: for entries whose `flags` carry 1, the lane's rows become the entry's seed's
standard-normal stream (`abi/rad_philox.h`), element `(k, c)` the stream's `k * n + c`. `seed` is
`[n_seq, 2]` u32, low word first.
@@ -1025,7 +1063,8 @@ shapes: an image's size belongs to a request, and a parameter is fixed at declar
- `conv2d_nhwc`: `w` is PyTorch's `[cout, cin, k, k]` (a kernel may store it permuted through its
layout hook), `b` `[cout]`; `up` 2 reads the input upsampled 2x nearest-neighbour; `pad` `same`
is `k/2` zeros a side, `down` is none above and left and one below and right
(`ZeroPad2d((0,1,0,1))` before a stride-2 conv). f32 accumulation, the bias added, one rounding.
(`ZeroPad2d((0,1,0,1))` before a stride-2 conv), `causal` is `k - 1` rows above, none below and
`k/2` columns a side (causal along the rows: LTX-2's audio VAE). f32 accumulation, the bias added, one rounding.
- `l2norm_chan`: each pixel's channels to unit L2 (eps 1e-12), times `sqrt(n)`, times `gamma`
(three roundings), then `act` `none` or `silu`.
- `chan_affine`: `mul` and `add` are space-separated lists of `n` values, each rounded to bf16;
@@ -1090,6 +1129,7 @@ libref function says which (`libref/ref_audio.cpp`).
| `interleave2` | `M`(range) `dtype` | `a`, `b` → `y` |
| `iota` | `M`(range) `start` `step` `period`/opt | → `y` |
| `cu_repeat` | `M`(range) `mult` | `len` → `y` |
| `int_affine` | `M`(range) `src` `mul` `add` | `x` → `y` |
**Frames.** A lane is one piece; a frame is one step of its language model, whose branches (the
conditional first, then the unconditional) are consecutive rows, `rep` of them a lane.
@@ -1120,7 +1160,10 @@ conditional first, then the unconditional) are consecutive rows, `rep` of them a
`status[lane] >= 0` (frame 0 only moves past the prompt; a negative status ended the piece).
- `iota`: `y[i] = start + i * step`, or `start + (i % period) * step` with `period` (the
positions of equal sequences laid end to end). `cu_repeat`: `y[j] = j * len[0] * mult`, the bounds of equal
sequences whose length lives on the device.
sequences whose length lives on the device. `int_affine`:
`y[j] = (src[j] < 0 ? 0 : x[src[j]]) mul[j] + add[j]` over three lists of integers of one length
(`src` -1 a constant): the shapes and bounds a model derives from a pass's device geometry, such
as a decoder's volume at each of its scales.
**Windows.** The denoiser runs over windows of frames, each entry of a window step a lane's latent
in a state buffer `stride` rows a lane (`lat_cu` bounds each entry's rows, `win_lane` names its
@@ -1194,8 +1237,8 @@ bf16 tensor and keeps f32 where it computes in f32; the libref function says whi
| op | params | operands |
|---|---|---|
| `rms_mod` | `M`(range) `n` `eps`:f64 `gated`/opt `dtype` | `y`?, `g`?, `s`, `w`w, `cu_seqlens`, `x`:inout → `z` |
| `rms_mod_quant_fp8` | `M`(range) `n` `eps`:f64 `group` `gated` `dtype` | `y`?, `g`?, `s`, `w`w, `cu_seqlens`, `x`:inout → `q`, `scale`, `z`? |
| `rms_mod` | `M`(range) `n` `eps`:f64 `gated`/opt `dtype` `wadd`:f64/opt `norm_once`/opt `norm`/opt | `y`?, `g`?, `s`, `w`w?, `cu_seqlens`, `x`:inout → `z` |
| `rms_mod_quant_fp8` | `M`(range) `n` `eps`:f64 `group` `gated` `dtype` `wadd`:f64/opt `norm_once`/opt `norm`/opt | `y`?, `g`?, `s`, `w`w?, `cu_seqlens`, `x`:inout → `q`, `scale`, `z`? |
| `flow_x0_step` | `M`(range) `n` `dtype` | `v`, `t`, `sigma`, `sigma_next`, `x`:inout |
| `patch_unfold` | `M`(range) `C` `pt` `ph` `pw` `mul` `add` `dtype` | `x`, `geom` → `y` |
| `vtile_gather` | `M`(range) `n` `tile` `overlap` `frames` `period` `n_reg` `dtype` | `x`, `reg`w, `geom` → `y` |
@@ -1211,7 +1254,14 @@ reads its entry's rows of `s` and `g`.
stored `x`), `n2 = bf16(n1 w)`, `m = bf16(n2 bf16(1 + scale[e]))`, `z = bf16(m + shift[e])`.
`s` is `[n_seq, >= 2n]` at its own row pitch, `shift = s[e, 0:n]` and `scale = s[e, n:2n]` (a
column slice of the modulation table); `g` is `[n_seq, >= n]` at its own pitch; `w` is `[n]`.
The residual rounds to `x`'s dtype and the norm chain to `z`'s.
The residual rounds to `x`'s dtype and the norm chain to `z`'s. `wadd` is added to the gain in
f32 (a zero-centred norm's `1 + w`), and with `norm_once` 1 the norm and its gain round together,
`n2 = bf16(x rsqrt(mean(x^2) + eps) (w + wadd))`, as an f32 RMS norm with a gain stores its
output (Krea 2's). `norm` `layer` (default `rms`) is a LayerNorm instead: `x` centred by its
mean (an f32 sum in ascending order) and `rsqrt` of the centred values' biased variance plus
`eps`. Without `w` the norm has no gain and rounds once, `n2 = bf16((x - mean) rsqrt(var +
eps))` (FLUX.3's LayerNorm without an affine). `norm` `none` takes no norm and no gain,
`n2 = x`, and refuses `w` (LTX-2's text keys and values, modulated as they are).
- `rms_mod_quant_fp8` is `rms_mod` with the norm chain in bf16, then `quant_act_fp8` of that bf16
row per `group` as `ln_mod_quant_fp8` takes it; `z` written when bound.
- `flow_x0_step` is MiniMax-H3's sampler step over a lane's rows, all f32, each product and sum
@@ -1376,7 +1426,7 @@ pass starts from. Each op rounds once into its output (`libref/ref_video.cpp`).
| op | params | operands |
|---|---|---|
| `conv3d_ndhwc` | `M`(range) `cin` `cout` `k` `kt` `dtype` | `x`, `w`w, `b`w, `geom`, `res`? → `y` |
| `conv3d_ndhwc` | `M`(range) `cin` `cout` `k` `kt` `dtype` `tpad`/opt `tpre`/opt | `x`, `w`w, `b`w, `geom`, `res`? → `y` |
| `group_norm` | `M`(range) `n` `groups` `eps`:f64 `act` `dtype` | `x`, `w`w, `b`w, `mod`?, `stats`:inout → `y` |
| `tconv_dw` | `M`(range) `n` `k` `dtype` | `x`, `w`w, `b`w, `geom` → `y` |
| `resize_bilinear` | `M`(range) `n` `dtype` | `x`, `geom` → `y` |
@@ -1395,7 +1445,10 @@ Every op honours its activation operands' row pitches. `rd` is a rounding into t
`y[(t,i,j), o] = rd(f32(sum over (dt, kh, kw, ci) of w[o, ci, dt, kh, kw]
x[(t+dt-kt/2, i+kh-k/2, j+kw-k/2), ci]) + b[o])`, terms outside the volume zero, f32 accumulation
in an order of the implementation's (libref: the taps in `(dt, kh, kw)` order, each tap's
channels ascending). With `res`, `y = rd(rd(acc + b) + res)`: the convolution's output rounded,
channels ascending). `tpad` (optional) pads the frames instead with `replicate` (the edge frame
repeated, `kt/2` a side) or `causal` (the first frame repeated `kt - 1` times in front, nothing
after; with `tpre` that many more copies in front, and y then has `T + tpre` frames): LTX-2's
decoder and encoder. With `res`, `y = rd(rd(acc + b) + res)`: the convolution's output rounded,
then the residual added and rounded, as a block's `skip(x) + h` in bf16. `res` may be the same
memory as `y` (the residual added in place); `x` never aliases `y`. x, y, res and w bf16 (also
f32), b bf16 or f32. MiniMax-H3: `k` = `kt` = 3, `(cin, cout)` `(24, 512)`, `(512, 512)`,
@@ -1437,6 +1490,134 @@ Every op honours its activation operands' row pitches. `rd` is a rounding into t
first, `stream` the parameter. `x` f32 `[M, n]` at its row pitch. MiniMax-H3: `n` 96 (the video's
patch rows) and 32 (the soundtrack's), `stream` 1.
## LTX-2
The ops LTX-2's audio-video transformer adds (`libref/ref_ltx.cpp`): its rotary over fractional
coordinates, the per-head gate on every attention's output, and the sampler step that combines a
step's guidance passes in the clean-estimate space. Each rounds where the reference rounds
(diffusers' `transformer_ltx2.py` and `pipeline_ltx2.py`): the transformer in bf16, the rotary,
guidance and sampler in f32.
| op | params | operands |
|---|---|---|
| `rope_split` | `M`(range) `n_head` `head_dim` `dim` `n_dims` `theta`:f64 `max` `head0`/opt `dtype` | `x`:inout, `positions` |
| `head_gate` | `M`(range) `n_head` `head_dim` `dtype` | `g`, `x`:inout |
| `ltx_guide` | `M`(range) `n` `dtype` | `vc`, `vu`?, `vs`?, `vm`?, `scales`, `sched`, `stats`:inout, `x`:inout |
| `pixel_norm` | `M`(range) `n` `eps`:f64 `form` `act`/opt `ileave`/opt `dtype` `mult`:f64/opt | `x` → `y` |
| `d2s3d` | `M`(range) `C` `st` `sh` `sw` `drop`/opt `dtype` | `x`, `geom` → `y` |
| `s2d3d` | `M`(range) `C` `st` `sh` `sw` `tpre`/opt `group`/opt `mode` `add`/opt `dtype` | `x`, `geom`, `y`:inout |
| `pix_patch` | `M`(range) `p` `C` `order`/opt `dtype` | `x` → `y` |
| `patch_pix8` | `M`(range) `p` `C` `order`/opt `dtype` | `x` → `y` |
| `stft_logmel` | `M`(range) `hop` `nfft` `n_mel` `ch` `dtype` | `x`, `basis`w, `mel`w → `y` |
| `bwe_up` | `M`(range) `ratio` `ch` `dtype` | `x`, `res` → `y` |
| `vol_index` | `M`(range) | `geom` → `y` |
| `tile_grid` | `M`(range) `tile` `stride` `rule`/opt `min`/opt `tile_t`/opt `stride_t`/opt `min_t`/opt `tail`/opt | `geom` → `y` |
| `tile_crop` | `M`(range) `C` `dtype` | `x`, `geom`, `box` → `y` |
| `tile_stitch` | `M`(range) `tile` `stride` `rule`/opt `min`/opt `tile_t`/opt `stride_t`/opt `min_t`/opt `scale` `scale_t`/opt `p` `C` `order`/opt `dtype` | `x`, `geom`, `first` → `y` |
- `rope_split` is LTX2AudioVideoRotaryPosEmbed's "split" rotary. Over the full width `dim` of all
heads there are `P = dim / 2` pairs: the first `pad = P - steps n_dims` are not rotated, and the
rest are a frequency ladder `freq[k] = f32(theta^linspace(0, 1, steps)[k] pi / 2)` (f64 before
the cast, torch's linspace), `steps = P / n_dims`, its pairs interleaving the coordinates: pair
`pad + k n_dims + d` turns by coordinate `d` at `freq[k]`. A coordinate `c` gives the angle
`a = f32(f32(2 f32(c / max[d])) - 1) freq[k]`, `max` a list of `n_dims` values. Head `h` owns
pairs `[h hd/2, (h+1) hd/2)` and turns its halves against each other,
`o1 = f32(f32(x1 cos a) - f32(x2 sin a))`, `o2 = f32(f32(x2 cos a) + f32(x1 sin a))`, rounded to
`x`'s dtype. `head0` is the first head the operand holds (a rank's share). `positions` is
`[n_dims, M]`, f32 or integer, at its own strides. LTX-2.5: the video's self-attention `dim`
4096, `n_dims` 3, `max` `20 2048 2048` (two padded pairs); the soundtrack's and both cross
attentions' `dim` 2048, `n_dims` 1, `max` `20`; the text connectors' `max` 4096 over the row
index.
- `head_gate`: `x = rd(x rd(2 rd(sigmoid(g))))` for each head's `head_dim` values, `g`
`[M, >= n_head]` the head's logit (the gated attention's `to_gate_logits`), each operand at its
own row pitch.
- `ltx_guide` is one sampler step over a modality's latent `x` (f32 `[M, n]`, all of it: the
rescale's deviations are over every value) from its guidance passes' velocities (`[M, n]`, read
as f32), all in f32:
x0_p = f32(x - f32(v_p sigma)) each pass p
g = x0_c [+ f32(f32(gs - 1) f32(x0_c - x0_u))] [+ f32(stg f32(x0_c - x0_s))]
[+ f32(f32(ms - 1) f32(x0_c - x0_m))] left to right
r > 0: g = f32(f32(r f32(g f32(std(x0_c) / std(g)))) + f32(f32(1 - r) g))
v = f32(f32(x - g) / sigma), x = f32(x + f32(f32(sigma_next - sigma) v))
A bracketed term is taken when its pass is bound and its coefficient is not zero. `std` is the
unbiased deviation over all `M n` values, accumulated in f64. `scales` is f32 `[4]`
`(gs, stg, ms, r)` and `sched` f32 `[2]` `(sigma, sigma_next)`, both read on the device; `stats`
is f32 of at least 8200 values, the implementation's scratch.
Its VAE, audio VAE and vocoder run in bf16 tensors, and these ops round where those tensors are
stored (`rd`, the output's dtype unless said).
- `pixel_norm` is an RMS norm over each row's `n` values: `m = rd(sum rd(x^2) / n)` (f32 sum in
ascending order), then `form` `rsqrt` `z = rd(x rd(1 / sqrt(rd(m + eps))))` or `div`
`z = rd(x / rd(sqrt(rd(m + eps))))`, with `act` silu `z = rd(z / (1 + exp(-z)))`, and with
`mult` `z = rd(z mult)` (the connectors' scale to the DiT's width). The VAE's
PerChannelRMSNorm and the audio VAE's PixelNorm are the div form (with the SiLU after them
fused); the text connectors' per-layer norm is the rsqrt form, whose output `ileave` L
interleaves: x's row `t L + l` goes to columns `c L + l` of y's row `t`, as the reference
flattens `[C, layers]`.
- `d2s3d` and `s2d3d` resample voxel rows (`geom` = x's `(T, H, W)`, i32 on the device), the
packed channel of `(c, a, b, d)` being `((c st + a) sh + b) sw + d` (a the frame offset, b the
row's, d the column's). `d2s3d` is the upsampler's depth to space,
`y[(t st + a - drop, i sh + b, j sw + d), c] = x[(t, i, j), packed]`, the first `drop` frames
dropped (by default `st - 1`, the causal mapping; 0 keeps them, as a decoder's tile that does not
start the video does). `s2d3d` is the downsampler's space to depth over the volume with `tpre` leading
frames prepended (frames `0 .. tpre - 1` again): `mode` copy writes the packed row, `mean`
averages each run of `group` packed channels (f32 sum, divided, one rounding); with `add` 1
`y = rd(y + v)`. `M` is x's rows.
- `pix_patch` and `patch_pix8` are the patchifier both ways over dense 2-D operands whose shapes
give the sizes: a `p x p` patch of `C` channels is one row of `C p p` values, channel `c`'s
`(ph, pw)` at `c p p + pw p + ph` (`order` wh, LTX-2's) or `c p p + ph p + pw` (hw).
`pix_patch` takes an image `[H, W C]` to `[H / p, (W / p) C p p]`; `patch_pix8` takes patch rows
`[R, w C p p]` to RGB bytes `[R p, w p C]` by `to_rgba8`'s rule,
`round(255 clamp(rd(rd(clamp(v, -1, 1) / 2) + 0.5), 0, 1))`, rd x's dtype.
- `vol_index` writes a volume's voxel coordinates, the rotary positions of attention over it:
`geom` = `(T, H, W)`, `y` i32 `[3, n]` component-major at its own row pitch, voxel
`m = (t H + i) W + j`'s `(t, i, j)` at column `m`, for `m < min(n, T H W)`.
- `tile_grid`, `tile_crop` and `tile_stitch` run a decoder in tiles as diffusers does: LTX-2's VAE
(`tiled_decode`, `rule` `stride`, the default) and LTX-2.5's diffusion decoder
(`_tile_intervals`, `rule` `intervals`). Along an axis of `L` cells a tile starts at every
multiple of `stride` below `L`; under `intervals` an axis of `tile` cells or fewer is one tile, and
while more than one start is left and the last leaves fewer than `min` cells (default 1) that
start is dropped. A tile but the last is `min(tile, L - start)` long, the last runs to `L`. The
same cut with `tile_t`, `stride_t` and `min_t` makes time bands (without `tile_t`, one band of
every frame); tiles are raster-ordered over (time band, row band, column band). `tile_grid`
writes the tiles of the grid `geom` = `(T, H, W)` to `y` i32 `[M, 8]`, row k
`(t, h, w, t0, y0, x0, k, count)`, the last time band `tail` cells longer than its cut (frames a
decoder carries past `T`); rows past the count are zero. A row's `(t, h, w)` is a decoder's volume
operand and its first six entries `tile_crop`'s `box`: `tile_crop` copies the box
`y[(a, i, j)] = x[(t0 + a, y0 + i, x0 + j)]` out of the volume `x` (`geom` its `(T, H, W)`).
`tile_stitch` takes every tile's decoder output back to back in tile order: a cell is `scale`
patches of `p x p` pixels a side and `scale_t` frames (default 1), the video's first cell one
frame, so tile `(kt, i, j)` with cells `[t0, t1)` in time holds `scale_t (t1 - t0)` frames (less
`scale_t - 1` when `t0` is 0) of `(h scale) x (w scale)` rows of patches (`pix_patch`'s columns).
`geom` is the grid the tiles cut, `first` the first frame `y` holds, and `y` RGB bytes
`[n (H scale p), (W scale p) C]`. A frame is the time band whose kept frames hold it (a band but
the last keeps `stride_t scale_t`, the first `scale_t - 1` fewer), a pixel `(Y, X)` the tile
`(Y / s, X / s)` of that band, `s = stride scale p`, the last band of an axis keeping the rest.
With every product and sum rounded to `x`'s dtype and
`mix(a, b, k, e) = rd(rd(a f32(1 - k / e)) + rd(b f32(k / e)))`, a band's picture is diffusers'
in-place `blend_v` with the tile above and then `blend_h` with the tile to the left over
`min(their extents, (tile - stride) scale p)` pixels, the neighbours read as their own blends
left them (libref/ref_ltx.cpp writes the four-tile corner out), and a frame of a band within
`min(their frames, (tile_t - stride_t) scale_t)` of its start is `blend_t` of the band before and
this one; the byte is `patch_pix8`'s.
- `stft_logmel` is each channel's causal log-mel spectrogram (the bandwidth extender's MelSTFT):
`x [S, ch]`, `basis [2F, 1, nfft]` (the windowed DFT, real then imaginary rows,
`F = nfft / 2 + 1`), `mel [n_mel, F]`; frame `t` reads samples `t hop + j - (nfft - hop)`, zero
before the start; `s_k = rd(sum_j basis[k, j] x)`,
`mag_k = rd(sqrt(rd(rd(re_k^2) + rd(im_k^2))))`,
`y[t, h n_mel + m] = rd(log(max(rd(sum_k mel[m, k] mag_k), rd(1e-5))))`; y is `[S / hop, ch n_mel]`.
- `bwe_up` is the extender's output: x `[S, ch]` raised `ratio` times by its Hann-windowed sinc
resampler (width `w = ceil(6 / 0.99)`, `2 w ratio + 1` taps
`rd(sinc(u) cos^2(clamp(u, -6, 6) pi / 12) 0.99 / ratio)` with `u = f32(n / ratio - w) 0.99`,
the input's edges replicated), `up = rd(ratio rd(sum taps x))`, then
`y = clamp(rd(res + up), -1, 1)`; rd is x's dtype, y f32 or x's dtype.
The VAEs' convolutions are `conv3d_ndhwc` with `tpad` and the audio VAE's `conv2d_nhwc` with
`pad` causal.
## Mixture of experts
| op | params | operands |
@@ -1582,9 +1763,9 @@ with `route_scale` 2.5.
libr4d's `router_sigmoid_topk_f32` takes up to 512 experts and `top_k` up to 32, f32 logits, bias
and weights, i32 ids, pitched rows, `M` up to 65535. It selects in one wave per row: each lane
holds its experts as order-preserving keys (`-0` as `+0`, ties to the lower expert), and round `j`
takes the largest key below round `j-1`'s winner. A row without NaN ranks gives the bytes of the
serial scan. A NaN rank is never selected, and a row with fewer than `top_k` other ranks names
expert 0 in its empty slots, weighted by expert 0's `p`.
takes the largest key below round `j-1`'s winner. A row without NaN ranks gives the bytes of a
serial scan with a strict `>`. A NaN rank is never selected, and a row with fewer than `top_k`
other ranks names expert 0 in its empty slots, weighted by expert 0's `p`.
**`router_sigmoid_topk_scatter`** (device-only) is `router_sigmoid_topk` and `moe_scatter` over its
`ids` in one launch, and with `gate` `[M, 1]` also the `fill` of an ungated shared arm's gate with
@@ -1621,8 +1802,10 @@ at this dtype. The form follows the routed rows. The expert-major form, a block
expert) that reads each expert slice once, takes up to 511 rows, and at GLM's TP8 slices (288
experts, top 8) gate_up up to 768 and down up to 6143. At those slices the wide prefill form (P64:
jobs of 32 or 64 rows of one expert) takes gate_up from 769 rows and down from 5760, ahead of the
expert-major band. Elsewhere the row-group forms serve. Every form gives the bytes of the
arithmetic-decode row-group form (`tests/r4d_emu/test_moemx.cpp`).
expert-major band. At GLM's TP4 slices the GLM prefill form (jobs of 32 rows of one expert, its
loads a stage ahead) takes from 512 rows; elsewhere the row groups (16 sorted rows a block) serve.
Every form gives the bytes of one per-element sequence, restated on the host by
`tests/r4d_emu/test_moemx.cpp`.
**`moe_gemm_q_mod4`** is the same GEMM over four classes by the expert's number mod 4. `w`/`w_scale`
hold class 0 at `[N, K]` and `w_q`/`w_q_scale` class `q` at `[N_q, K_q]` (defaulting to `N`, `K`);
@@ -1730,12 +1913,12 @@ at most 32 tokens. `mode=prefill` commits its final state and sets the count to
scratch slot replays nothing.
libr4d's `kda_update_k128_v128_bf16` takes `head_k = head_v = 128`, 1 to 65535 heads, bf16
activations, f32 `A_log`, `dt_bias` and state, both modes and both state forms. A wave holds one,
two or four value rows of a head (four by default, the next token's operands loaded while the
current one reduces) and runs the sequence's tokens in order; every form gives the bytes of the
one-row kernel (`tests/r4d_emu/test_kda.cpp`). Under `anchor`, `verify` replays the accepted prefix
in a separate dispatch before the window, so no value row overwrites factors another is still
reading. A sequence whose window or slots are out of bounds is skipped on the device, not refused.
activations, f32 `A_log`, `dt_bias` and state, both modes and both state forms. A wave holds four
value rows of a head, loads the next token's operands while the current one reduces and runs the
sequence's tokens in order (held to libref by `r4d_selftest` and `tests/r4d_emu/test_kda.cpp`).
Under `anchor`, `verify` replays the accepted prefix in a separate dispatch before the window, so
no value row overwrites factors another is still reading. A sequence whose window or slots are
out of bounds is skipped on the device, not refused.
**Speculative rollback is part of the schema** (`spec.md` §10). The recurrent state and the conv
window have already absorbed rejected tokens, so the state cache is a rolling window of
@@ -2495,11 +2678,10 @@ it as bf16 high and low parts with f32 accumulation. At a multiple of 16 a tile
one query; otherwise it pairs eight heads of two neighbouring queries, loading a key once where
both tables name the page, so GLM-5.3's 8 heads a rank fill the tile. The pairing walks the union
of the two tables, so each chunk runs once, for tables of up to 520 entries; past that it pairs
by table position, with a second pass where the two differ.
`RADIANCE_MLA_MATRIX_MAX_M` lowers the matrix row's `M` bound (65535 by default); past it the
wave row, `mla_attn_bf16`, serves: a wave per head with an online softmax. Both split a short
batch's history across workgroups and merge the f32 partials before narrowing, into the fixed
scratch their hooks reserve; without scratch they compute unsplit.
by table position, with a second pass where the two differ. Other head counts take the wave row,
`mla_attn_bf16`: a wave per head with an online softmax. Both split a short batch's history across
workgroups and merge the f32 partials before narrowing, into the fixed scratch their hooks
reserve; without scratch they compute unsplit.
`mla_project` moves a query into the latent and a latent result out of it, through the bf16
weight `b` `[heads*2*head_dim, latent_dim]` that stores each head's key rows, then its value rows.
@@ -2512,8 +2694,8 @@ per-head width. Its rows are head-major, so a tensor-parallel slice of whole hea
libr4d's `mla_project_bf16` serves `head_dim` 256 and `latent_dim` 512, up to 64 heads, pitched
tensors. It takes up to eight rows a thread (`absorb`) or a wave (`expand`), loading each weight
element once for them, with every row's sum in the one-row kernels' order, so all forms give the
same bytes.
element once for them, with every row's sum in the same order whatever the group, so a row's bytes
do not depend on the batch.
## Draft heads