docs: the pipelined prefill, the second lane's window and scratch region, the narrow all-reduce at three and eight ranks

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
mici81andClaude Opus 5.5 authored and StillDeadcode committed 2026-10-24 11:10:08 +02:00
1 parent 4ec175549c
commit acd06d2a48
8 files changed
+145 -1

No files matched your search

+7
View File
@@ -1094,6 +1094,13 @@ w4a8 / w8a8 trunk takes `gemma4_bf16`'s fused junctions; an i8a8 or asymmetric-i
chain. Where a row is missing the plugin declares the chain, and the startup notes say which form
each took. Under calibration no junction is fused (below).
**Pipelined prefill.** At two ranks an MXFP4 trunk with the fused fp8 junctions prefills a prompt
of 1024 tokens or more in two pieces, the junctions and all-reduces of one beside the other's
compute (GUIDE §4.5, `RADIANCE_PREFILL_PIPELINE`). The window KV group's `seqused` counts from its
rebased first block, so the first piece's bound is computed on the card (`sub_i32`: the group's
`seqused` less the second piece's rows), not taken from its position. The gain needs 1024-row
pieces: serve at `--max-num-batched-tokens 2048`.
**Calibration.** Serve a calibration container (int8, `translategemma-27b-i8a8.recipe`: KL 0.003
against bf16, and it fits two 32 GB cards) with `RADIANCE_CALIB_DIR` set, push a corpus of the
prompts you will serve through prefill, and each linear's input Gram is written once
+69
View File
@@ -1049,6 +1049,62 @@ avoids the extra copies, at the cost of full re-prefill if an edit precedes the
Recurrent-state models still checkpoint at intervals under `tip-only`; their
existing scheduling is unchanged.
**One prefill sequence in two pieces** (`RADIANCE_PREFILL_PIPELINE`). On `qwen35_fp8` (and
`qwen35_w8a8`, built from it, where its norms do not write rotated int8 codes) and on `gemma3`'s MXFP4 trunk, a step of at least 1024 tokens that
carries one prefill sequence and nothing else runs in two pieces of about half, the first rounded up
to 64 rows so both sit in the whole step's kernel band. Every block runs a piece at a time; the work
between two blocks (the block's all-reduce, the next norm, and after a feed-forward the add) runs a
piece at a time on the second lane, beside the other piece's compute. The all-reduce there is the
narrow `overlap` launch ([OPS.md](OPS.md#collectives)): the fused all-reduce and norm holds its
blocks while it waits on the link and slowed the GEMM beside it by a third, and a wide launch slows
it 1.45-2.1x; either ate the whole gain at two ranks. A piece computes what a narrower chunk
computes, so a pipelined step is the serial step bit for bit: Qwen3.8-27B's KL recordings (`k6_v4`,
`--tp-wire wht6`) and TranslateGemma's compare equal with it on and off. One setting makes a piece
differ from the whole step: a lossy `--tp-wire` whose `--tp-wire-min-kb` a piece's message falls
under while the whole step's does not (that piece goes out exact).
| `RADIANCE_PREFILL_PIPELINE` | |
|---|---|
| `auto`, or unset | pipelined at two ranks |
| `on` (`1`, `true`) | also at three, four and eight ranks; startup notes that it is not measured there |
| `off` (`0`, `false`) | never |
Another value is noted at startup and taken as `auto`. On two R9700s (PCIe Gen5 x8, 265 W):
| model, chunk | prompt | serial | pipelined |
|---|---|---|---|
| Qwen3.8-27B MXFP4, 2048 | 41k tokens | 9.00 s | 8.41 s |
| TranslateGemma 27B MXFP4, 2048 | 6k | 1.27 s | 1.21 s |
| | 12k | 2.48 s | 2.42 s |
The Qwen figure includes the tiled GEMM's TN=4 crossover at 1024 rows, which the 1024-row pieces
need. At a 1024-token chunk TranslateGemma's pieces are 512 rows and gain nothing, so serve it at
2048 (against 1024: -9% at 6k, -7% at 12k). Decode steps are unchanged.
- **Above two ranks it is not measured.** `on` lets it run at three, four and eight ranks. At four
libr4d's `overlap` all-reduce rows take a narrow launch that leaves the CUs to compute
([TP4.md](TP4.md)); at three and eight they launch wide unless `R4D_AR_LANE_3_8=1` (§4.7), and a
wide all-reduce beside the other piece's GEMM is what ate the whole gain at two ranks, so try the
pipeline there with the variable set too. Compare a long prompt's prefill with `on` and `off` at
the chunk you serve before keeping it. On the exact wire only the two-shot band above 524288
elements has a lane row: a smaller piece (512 rows of a model 1024 wide) keeps the wide launch,
the one-shot at three and four ranks, the one-shot or the wide two-shot at eight. The
tiered-int8 lane rows at three and four ranks have no such floor. Eight ranks have no
lossy wire, so `on` there pipelines on the exact wire only. Qwen3.8-27B (4 KV heads) and
TranslateGemma (16) do not serve at three ranks.
- **Measured on MXFP4 containers.** `qwen35_w8a8` prefills serially where libr4d serves its
rotated int8 norms (the boundary norms would need the int8 codes on the second lane; startup says
so). Without them it builds the same code, not checked bit for bit on its int8 trunk.
- **Which steps.** A prefill step with more than one sequence, decode rows beside it, or media rows
(an image's tokens) runs serially; the first wide step that does says why, once, on rank 0
(`radiance: qwen35: a 2048-row prefill step runs serially: more than one sequence`). `gemma3`
needs the fused fp8 junctions, a library that serves `sub_i32`, and no calibration tap
(`RADIANCE_CALIB_DIR`); without them a startup note says the pipeline is off.
- **Memory.** The buffers the second lane touches leave the arena's sharing pool across the
architecture's second-lane window ([PLUGIN.md](PLUGIN.md) §11). On Qwen3.8-27B with its DFlash2
drafter at 64 sequences and speculation 7 the activation arena is 526.32 MiB a card, as without
a second lane; the second lane's third hardware queue (33 MiB, §4.3) remains.
**Sharing a step** (`--busy-prefill-chunk`, default `auto`). When other work is pending, a prefill
chunk leaves room for one row plus the draft window per decode row behind it, and a share of the
budget (an eighth, at least one quantum) for each prefill behind it and for the next request waiting
@@ -1239,6 +1295,17 @@ engine does not use it: on this board those weights lost their lead within a tim
served no faster. `r4d_selftest --perfar8 --ar8-weights W0,..,W7` times other weights on another
board (`off` for even shards).
**An all-reduce beside compute at three and eight ranks** (`R4D_AR_LANE_3_8`). An all-reduce a
plugin issues on its second lane (`overlap` 1: a pipelined prefill, §4.5; qwen4exp's
`--prefill-span`; gemma4's prefill trunk overlap; the image and video plugins' second-lane
collectives) takes a narrow launch at two and four ranks, measured there: a wide all-reduce's
blocks spin on peer flags on the CUs the GEMM beside it needs, and at two ranks slowed it
1.45-2.1x. At three and eight ranks `ar_twoshot_3rank_exact_lane`, `ar_twoshot_3rank_ti8_lane` and
`ar_twoshot_8rank_exact_lane` take those collectives, but by default they launch exactly as the
wide rows do, so nothing changes against a build without them. With `R4D_AR_LANE_3_8=1` they take
the four-rank launch, 4 blocks of 1024 threads. The bits are the same either way; only the time
moves:
### 4.8 Host tier for finished conversations
By default a finished conversation's KV blocks stay in VRAM, held by the prefix cache, until evicted
@@ -3288,6 +3355,8 @@ reductions running on fewer blocks: Qwen3.8-27B's 41k-token prefill 9.5 s uncapp
| `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_PROFILE_EVERY` | with `--profile-ops`, dump the per-op table every N steps (default 32) |
| `R4D_AR_LANE_3_8` | `1`: at three and eight ranks an all-reduce beside compute (`overlap` 1) takes the narrow four-rank launch instead of the wide one. Same bits; faster where the all-reduce is the shorter of the two, slower where it is the longer; not measured on such machines. Unset or `0`: the wide launch, as without the lane rows (§4.7) |
| `RADIANCE_PREFILL_PIPELINE` | a prefill step of one sequence and 1024 tokens or more in two pieces, the work between blocks of one piece on the second lane beside the other's compute (§4.5): unset or `auto` at two ranks, `on` also at three, four and eight ranks (not measured there), `off` never. The bits are the serial step's |
| `RADIANCE_LOG_STEPS` | log one line per step: its phase, sequences, and each one's token count and context (§4.5) |
Engine development has its own instruments: `RADIANCE_DEBUG_*` (residual probes, routing and issue
+14
View File
@@ -88,6 +88,20 @@ to bisect it (`spec.md` §17).
**No allocation and no synchronisation on the step path.** The arena is sized at declare. A
`malloc` needed inside `rad_arch_step` or the scheduler's per-step work is a declare-phase bug.
**Kernel scratch is per lane, each region sized by what its lane may issue.** In-order launch lets
every op on one stream share one scratch region; a second lane is a second stream and gets a second
region once the architecture names any buffer to `rad_buf_concurrent` (`Program::scratch_regions`).
Region 0 holds the program's largest device scratch (`Program::scratch_bytes`). Region 1 holds the
largest device scratch of an op the second lane may issue (`Program::scratch_bytes_lane1`, computed
in `Builder::finish_buffer_liveness`): by `Ctx::lane1_`'s rule 3 such an op touches only
concurrent buffers, so an op with any other transient buffer never runs there, and one with no
transient buffer counts. `Arena::init` takes both sizes, `arena_plan_bytes` charges both to the VRAM
budget, and startup prints them (`arena: ... device + ... scratch + ... for the second lane = ...`).
A lane-1 request larger than region 1 comes from an op that breaks rule 3 in its buffers too, so
`Ctx::issue` fails the step naming the kernel (`RAD_E_SCRATCH`) rather than let it overrun the
region. On Qwen3.8-27B with its DFlash2 drafter region 1 is 0 B, where it used to be a copy of region
0: 50 MiB a card at speculation 7, 17 MiB without speculation.
**`rad_memset_async` refuses `RAD_MEM_HOST` on a card; the host backend cannot reproduce that.**
`RAD_MEM_HOST` is pageable memory the GPU has never been shown, so the device backend returns
`RAD_E_UNSUPPORTED` naming the rule (`core/device/aql.cpp`). On the host backend all memory kinds
+5 -1
View File
@@ -2160,7 +2160,11 @@ start above 524288 elements (8192 at eight ranks), a band edge of the ranged `nu
all-reduce kernel serves `y` absent, in place. `overlap` 1 says the caller issues the collective on
its second lane, beside compute; libr4d then picks rows with a narrow launch (8 blocks of 256
threads at two ranks, 4 of 1024 for the four-rank two-shots, exact and tiered-int8) that compute the
same bits and leave the CUs to the kernels running beside them. libref ignores it.
same bits and leave the CUs to the kernels running beside them. At three and eight ranks the lane
rows (exact at both, tiered-int8 at three) launch as the wide rows unless `R4D_AR_LANE_3_8=1` gives
them the four-rank launch, unmeasured there (GUIDE §4.7); the eight-rank one starts above 524288
elements, so an `overlap` 1 message of 8193..524288 elements keeps the wide two-shot there. libref
ignores it.
libr4d serves these at 2, 3, 4 and 8 ranks:
+25
View File
@@ -361,6 +361,31 @@ says so with `RAD_ARCH_SERVES_IMPORTS(0)` (`qwen35_w8a8` does), and imports keep
(`rad_op_resolved`) and is an error only if issued. The in-tree blocks do this for
`qk_norm_rope_gate`.
- **Read §8** if the model has a linear or recurrent block.
- **Declare the second lane's window.** Work issued on the second lane (`rad_lane`,
`abi/rad_runtime.h`) runs beside lane 0 in time, so every buffer it touches is named to
`rad_buf_concurrent`, which keeps it live for the whole program: the planner cannot tell when
lane 1 runs. An architecture whose lane-1 work lies in one stretch of its declared ops says so,
calling `rad_lane1_window_begin(b)` before the first op of the stretch and
`rad_lane1_window_end(b)` after the last, once each and in that order, at declare. A concurrent
buffer is then live across the window and over its own declared uses only, so buffers used only
outside the window (a drafter's, the heads') share its bytes again. What the plugin promises:
it issues nothing on lane 1 outside the window. What the runtime does (`Ctx::issue`): an op
issued on lane 1 outside the window fails the step, naming the window's op range and the op's
position; the first op issued on lane 0 past the window joins lane 1 first when lane 1 has work
pending, so the plugin need not join before the window ends; an op the core appends behind a
declared one (runtime LoRA) counts at that op's position. The builder refuses a second `begin`,
an `end` without a `begin`, twice or around no op, a `begin` never closed, and either call after
declare. `qwen35_fp8` (with the plugins built from it) and `gemma3` declare one from the
embedding's all-reduce to the final norm. On Qwen3.8-27B with its DFlash2 drafter at 64 sequences
and speculation 7, on two R9700s, the activation arena went from 633.99 to 526.32 MiB a card, as
without a second lane, and with the second lane's own scratch region
([IMPLEMENTATION.md](IMPLEMENTATION.md)) the KV pool from 86 208 to 93 856 tokens.
`tests/arch_test.cpp`'s builder applies the window to liveness as the core does, so the pinned
graphs and steps are the ones the core plans; the runtime (`Ctx::issue`) is what refuses a lane-1
op outside the window. The join is at the window's end only: an op declared before the window must
not be issued again while lane 1 has work pending. Both calls are additive exports:
`RAD_ABI_VERSION` (26) does not move, and a plugin that does not call them is unaffected. A plugin that calls them needs an engine that exports them; an older engine fails
to load it (`dlopen` with `RTLD_NOW`: an undefined symbol).
- **Media preprocessing is the core's** (`core/mm`): resizing, patching, placeholder-token
expansion and positions, in five processor families (Qwen-VL, Gemma 4, LFM2-VL, Unlimited-OCR,
GLM-5.3) chosen by the container's `vision_config.model_type` (Unlimited-OCR's by its
+15
View File
@@ -137,6 +137,21 @@ fold in fp32 in ascending rank order, so the switch between them changes no bits
at three ranks is the tiered-int8 wire over the same uneven two-shot for messages from
`--tp-wire-min-kb` up, and the exact one-shot below.
An all-reduce a plugin issues on its second lane beside compute (`overlap` 1, [OPS.md](OPS.md)
Collectives) takes `ar_twoshot_3rank_exact_lane` or `ar_twoshot_3rank_ti8_lane`, the exact and
tiered-int8 two-shots' entry points one priority above the wide rows: qwen4exp's pipelined prefill
under `--prefill-span` ([GUIDE.md](GUIDE.md) §4.5), gemma4's prefill trunk overlap and the image and
video plugins' second-lane collectives among them. By default they launch exactly as the wide rows
(`tArTs38Lane` holds `tAr`'s defaults), so a three-rank deployment runs as it did before them.
`R4D_AR_LANE_3_8=1` gives them the four-rank lane rows' launch, 4 blocks of 1024 threads; the
arithmetic is the wide rows' either way, bit for bit. At two ranks a wide all-reduce beside a GEMM
slowed it 1.45-2.1x on R9700s, which the narrow launch avoids; at three it may pay the same way,
or cost where the all-reduce outlasts the compute beside it. Not measured: no three-card machine
was available, and the launch is untuned there. GUIDE §4.7 has how to compare the two.
`RADIANCE_PREFILL_PIPELINE=on` also allows `qwen35_fp8`'s and `gemma3`'s pipelined prefill at three
ranks, but neither model this tree serves with them splits its KV heads three ways (Qwen3.8-27B has
4, TranslateGemma 16), so it has nothing to run there yet.
Startup logs the geometry:
```
+9
View File
@@ -73,6 +73,15 @@ promotion truth; quick concurrency ladders within windows.
4. ti8 **one-shot band** for 128 KiB–512 KiB lossy messages (currently every
such message pays two-shot 1.5N + 2 syncs) — flagged upstream on #78.
5. Draft-pass graph capture — only if low-concurrency latency ever matters.
6. **The dense pipelined prefill at TP4** (`qwen35_fp8`, `qwen35_w8a8`, `gemma3`; GUIDE §4.5): a
prefill step of one sequence in two pieces, every block boundary's all-reduce on the second lane
at `overlap` 1, so on this table's `*_4rank_*_lane` rows (row 1). Off by default above two
ranks; `RADIANCE_PREFILL_PIPELINE=on` allows it and startup notes that it is unmeasured. Measured
only at TP2 (2×R9700, PCIe Gen5 x8, 265 W): Qwen3.8-27B MXFP4 41k prefill 9.00 → 8.41 s,
TranslateGemma 27B 6k 1.27 → 1.21 s at a 2048 chunk; bit for bit the serial step by construction,
checked by KL recordings at TP2 (arch_test checks the pieces and lanes a four- and an eight-rank
step declares, not their output). One boot-flag arm, `on` against `off`, at 18K-64K
prompts and the chunk served, settles whether it ships on by default here.
## Interaction diagram
+1
View File
@@ -71,6 +71,7 @@ The table lists a selection; `r4d_rows.cpp` and `r4d.h` hold the full set.
| `gdn_gated_norm_had_quant_i8` | the GDN gated norm with the rotation and quantiser fused onto it |
| `qk_norm_rope_gate` | q/k RMS norm, rope and the attention gate in one kernel |
| `ar_oneshot_{3,4,8}rank_exact`, `ar_twoshot_{3,4,8}rank_exact`, `ar_twoshot_{3,4}rank_ti8`, `ar_gather_3rank` | the wider-world collectives (TP3/TP4/TP8), exact and int8-wire |
| `ar_twoshot_{3,4,8}rank_exact_lane`, `ar_twoshot_{3,4}rank_ti8_lane` | the same two-shots at `overlap` 1, beside compute: the wide rows' entry points, the same bits; at four ranks a narrow launch (4 blocks of 1024 threads), at three and eight the wide launch unless `R4D_AR_LANE_3_8=1` gives them the narrow one (unmeasured on such cards) |
| `p2p_copy2d`, `p2p_copy2d_kernel`, `p2p_fence` | strided peer device-to-device copy, through the copy engines or a kernel |
## Constraints as data