Files
radiance/docs/IMPLEMENTATION.md
Deadcode 3b13fd3266 radiance 2.3.0
New models. Thinking Machines' Inkling 2 Mini by gostar (#584-#586): its text backbone and loop, the
release's NVFP4 and MXFP8 checkpoint read by the converter, an int8 trunk, the vision tower, tensor
parallelism, tool calls (with Warzuponus) and an image processor that matches transformers bit for
bit (millaguie). Inkling's routed experts are served in IQR-V4's four-bit trellis (moe_gemm_iqr),
fitted by GPTQ against Hessians the plugin now records (`--calib-dir`), its token embedding in int8
(read in place by embed_lookup), and incoai's DFlash2 drafter in four bits in place of the release's
DSpark. That container, 14.4 GiB with the vision tower, decodes 190 / 427 / 658 tokens a second at 1
/ 4 / 8 streams at tp 2 on two R9700 with `draft-window: adaptive` (code 240 / 550 / 790,
step-by-step arithmetic 358 / 811 / 1116): 19-43% ahead of the same target with the release's DSpark
drafter and 45-83% ahead of the all-int8 container (26.1 GiB, 124 / 263 / 386), at a mean KL of
0.0066 against the release's weights (int8: 0.0042). DeepSeek-V4.1-Flash on 2.x by baKon (#583),
with its vision tower, its IQ1_S and IQ2_XXS containers and linears and experts served in
llama.cpp's own blocks; parts ported from mikoskinen/r9700-exact-serving by Dad_Vibes' fork.
GLM-5.3-Flash on 2.x with its IQR / IQ8R container, an int8 latent cache and four-card serving by
AnimusNull (#566). Gemma 4 dense on EXL3-V3 by keptn42 (#537), on the EXL3 dense rows and
qwen35_exl3 tensor parallelism by Hero422. NVIDIA's 2-bit Nemotron-3.5-Bolt-74B-A9B on one card by
keptn42 (#477). Wan 2.2 TI2V-5B text-to-video and first-frame video by rkcth (#535). LFM3-1.7B on
RDNA3 iGPUs by DokterSmol (#578). Qwen3.8-27B in bf16 with the DFlash2 drafter, and bf16x12, bf16
weights packed losslessly in 12.25 bits, by eddie168 (#577). Int8 experts for drama-3 by morevgalex
(#598).

Speculative decoding. Draft trees for Qwen3.8-27B's DFlash2 drafts by Kezi (#450, opt-in): one card,
+17% at one stream and +14% at two. --draft-max-lanes and --draft-min-accept, two gates on a block
drafter, and --draft-window-ckpt, its window KV kept in the checkpoint slots, by rkcth (#600-#602).
`draft-window: adaptive` verifies each sequence's drafts up to the first one unlikely to be kept. A
verify's rows share each K and V tile in Inkling's attention by gostar (#608): 93 to 118 tokens a
second at a 70k-token prompt on one card.

Generation. Krea 2 instruction edits with one or two references and registered outfill, LoRA on the
image generators with bias deltas and row-mixer adapters applied per request, and MiniMax-H3's
model-declared sparse attention profiles, by rkcth (#534, #542, #543, #605-#609). MiniMax-H3's audio
reference guide pinned from a frame by 1beb (#595). LTX-2's chunk ceiling raised to 40 by Itoash
(#570).

Fleets and memory. memory.queue-reserve, the hardware queues a card keeps ready, by kevinjd (#589).
memory.pinned-numa-node by Foundry (#580). memory.card-headroom-mib on single-model tensor-parallel
budgets by zihaomu (#624). Parked weights rebuilt on the CPU, memory ownership kept across a failed
handoff and quiescent callbacks serialised, by rkcth (#557-#561). A warm load may unload a parked
model (#592); the first card listed chooses the architecture (#458).

Kernels. libr3d's packed dense IQR GEMM and routed IQR expert rows on gfx1100, and libhalo's GEMV
decode for Qwen3.8-Flash-Next's MoE down, by zihaomu (#562, #620, #622). GGML IQ2_XXS and IQ3_XXS
packed on the card by baKon.

Dashboard. KV cache in tokens (in use, capacity now and with all flexible space), live figures
through long prefill steps, step / decode / prefill / acceptance lines without holes, and expert hit
rates only on tiered models. Seven tile and history defects fixed by Noblistic (#597), vision
encoder and per-card hardware figures by davetha (#574), per-LoRA attribution by dowjames (#552).

Fixed. return_tokens / return_token_ids on the OpenAI endpoints (#571). reasoning_effort "none" and
"minimal" reach a template that takes them as levels, by millaguie (#608). Misaligned loads in the
windowed paged attention over an int8 cache (#540). A retired 27B head refused by name (#541).
rad-convert's GPU trellis jobs kept fed, and --reuse-only, by gostar (#575). jinja's tojson takes
sort_keys by Warzuponus (#582). hfget measures file sizes with stat, by kepler_62f (#623). The
tested C++ compiler is stated in the build guide by lowell80 (#551). The codebase was cleaned up:
shared helpers instead of repeated blocks, and the int8 linear, activation and GEMM code no longer
named after the retired fp8 formats.

Inkling 2 Mini is served in one form: IQR-V4 experts with the DFlash2 drafter
(StillDeadcode/inkling-2-mini-iq4r-v4 on Hugging Face, or
data/recipes/inkling2-mini-iq4r-v4.recipe). A container with the release's DSpark drafter, or with
NVFP4, int8 or 4-bit experts, is refused by name and needs converting again.

Plugin ABI 44: out-of-tree plugins need to be rebuilt.

Thanks to @gostar, @baKon, @Dad_Vibes, @AnimusNull, @keptn42, @Hero422, @rkcth, @DokterSmol,
@eddie168, @morevgalex, @Kezi, @1beb, @Itoash, @kevinjd, @Foundry, @zihaomu, @Noblistic, @davetha,
@dowjames, @Warzuponus, @millaguie, @kepler_62f, @lowell80 and @Code000.
2026-11-26 15:28:37 +01:00

9.5 KiB

Radiance: implementation brief

spec.md is the design and it is binding; read it first. This file covers the mechanical part: where things live, how they build, and the conventions every component follows.

The host backend is a primary target

Everything except the device kernels builds, tests and runs through the host device backend: cmake with no ROCm must configure, build, test and run, and RAD_HIP_FOUND gates only the HIP backend and the device kernels. A machine with no card is a complete development environment for the core, the tools, the architecture plugins and libref, and the suite runs in full there.

Layout

abi/              the ABI, and all a plugin compiles against. Frozen: change it deliberately
core/rad_internal.h   shared internals: logging, Geometry, constraint matching
core/util/        logging, error strings, dtype arithmetic, tensor helpers
core/device/      device backends: host, and aql (HSA queues the engine writes; HIP for memory)
core/plugin/      plugin loader, kernel registry, op schemas, selector, bucket tables
core/build/       the declare phase: builder, weight manifest, buffer plan, graph dump
core/runtime/     the run phase: RadCtx, rad_issue, the arena
core/mem/         pools, slab, KV block manager, prefix cache
core/kvstream/    streamed KV: the host mirror, the VRAM ring and its bring-up (docs/KV-STREAMING.md)
core/lora/        LoRA adapters loaded beside the base model
core/sched/       scheduler, RadBatch construction, request lifecycle
core/place/       placement planner, the mover, the heat engine
core/sample/      device sampler dispatch, the host reference chain, grammar bitmask
core/text/        tokeniser, chat template, tool parsing, detokenisation
core/mm/          image and video decoding, and the processor that turns frames into patches
core/gen/         image generation: the request and the pass driver
core/format/      the .rad reader and writer, safetensors, recipes, the imatrix, the tune cache
core/server/      HTTP: the OpenAI, Anthropic and llama-server endpoints, /metrics, the dashboard
core/diag/        the startup report
core/fleet/       the YAML file `radiance --config` reads: levels, defaults, the flag table's keys
core/kld.*        the KL mode: the kld-record / kld-ref keys
core/engine*      the engine that ties them together; core/main.cpp is the `radiance` binary
libref/           every op, naively and correctly, host domain: the oracle and last resort
libr4d/           the RDNA4 (gfx12xx) kernel library: kernels, rows, layouts, fusion claims
libr3d/           the RDNA3/3.5 (gfx11xx) kernel library
libhalo/          the Strix Halo (gfx1151) kernel library
libavx/           the same vocabulary in x86 SIMD, host domain: the production host kernels,
                  built on every x86-64 build because the engine refuses to serve an op that
                  resolves only to libref (without debug-accept-reference-kernels)
libquant/         the built-in quantisers rad-convert's recipes name: grids, transforms, rtn, gptq
plugin/spechub/   the draft-coupling ops (`mtp_couple_propose`, `mtp_couple_verify`, `mtp_trav_verify`,
                  `dflash_couple_propose`, `draft-coupling: on`): schemas and shapes on the host,
                  launches on the card and in a host reference
plugin/glm/       GLM-5.3-Flash's fused kernels, ops only glm5next issues
plugin/exl3i/     EXL3-V3 on gfx1201: `exl3i_dense` (trellis linears at any rate in 1/8 steps), the
                  A8 path's quantiser, the head's rerank and the trellis and fwht128 token tables
plugin/exl3quant/ the `exl3i` quantiser: imports EXL3-V3 levels into the exl3i encoding
plugin/qwen35_exl3/, plugin/gemma4_exl3/
                  the architectures (`qwen35`, `exl3`) and (`gemma4`, `exl3`) over those linears
plugin/exl3import/ the EXL3-V3 decode (the oracle) and interface headers the four share
arch/<id>/        one architecture plugin per directory
tools/            rad-info, rad-convert, rad-export, rad-kbench, rad-tune, rad-schemas,
                  rad-tokcheck, rad-yaml, rad-chatparse, rad-gbnf-check
cmake/            rad_add_plugin, and the package config an out-of-tree plugin find_package()s
scripts/          harnesses for serving, tracing and profiling a running engine
dashboard/        the page the engine serves at `/` (React, built by Vite into
                  core/server/dashboard_page.h)
docker/           the image build (`docker/build.sh`) and its licence collection
deploy/           compose files, chat templates, Grafana dashboards
integrations/     clients of the HTTP API (ComfyUI nodes)
data/             kernels.rkb and kernels_moe.rkb: recorded references rad-kbench replays with
                  no model. Two, because no one container declares the whole vocabulary.
                  recipes/: the quantisation recipes of the containers this tree serves
docs/KERNELS.md   what rad-kbench last measured, generated and checked in
vendor/           llama.cpp lifts tracked to an upstream commit (vendor/UPSTREAM), changed only
                  through vendor/patches/; yyjson and cpp-httplib
tests/            ctest

Each directory has its own CMakeLists.txt and builds only what is inside it. A new top-level directory adds its add_subdirectory line to the root CMakeLists.txt; arch/CMakeLists.txt adds every architecture directory itself.

Build

cmake -S . -B build -G Ninja           # host backend; no ROCm required
cmake --build build -j
ctest --test-dir build --output-on-failure

A change is done when its directory compiles and its tests pass.

Conventions

No Python in the engine, its tools, its build or its test suite. spec.md opens with this constraint. Tests are C++ and CTest. The Python files in the tree are run by hand and nothing in the build or the suite calls them: tests/mkgolden.py and tests/mklfm2golden.py regenerate the reference numbers in tests/mm_golden.h and tests/lfm2_golden.h from transformers; tools/pad_tp.py and tools/pad_verify.py pad a checkpoint for a tensor-parallel width and check the result; scripts/cardclock.py monitors card clocks.

C ABI at plugin boundaries, C++20 inside. abi/ is C and must stay compilable as C. Everything under core/ is C++20 and may use the standard library freely.

Errors are values. Return RAD_OK or a negative RAD_E_*. Do not throw across a function that a plugin or the run phase can call. fatal() is for broken invariants only.

Nothing unimplemented returns success. An unwritten function returns RAD_E_UNSUPPORTED and logs once at Warn with its own name. A stub that returns 0 produces fluent wrong output with no way 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 against region 0's 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 are the same memory, so a memset on host memory passes in a no-ROCm build and fails on a card. Use RAD_MEM_HOST_PINNED or RAD_MEM_HOST_MAPPED, or memset on the host. rad_memcpy_async accepts pageable memory but bounces it through pinned memory and waits, so a pageable copy on the step path is a host stall; aql_pageable_bytes() counts them.

Kernel plugins launch with hipLaunchKernel and the engine dispatches them. On a card every stream is an HSA queue the engine owns and writes AQL packets into (core/device/aql.cpp). The executable defines hipLaunchKernel and HIP's kernel registration hooks, so a plugin built by hipcc needs nothing special. A plugin must not call any other HIP stream API on an engine stream: hipEventRecord and hipStreamWaitEvent are refused by name, and anything else would hand HIP a stream it does not own. Use rad_event_* and rad_memcpy_async.

Comments explain the decision, not the syntax. Say why this and not the obvious alternative, and name the cost when there is one. libr4d/r4d_rows.cpp is the model.

Naming. rad_ prefix on everything with external linkage. Files are named for what they provide. snake_case for functions and variables, PascalCase for types.