Compiler
The compiler turns RDL and checkpoints into a directory the runtime can execute. Its public interface is redwood compile.
redwood compile model.rdl checkpoint=/path/to/model
The Python passes and intermediate records are private. Applications should use the CLI to compile and redwood.runtime to execute the result.
Checkpoint bindings
The model file declares checkpoint names:
from redwood.rdl import *
BASE = Model("base")
ADAPTER = Model("adapter")
Supply those names on the command line:
redwood compile model.rdl base=/path/to/base adapter=/path/to/adapter
The strings passed to Model supply the binding names. A reference such as BASE["layer.weight"] resolves layer.weight from the base binding.
Paths must exist and be readable. Safetensors files and directories are supported, including sharded checkpoints. A binding can also supply tokenizer or feature-extractor assets.
Quantized checkpoints need a supported interpretation of their codes, scales and configuration.
Express the adapter’s computation in RDL and supply its checkpoint path during compilation.
Input bounds
The compiler plans storage before execution. Variable input dimensions therefore need upper bounds. An RDL input’s maximum_shape takes precedence; otherwise --max-input-size supplies the dimension bound, defaulting to 4096.
Set cache capacities and generation limits separately in RDL. For an 8192-token prompt, the cache must also have room for the prompt and any generated tokens.
Scalar controls affecting allocation also need useful bounds in the model. See graph inputs.
Search levels
| Depth | What Redwood does |
|---|---|
none | Pick compatible kernels using heuristics, without benchmarking |
low | Measure alternative kernels for the selected computations |
high | Also explore alternative fused and composed implementations |
Start with none. Use more search when compilation time is worthwhile for a model you will run repeatedly.
Measurements use the selected machine and thread count. Exact workloads and search algorithms are implementation details and may change. The benefit of deeper search depends on the model and request size.
Compilation flow
RDL + checkpoints
-> validate references and infer shapes/dtypes
-> simplify computation and select kernels
-> pack weights and plan execution/memory
-> verify and publish a compiled directory
Kernel selection considers the computation, supported dtypes/layouts and available hardware/software. It can retain different choices for different workload sizes. Memory planning reuses intermediate storage after its consumers finish; caches remain persistent state.
Logical dtypes come from the model and supported promotion rules. Physical packing is chosen for the selected kernels.
Output
The compiled directory contains:
| Item | Purpose |
|---|---|
executable.json | Inputs, outputs, execution, memory and kernel requirements |
weights.bin | Logical weight metadata and prepared tensor payloads |
| Kernel libraries | Selected native implementations |
| Processing assets, when declared | Local tokenizer and feature-extractor files |
Use the compiler to write these artifacts and the runtime to read them.
The default location is $REDWOOD_HOME/<installed-version>/compiled/<model-name>/. With one binding, its directory name supplies the model name, or the parent name for a checkpoint file. Otherwise the RDL filename supplies it.
Use --output for an explicit path. Existing output is refused. Compilation writes to a temporary sibling directory, verifies the result, then renames it into place. Failure or Ctrl+C removes incomplete output.
For all flags, see CLI. For storage and compatibility, see files and versions.