Read the Code in This Order
The files are split by runtime responsibility. For a new model, read the request path first:registry.pychooses the model family, sampling params, and pipeline config.configs/pipeline_configs/{model}.pydefines model-specific denoising and decoding behavior.runtime/pipelines/{model}.pywires modules into stages.runtime/pipelines_core/stages/runs the shared stage logic.runtime/models/contains native model components only when the architecture cannot be reused.
runtime/models/ owns modeling code: checkpoint-defined neural modules,
architecture wrappers, and weight-loading or forward-path details that are
intrinsic to one model family. Reusable serving infrastructure belongs in
SGLang-Diffusion runtime folders such as runtime/cache/,
runtime/distributed/, runtime/utils/, or shared pipeline stages. This
includes cache managers, graph runners, process-group transport, request
utilities, and common action-policy helpers. Model packages may call these
helpers. Keep ownership in shared runtime folders unless the code is truly
architecture-specific.
Start With the Smallest Change
Before adding files, decide which path fits the model.
Do not add a folder just to mirror the Diffusers repository layout. Add a new
file only when an existing pipeline, stage, module, config, or sampler cannot
express the behavior clearly.
Minimal File Map
The source tree is split by runtime responsibility. That split is useful for optimization. Keep new model PRs focused on the files required by model behavior.
For a new native architecture, the common minimum is:
registry.pyconfigs/sample/{model}.pyconfigs/pipeline_configs/{model}.pyruntime/pipelines/{model}.pyruntime/models/dits/{model}.py
runtime/models/. Prefix caches,
request-local contexts, denoising graph runners, OpenPI-compatible transport,
and prefix/action process-group utilities should be shared SGLang-Diffusion
runtime infrastructure when they are useful beyond the first model.
Read the Reference First
Use the model’s Diffusers pipeline, official implementation, ormodel_index.json as the source of truth. Write down:
- Which modules must be loaded: tokenizer, text encoder, image encoder, transformer, scheduler, VAE, processor, and any extra adapters.
- The prompt and image encoding flow.
- Latent shape, packing, scale, shift, dtype, and device rules.
- Timestep and sigma schedule.
- The exact
forward()kwargs expected by the denoising network. - VAE decode rules and output post-processing.
Choose a Pipeline Shape
SGLang-Diffusion usesComposedPipelineBase to wire stages together. Most
native pipelines should use one of these two shapes.
Prefer standard stages when possible. Use a model-specific
BeforeDenoisingStage when trying to force the model into shared stages would
create many conditionals.
Implement the Pieces
1. Sampling Params
Create request parameters only for values users can set at runtime.2. Pipeline Config
PipelineConfig is where shared denoising and decoding stages get model-specific
callbacks.
forward() signature exactly.
3. Pipeline Wiring
Use the standard helper when the model fits it.4. Optional Before-Denoising Stage
ABeforeDenoisingStage should populate the batch fields consumed by
DenoisingStage.
DenoisingStage:
5. Denoising Module
Add a file underruntime/models/dits/ only when the architecture is new. Reuse
existing encoders, VAEs, schedulers, normalization layers, and fused kernels
whenever possible.
For multi-GPU serving, add TP/SP support after the single-GPU path is correct.
Useful references:
runtime/models/dits/wanvideo.pyfor TP plus SP.runtime/models/dits/qwen_image.pyfor USP attention.
6. Registry
Register the family once the sampling params and pipeline config exist.EntryClass; do not add a second
pipeline registry unless the existing registry requires it.
Verify the Port
Use one deterministic prompt and seed while comparing with the reference implementation.- Run a single-GPU smoke test and check that the output contains coherent content.
- Compare latent scale and shift, timestep order, sigma values, and conditioning kwargs against Diffusers or the official implementation.
- Verify VAE decode and post-processing separately from denoising.
- If the model supports LoRA, CFG parallelism, TP, SP, or disaggregation, test each feature explicitly.
- Add or update docs, examples, or the compatibility matrix when users need a new launch command.
- Wrong latent scale or shift.
- Reversed or dtype-mismatched timesteps.
- Missing negative embeddings when CFG is enabled.
- Conditioning kwarg names mismatched with the DiT
forward(). - Rotary embedding shape or style mismatch.
- Decoding packed latents without restoring
raw_latent_shape.
PR Checklist
- Reused an existing family, stage, module, scheduler, or VAE wherever possible.
- Kept the new-model touch surface small and justified any extra files.
- Added
SamplingParams,PipelineConfig, pipeline wiring, DiT module, and registry entry when native support is needed. - Confirmed
pipeline_namematches the Diffusersmodel_index.json_class_namewhen applicable. - Confirmed
_required_config_modulesmatches the model repo. - Verified image or video quality against a reference output.
- Tested multi-GPU paths if the PR claims TP, SP, CFG parallelism, or distributed serving support.
