SGLang Diffusion ModelOpt Quant
Overview
Use this skill when the task is to take a diffusion transformer through the full ModelOpt workflow:
- quantize it with NVIDIA ModelOpt
- adapt the exported checkpoint to SGLang Diffusion
- verify that quality holds up
- benchmark whether the quantized checkpoint is actually faster
This skill owns the ModelOpt-to-SGLang bridge. It is not a generic kernel-tuning skill.
Core Rules
- Use ModelOpt's official
quantize.pyas the PTQ source of truth. - Keep the workflow generic. Put model-specific fallback logic in small isolated branches, not in the main conversion path.
- Benchmark only when BF16 and quantized commands are identical except for the checkpoint override being tested.
- For diffusion FP8, keep
dit_cpu_offload=false.dit_layerwise_offload=trueis valid on the fixed path when you want lower DiT residency. - For multi-transformer pipelines, use per-component overrides when different components need different checkpoints.
- For B200 NVFP4 validation, keep backend-sensitive environment variables
explicit. The current default is FlashInfer TensorRT-LLM
(flashinfer_trtllm); high-resolution Qwen Image can favor
SGLANG_DIFFUSION_FLASHINFER_FP4_GEMM_BACKEND=cutlass, while 1024x1024 can
remain BF16-faster. Benchmark the exact shape instead of assuming one backend
or quantized checkpoint wins.
- When a branch is missing the validated helper tools, refresh
python/sglang/multimodal_gen/tools/build_modelopt_fp8_transformer.py,python/sglang/multimodal_gen/tools/build_modelopt_nvfp4_transformer.py, andpython/sglang/multimodal_gen/tools/compare_diffusion_trajectory_similarity.pyinstead of inventing one-off scripts elsewhere. - After validating a new ModelOpt quant path, update the ModelOpt support matrix in
docs/docs/sglang-diffusion/quantization.mdxbefore closing the task.
Read First
Read these sources before changing code:
- NVIDIA ModelOpt diffusers guide:
examples/diffusers/README.md - ModelOpt quantization entrypoint:
examples/diffusers/quantization/quantize.py - ModelOpt diffusers quant presets:
examples/diffusers/quantization/config.py - SGLang diffusion quant runtime:
python/sglang/multimodal_gen/runtime/layers/quantization/modelopt_fp8.pypython/sglang/multimodal_gen/runtime/layers/quantization/modelopt_quant.pypython/sglang/multimodal_gen/runtime/utils/quantization_utils.pypython/sglang/multimodal_gen/runtime/loader/transformer_load_utils.py- Helper tools in this repo: