Dtypes and quantization
A logical dtype describes the tensor’s stored numerical representation. A physical packing describes how a kernel arranges those values in bytes for efficient access. Model authors choose logical dtypes; the compiler handles compatible physical packing.
Supported names
Use these strings wherever an RDL function accepts DType:
| Category | Names |
|---|---|
| Boolean | bool |
| Signed integers | int8, int16, int32, int64 |
| Unsigned integers | uint8, uint16, uint32, uint64 |
| Floating point | fp16, bf16, fp32 |
| Scaled INT8 | row_int8, grp_int8 |
| Grouped low-bit integers | grp_int4, grp_int5, dubgrp_int6 |
| Binary/ternary | grp_binary, grp_ternary, mat_ternary |
| Low-bit floating point | mxfp4, fp8_e4m3 |
Operations need compatible kernels for their selected dtypes.
Choose storage explicitly
W = Model("checkpoint")
weight = Weight(f"{W.root}.projection.weight", dtype="bf16")
Without an explicit weight dtype, the compiler uses source-resolution information. With one, it resolves/converts the checkpoint tensor into the requested representation where supported.
low_precision = Cast(x, "bf16")
quantized = Cast(x, "row_int8")
Cast converts logical values. Quantizing can lose information.
Promotion and accumulation
The compiler resolves operation dtypes and inserts required conversions. Common cases include:
- Same-type ordinary numeric tensors generally keep their dtype
- Mixed floating tensor types promote to FP32
- Boolean numeric arithmetic treats booleans as zero/one; adding two boolean tensors produces int64
- Signed/unsigned integer combinations may require a wider type or an explicit common cast
- Quantized tensors in generic arithmetic are promoted to floating computation
Scalar literals and operation-specific rules also affect promotion. Use an explicit Cast when the model needs a particular result representation.
A kernel can use a wider accumulator internally. For example, INT8 products may accumulate in INT32 before producing a scaled floating result. Kernels choose accumulator precision to implement the described computation.
BitLinear and shared activation codes
BitLinear(x, weight) quantizes activations, applies the projection and returns FP32. When several projections share the same input, quantize once explicitly:
codes, scale = QuantizeInt8(x)
q = QuantizedLinear(codes, W["q.weight"], scale, dtype="bf16")
k = QuantizedLinear(codes, W["k.weight"], scale, dtype="bf16")
v = QuantizedLinear(codes, W["v.weight"], scale, dtype="bf16")
QuantizeInt8 returns INT8 codes and an FP32 per-row multiplier used during quantization. QuantizedLinear divides by that multiplier to undo activation scaling.
Choose weight and activation dtypes according to the model.
Cache precision
A BF16 cache can receive a floating activation; conversion happens at the write boundary. An activation’s dtype and a persistent cache’s storage dtype remain separate decisions.
Changing cache dtype can change numerical quality and kernel availability.
Numerical expectations
Redwood describes inference mathematically. Results can vary between kernels because of floating-point reduction order and intermediate precision.
Quantized representations introduce their own approximation. Validate a chosen representation against the model’s expected behavior; avoid assuming that every low-bit checkpoint uses the same scale convention just because its container dtype is an integer.