Expand description
The compiled generation lane: a model’s decode step, written in LOGOS from its ModelSpec and compiled to one
CUDA program that loads the checkpoint, runs the prompt and generates.
The path is the compiler’s own, end to end, and nothing on it is written for one model:
author::decode_stepwrites the step as a LOGOS program — the token and position in, every layer’s KV cache, convolution ring and delta-rule memory carried, the next token out — a cut of the model’s one program (program), whose identity the emitted program prints above the text it compiled;- the shared tensor front end lifts it into a
StepGraph: every statement an op, or the compile refused by name; weightsplaces every constant — quantized projections as rows read in place from the checkpoint, the rest computed once into a sidecar;plangives each op a kernel from thekernelslibrary, applies the fusion rules and lays out the buffers;arenaplaces every array a step computes and reads within the step in one arena, by its lifetime;emitprints the program, each step captured as one CUDA graph and replayed per token or per chunk.
A lane has several forms of the step, compiled the same way: the decode step, and author::prefill’s chunks of
2, 4, … rows — the same layers over a block of prompt tokens, every projection reading its weights once for the
block. They share the model’s constants and its carried state; the prompt runs as the largest chunks that fit.
The lane’s knobs are CudaKnobs’: activations picks the projections’ numerics — f32 activations with f64
sums, a two-word ~14-bit int8 activation (the default), or llama.cpp’s one int8 word — cuda_graphs captures each
step, fuse_quant quantizes a projection’s activation in its producer.
Modules§
- arena
- The step-local memory of a lane’s forms. Every array a step computes and reads within the step — a tensor’s
f32(ori32) buffer, or its quantized form — lives in one arena the program allocates once, placed by its lifetime: from the launch that first writes it whole to the last launch that touches it, through any view of it. A launch’s scratch lives there while the launch runs. The forms share the arena, one form running at a time. - branches
- A form’s launches as a graph over several streams. A launch runs after every earlier launch that writes memory it
reads or writes, or reads memory it writes — memory by where it lives: a step-local array or a launch’s scratch by
its bytes in the arena (which several tensors share in turn), anything else by its buffer, an alias — a view — where
its array lives (
arena::home). Each launch takes a stream: the stream whose last launch it follows, or one whose work it already follows, or the least recently used; it waits on another stream’s launch by an event only where nothing it already follows orders the two. The launches compute what they compute in order, every dependency kept. - emit
- The lane’s forms printed as one CUDA program, and the sidecar of values it reads.
- graph
- The step graph: an authored step (a decode step, a prefill chunk) as the ops it runs and the tensors they touch, each tensor given the role a compiled lane needs to place it.
- kernels
- The lane’s kernel library: one CUDA kernel per kind of op a step runs, each templated over the forms the fusion rules ask of it (a residual added before a norm, an activation quantized in a producer’s epilogue, a result written into the row of a cache a position names). The planner instantiates them; no kernel here knows a model.
- plan
- A step graph lowered to launches of the kernel library. The lane decides no fusion of its own: the step, lifted into
the one IR, is optimized by the shared table under the lane’s shim (
LaneShim), which answers whether a fused class has a launch; each op the optimizer leaves takes the launches its link names (link), a class the lane runs whole one launch, a class it runs as its parts each part’s. Then the lane’s schedule sets how the launches run — four rows a warp for a wide product (rows_a_warp), the shared-row attention, the split counts, a batch’s sequences as one launch (sequences) — and every tensor is given its buffers. - residence
- Where a lane’s arrays live. Every array the program allocates goes on the device while they fit the memory it is given; past it, constant matrices move to pinned host memory the device maps, in the order that costs a step least: a table only ever gathered from (a row a token), then each expert stack from the last layer’s back (a step reads its chosen experts’ rows), then the other matrices from the last read back — until the rest fits. A kernel reads a mapped matrix through the same pointer it reads one in device memory, so where a matrix lives changes no value. Matrices that read the same checkpoint rows (a tied head and the embedding table it is) share one upload.
- weights
- Where each constant of a compiled step comes from.
Structs§
- Form
- One form of a lane: the step of
rowsrows (1 for the decode step; a batch’s, one a sequence), its LOGOS source, its graph, its schedule and where its step-local arrays live in the program’s arena. - Lane
- A compiled lane: its forms, the decode step first, and the one program that runs them.
- Lane
Options - How a lane is compiled: its caches’ length in positions, its knobs, and its largest prefill chunk (a
power of two up to
plan::MAX_CHUNK; 1 runs the prompt a decode step at a time).
Enums§
- Form
Kind - What a form of a lane computes: the decode step, a prefill chunk of one sequence’s tokens, or a batch’s step of one token for each of its sequences.
- Lane
Error - Why a model’s step does not compile to the lane, by name.
Functions§
- batch_
io - The names an authored batch of
rowssequences reads and writes across steps: its tokens, one a sequence, and sequenceb’s positionpos_s<b>, logitslogits_s<b>and next tokennext_s<b>. - compile
- Compile the lane of
specagainst the checkpoint atcheckpoint: its decode step and its prefill chunks. - compile_
batch compilewith a batch step beside the decode step and the chunks: the model’s batch cut (Cut::Batch) ofbatchsequences, one token each a step, every weight read once for all of them, each sequence its own position, caches and next token. The program decodes up tobatchprompts together, each prefilled into its own sequence’s state.- compile_
batch_ holding compile_batchwith the fusion rulesheldheld back.- compile_
holding compilewith the fusion rulesheld(ofplan::RULES) held back, their launches kept apart: the program each fusion is checked against, computing what the fused one computes.- decode_
io - The names the authored decode step reads and writes across steps.
- prefill_
io - The names an authored prefill chunk reads and writes across steps.