Processing reference

Supplied preprocessors have the signature function(value, *, assets, options) and return TensorInputs. Supplied postprocessors have function(outputs, *, assets, options) and return the application result.

assets maps role names to local directories. options is a mapping of JSON-compatible settings. Runtime Model binds these from the manifest; direct callers pass them explicitly.

Text

preprocessing.text accepts a plain string or a mapping containing text or messages, plus optional reset:

{"messages":[{"role":"user","content":"Explain inference."}],"reset":false}

Supply exactly one of text and a nonempty messages list. Messages contain role and string content. It returns int32 tokens and scalar boolean reset.

OptionDefaultMeaning
chattrueApply the tokenizer’s chat template when available
visionfalseAdd text-only empty vision inputs for the supplied Qwen programs
skip_special_tokenstrueText postprocessing removes special tokens

Use custom processing for actual image/video input. Message lists require a supported tokenizer chat template.

postprocessing.text decodes the tokens output into a string. The supplied launch RDLs return generated tokens, excluding the prompt. A true truncated output raises an error.

Whisper

preprocessing.whisper accepts an audio-path string, an Audio value, or a request:

{"path":"sample.wav","language":"en","task":"transcribe"}

Task is transcribe or translate; defaults are English and transcription. The processor produces mel, decoder-prefix tokens and reset. Pair it with text postprocessing.

Assets must contain features and tokenizer. Audio is converted to mono 16 kHz. Each call supports at most 30 seconds; split longer recordings in the application. Combining transcriptions and handling overlap is an application decision.

Parakeet

preprocessing.parakeet accepts an audio path, a path request, or Audio. It converts audio to mono 16 kHz and returns NeMo-style normalized log-mel features under mel.

The graph handles prediction. Pair the supplied token-producing graph with text postprocessing and its tokenizer assets.

PocketTTS

preprocessing.pocket_tts accepts nonempty plain text, normalizes whitespace/capitalization and adds final punctuation when needed. It returns tokenized text under tokens using local tokenizer assets.

Add any voice features or other conditioning inputs required by the RDL through a custom preprocessor.

postprocessing.audio reads audio, checks finite samples and returns Audio(samples, sample_rate). Set the positive sample_rate option to match the model, such as 24000. A true truncated flag raises an error.

Image generation

preprocessing.image targets the FLUX.2 Klein-style contract. It accepts a prompt string or:

{"prompt":"A redwood forest at dawn","height":1024,"width":1024,"seed":7,"steps":4}
FieldDefaultBounds
height, width102416 through 1920, multiples of 16
seed0Unsigned 64-bit integer
steps41 through 1000

It returns tokens, coordinates, sigmas, height, width and seed. Prompts are limited to 512 encoded tokens. The RDL’s own compiled bounds still apply, so a particular program can impose tighter limits.

The coordinates and sigma schedule are model-specific. For another image architecture, adapt processing to its coordinate and scheduling conventions.

postprocessing.image reads a finite channel-first RGB tensor [3,height,width] named image, interpreted in [-1,1], and returns a PIL image.

Utilities

Import these from redwood.processing.utils:

FunctionResult
tokenize(text, assets=..., chat=True, enable_thinking=None)Rank-one int32 token array
decode_tokens(tokens, assets=..., skip_special_tokens=True)Decoded string
load_audio(value, sample_rate=16000)Mono float32 Audio at the requested rate
log_mel(audio, mel_bins=128, n_fft=512, window_length=400, hop_length=160, preemphasis=0.97)Normalized [mel_bins,frames] features
image_from_tensor(tensor)PIL RGB image from [3,H,W] values in [-1,1]

tokenize accepts text or supported message dictionaries. SentencePiece-only assets accept plain text. decode_tokens expects rank-one integer tokens.

load_audio accepts a path or Audio; it averages file channels and resamples when needed. File formats depend on the installed audio reader. log_mel uses NeMo-style normalization and needs at least two feature frames.

To call a supplied processor directly, pass assets and options, or bind them with functools.partial for use as a Model callback.