sglang/kernels/ops/diffusion.
This page is an inventory: what each kernel fuses, what its numerical contract is, and which models use it. It is not a lever you tune — most of these kernels are on by default and require no flag. The one switch is --quality, described below.
Numerical contracts and quality tiers
Multi-step denoising amplifies a per-step rounding difference into visible quality loss, so “close enough” and “bit-exact” are different products here. Thequality switch distinguishes unconditional bit-exact replacements from non-bit-exact eager-chain fusions:
Bit-exact — mounted unconditionally. The kernel reproduces every rounding boundary of the eager chain, so torch.equal holds against the reference. Some go quite far to get there: the fused LayerNorm+modulate kernel replicates PyTorch’s vectorized_layer_norm_kernel down to its Welford update order, guarded reciprocal, and warp-fold tree; the fused RMSNorm+scale/shift kernel replicates FlashInfer’s CuTe-DSL RMSNormKernel fragment order and shfl.bfly fold. Because the dispatch they replicate can change underneath them, each one still verifies itself against the live eager chain on first sight and falls back permanently on any mismatch.
Not bit-exact — request-gated. These differ from eager only at half-precision rounding-order level, but that is enough to matter, so they are mounted only for quality="extra-high" and quality="high" requests, at batch boundaries, all-or-nothing per transformer. The default quality="lossless" runs the unmodified reference chain.
Model/checkpoint-native. Generic close-contract kernels, sparse operators, and FP8/NVFP4 producers can be part of a model implementation or a separately selected deployment path. They are documented in the inventory, but quality does not select or undo those choices.
Selection-equivalent routing — enabled unconditionally. LingBot Video’s fused group-limited top-k returns the same selected expert-id set as its guarded CUDA torch.topk(..., sorted=False) reference chain. The order of those ids is not part of either path’s contract. Because the selected experts are unchanged, this path does not depend on the request quality tier.
A plain fp32 single-pass norm fusion looks harmless and is not. On ERNIE-Image it moved the 50-step trajectory to 18.83 dB PSNR, which is what motivated the bit-exact rewrite of that path.
If a model has no eligible request-gated fusion,
extra-high can execute the same path as lossless. Likewise, high adds only the model-specific high-only paths that the active pipeline implements.
quality is not a master precision switch. A quantized checkpoint, an explicitly selected approximate attention backend, or an independently enabled cache remains active at every quality tier.Enabling the request-gated set
lossless; the OpenAI-compatible endpoints carry it per request. Images:
quality participates in the dynamic-batch signature, so mixed-quality traffic is batched separately and the transition happens safely at a batch boundary. Mounting is all-or-nothing: if any marked site on a transformer fails its static guards, no site on that transformer is fused.
These fusion families mount under both quality="extra-high" and
quality="high":
Kernel inventory
45 operators are registered in the kernel registry across 51 implementations (some operators carry several backends). Backends are named by provenance, not device:KDA identifies Kernel Design Agents implementations, JIT compiles under nvcc and hipcc, TRITON identifies Triton sources, CUTE_DSL needs CUTLASS, FLYDSL is ROCm gfx950 only, and AOT comes from the sgl_kernel wheel. Per-operator capability metadata determines which devices can load each implementation.
Normalization
adaLN modulation and gating
RoPE and QK-norm
Activation
Attention
MoE routing
Data movement
Every kernel here only moves values (plus zero fill, plus at most one same-order add), so each is bitwise identical to the aten chain it replaces.Quantized layout producers
These kernels preserve the quantized checkpoint path’s selected reference operation. They are not a claim that FP8 or NVFP4 is equivalent to an unquantized BF16 checkpoint.Coverage by model
Kernels are written against a specific eager chain in a specific model, so coverage is per-model rather than universal.Inspecting what is registered
Every kernel is described by aKernelSpec in the process-wide registry, so the inventory is queryable without importing any backend:
Importing the kernels
Runtime code imports from the package, never from a submodule:can_use_<op>(...) first and fall back to the reference chain when it returns False; the kernel raises on an unsupported input rather than silently returning None.
The package README.md carries a selection matrix for the cases where several kernels look interchangeable and are not. The normalization domain alone holds more than a dozen implementations that differ by numerical contract, activation layout, and backend rather than by speed.
References
- Performance Optimization
- Attention Backends
- Quantization
- Profiling
sglang/kernels/ops/diffusion— source and selection matrix- RFC #29630 — the unified
sglang.kernelsnamespace
