RDL overview
RDL is Python source that describes model computation. The compiler executes the file to build a graph. The runtime later executes that graph’s compiled kernels with numerical inputs.
Write self-contained .rdl files. Their only import is:
from redwood.rdl import *
A small model
from redwood.rdl import *
W = Model("checkpoint")
with Graph() as graph:
x = Input(
name="x", shape=(None, 128), dtype="fp32",
maximum_shape=(256, 128),
)
y = Linear(x, W["projection.weight"], bias=W["projection.bias"])
Output(y, name="y")
This program applies a checkpoint projection to a sequence of up to 256 vectors. Model("checkpoint") declares the command-line binding checkpoint=/path/to/weights.
The graph above accepts tensors. To accept application data through runtime Model, declare standard processing defaults or supply custom callbacks.
What runs when
| Python/RDL code | Meaning |
|---|---|
A Python for over layer numbers | Build those layers during compilation |
| A local Python function | Build a repeated part of the graph when called |
If | Execute one branch during inference |
While | Repeat a graph body during inference |
Shape or Dim | Compute dimensions as graph values |
@Construct | Keep a named operation and its full core composition |
Use RDL operations for decisions based on tensor values. The compiler infers intermediate shapes and dtypes after tracing.
Core and compositions
Core operators describe arithmetic, indexing, tensor shapes, control flow and persistent state. Higher-level operations such as Linear, Attention and FFN are built from them.
Use existing compositions when they fit. For a bespoke algorithm, use core operations or define a composition:
@Construct
def gated_update(x: Tensor, update: Tensor) -> Tensor:
return Add(x, Mul(Sigmoid(x), update))
A composition preserves its mathematical body. The compiler can select a fused kernel or compile the body using smaller kernels. Compilation requires compatible kernels for the shapes and dtypes used by the graph.
Keep library constructs around attention/MLP size or smaller. Put the model’s layer stack and full inference procedure in its RDL file. Use constants and local functions to keep model authoring concise.
Describe the full request
For a generative model, include prefill, decode, output selection and stopping conditions.
Declare caches explicitly, with fixed capacity. For session-aware LLMs, use ReusePrefix and a reset policy to reconcile a full incoming prompt with stored state. Caches persist between successful runtime calls; message history belongs to the application.
RDL describes numerical computation. Tokenization, audio loading and other application conversions belong in processing.
Reference
- Graph, inputs, outputs and checkpoints
- Core and common tensor operations
- Branches, loops and reductions
- Caches and prefix reuse
- Dtypes and quantization
- Higher-level compositions
RDL files execute as Python during compilation. Use programs you trust.