Orpheus streams audio during decode
Orpheus turns{voice}: {text} into 24 kHz speech. Its model declares a paged KV cache and sampler for the LLM. The LLM prefills, then runs a decode loop that sends audio tokens across a streaming edge to a second partition. That partition decodes a sliding window of tokens while the LLM generates the next ones.
The SNAC decoder needs no declared state. The model’s get_node_precision keeps it in fp32 without autocast, the submodule sets disable_torch_compile, and it emits int16 PCM. The streaming tests exercise chunk boundaries and the final flush.
BAGEL switches between text and image generation
BAGEL uses one Qwen2 backbone for text decoding and image denoising. Its walk planner sends text spans throughprefill_text, image patches through prefill_vit, and image latents through prefill_vae. For interleaved prompts it binds each walk to its own span. Text output runs decode. Image output runs denoising followed by the VAE decoder. In think_mode, text decoding precedes denoising.
Three choices in the LLM submodule matter when adapting this design:
- Edges. A declared output is a possible output. The same LLM emits
new_tokenon text steps and can update the cache without emitting a token on image steps. Keeping embedding, transformer, and output heads together avoids transferring intermediate tensors between colocated nodes. - State. Text reads are causal. Image reads are bidirectional. On a guided request, the
cfg_textbranch forks before text is written but after an image is committed. A denoise step reads the cache withkeep=False. Rows and position IDs must follow the same label order, including placeholders for unguided rows. The capture key distinguishes guided and unguided decode. - Placement. The single-GPU config runs guidance branches in one forward. The CFG-parallel config gives
LLM_cfg_textandLLM_cfg_imgtheir own GPUs and joins them atcombine_cfg. The request’s guidance window determines its walks and loop caps. Unguided requests skip the branch GPUs. Include every denoise walk when assigningLLMranks per walk.
declare_step together when changing a guidance branch so the selected walks, cache labels, and capture keys agree.
Whisper reads a fixed encoder context
Whisper’s audio encoder and decoder have different lifetimes. The encoder needs no persistent state. During prefill the decoder writes the fixed encoder context tocross_kv_cache using ArrayStep(eager_add=True). Later steps declare zero additional context and read the resident pages. Decoder self-attention appends to kv_cache on each token. Its positions index learned embeddings. A separate decoder_state holds timestamp rules and the transcript used by alignment.
Size each pool for what one request can retain. At 128 tokens per page, a 448-token decoder needs four pages per request and a 1,500-token encoder context needs twelve. For 64 requests plus one sink page, that gives 257 self-attention pages and 769 cross-attention pages. The deployment caps concurrency at 64. validate_config_yaml checks that both pools still fit after resource overrides. The cache sizing tests cover this contract and the decoder tests exercise the step declarations.
For a new encoder-decoder model with an ordinary sampling decoder, start with EncoderDecoderNode, which already handles the fixed-context write and reads.
FLUX.2 denoises an image
FLUX.2 klein encodes the prompt once, denoises latents in a loop, and decodes the final latents with the VAE. Image editing also encodes a reference image. Conditioning persists across iterations. The loop carries latents from one step to the next. Implement the model-specific hooks in DenoiseLoopSubmodule. The base class batches compatible rows, draws seeded noise, caches schedules, and captures the denoiser and Euler update together.- Choose compatible rows.
bucket_key_forsupplies both the batch and capture key. Include any property that changes the forward, such as the latent grid, text length, or guidance mode.request_inputssupplies conditioning for a real row andcapture_request_inputssupplies the matching dummy inputs. - Initialize and run the denoiser. Implement
seed_latentsfor the first iteration,num_tokensfor the latent token count anddenoisefor the model prediction. - Define the schedule. Return the same step count from the model’s
get_loop_capsand the node’sschedule_for. Use the engine’s per-row loop counter. For additional device-side scalars, name schedule attributes inSTEP_SCALARS. SetPREFETCH_SEEDSonly if initial loop-back tensors depend solely on the bucket key and request seed. - Carry solver history. A multistep solver names extra loop-back tensors in
SOLVER_STATE, initializes them inseed_loop_back, and returns them from each step. For UniPC, useUniPCDenoiseLoopSubmoduleand implementmodel_output. Rows can then share a forward at different iterations. - Declare attention. Describe each layer’s attended spans in
attention_segmentsand declare arrays withmax_len=0for temporary tokens. The shared attention implementation uses a bound engine handle or falls back to SDPA.
DiffusionImageAdapter and its Rust counterpart. The SDK calls are generate_image and edit_image.
Qwen3.5 interleaves images and text
Qwen3.5 uses a vision encoder and a decoder LLM. A text-only prompt goes straight to the LLM. A prompt with images runs the vision encoder first, then prefills the whole prompt in one row with the image embeddings in their original positions. Both paths finish in the same decode loop.- Subclass DeclaredDecoderModel for a model using declared state. Supply
NAME,METADATA_FILES, the tokenizer, media intakes, and resource declarations. Implement_prompt_idsand_create_submodule. The base loads the checkpoint’s generation defaults, chooses walks for the requested media, constructs the state layout, and budgets decode after the token produced by prefill. SetTEXT_PROMPTS = Falsefor a model that always requires media. - Describe each encoder with a
MediaEncoder. Its output must contain one embedding row per media pad, in prompt order. Return the patch or frame layout in PreparedMedia. The scaffold stores it under the metadata keymedia_layout. The prompt-interleaving tests exercise a case that a single-image prompt misses: text and several images in one row. - Implement the forward passes in node submodules. Qwen’s LLM subclasses
DeclaredTokenDecoder, returns cache and sampler steps fromnode_step, and supplies its three-axis positions withprompt_positions. The shared decoder batches prefill and decode, captures supported shapes, and loops sampled IDs back on the device. Its vision encoder uses PackedBlockLoopEncoder to pack patches and replay the block loop by shape. - Check whether every declared resource can drop a request and rebuild it. The scaffold can retain prompt IDs and host copies of encoder outputs for reprefill. Override
rebuild_policiesto return an empty mapping when a resource cannot support this.