Processing

Preprocessing turns an application request into the graph’s input tensors. Postprocessing turns output tensors into a result, such as text, a waveform or an image.

request -> preprocess -> TensorInputs -> model -> TensorOutputs -> postprocess -> result

Model computation belongs in RDL. Describe neural-network components such as text encoders, vocoders and image decoders in RDL.

Choose supplied functions or custom callbacks

NeedUse
The supplied processor matches your model’s tensor contractDeclare defaults in RDL
Your application needs different input/output handlingSupply callbacks to runtime Model
Your application already owns all tensor conversionCall Runtime directly

Check that the processor matches the model’s token conventions, feature extraction, shapes and conditioning inputs.

Declare defaults in RDL

from redwood.rdl import *

W = Model("checkpoint")

processing = {
    "pre": "text",
    "post": "text",
    "assets": {"tokenizer": W.root},
    "options": {"chat": True, "skip_special_tokens": True},
}

This top-level mapping belongs alongside the model graph. The compiler records the identifiers/options and copies supported assets from the named bindings into the compiled directory.

tokenizer names the asset role; W.root names the checkpoint binding used to obtain it. For Whisper, declare both tokenizer and features assets.

processing = {
    "pre": "whisper", "post": "text",
    "assets": {"tokenizer": W.root, "features": W.root},
}

The compiler validates built-in processor identifiers and options. Supply custom callbacks from your application when needed.

Public Python modules

redwood.processing exposes preprocessing, postprocessing, utils and these types:

TypeMeaning
TensorInputsMapping of input names to NumPy arrays or supported JSON values
TensorOutputsMapping of output names to NumPy arrays
Preprocessor[T]Function from request type T to TensorInputs
Postprocessor[T]Function from TensorOutputs to result type T
AudioFloat32 sample array and integer sample rate

The processing reference covers supplied functions and utilities. The custom-processing guide shows how to implement callbacks.

Loading and ownership

Text processing uses local Hugging Face tokenizers or supported SentencePiece assets. Compile with checkpoint directories containing the tokenizer and configuration files so the compiler can bundle them.

Model uses recorded defaults unless a callback explicitly overrides that stage. Both stages must exist. Processing is synchronous within each request, and long-running custom work needs its own cooperative cancellation.

Pass complete messages from your application, as described in sessions.