rh-runninghub/minimax-h3-multigpu-lightning/sglang-diffusion-performance
Claude Code and agent skill by rh-runninghub/minimax-h3-multigpu-lightning
- community
Checking that the SKILL.md file is still in the repository.
Use when choosing the fastest SGLang Diffusion flags for a model, GPU, and VRAM budget.
Install
npx vskill@latest install rh-runninghub/minimax-h3-multigpu-lightning/sglang-diffusion-performanceSKILL.md
The same SKILL.md was published earlier as rh-runninghub/minimax-h3-multigpu-lightning/sglang-diffusion-performance.
SGLang Diffusion Performance Tuning
Use this skill when the user wants the fastest command line, lower VRAM, or the right performance flags for a specific model and GPU setup.
Start from the model's cookbook page
Tune from the deployment we already recommend, not from scratch: read docs/cookbook/diffusion/<Family>/ for the model first, take its command as the baseline, then apply the options below. The cookbook page is what users follow, so a recipe that silently disagrees with it on GPU count, parallelism degrees, or offload flags is a recipe for a configuration nobody runs.
Families with a cookbook page: Cosmos, Ernie-Image, FLUX, Ideogram, JoyEcho, Krea, LTX, LingBot-Video, LingBot-World, LongLive, MOVA, MiniMax, Qwen-Image, SANA-Video, SANA-WM, Wan, Z-Image.
test/ configs are pinned CI setups for correctness and regression checks, not deployment advice. Use them when you need an exactly reproducible run, and note which cookbook flags you diverged from.
Before running any sglang generate command below inside the diffusion container:
- use
python/sglang/multimodal_gen/.claude/skills/sglang-diffusion-benchmark-profile/scripts/diffusion_skill_env.pyto derive the repo root, verify write access, and choose idle GPU(s) - export
HF_TOKENfirst when the selected model lives in a gated Hugging Face repo such asblack-forest-labs/FLUX.* - export
FLASHINFER_DISABLE_VERSION_CHECK=1 - when a run downloads weights, use a task-owned cache and delete that model's
cache after its eager/BCG/quality/profile group finishes; the benchmark skill's --quality-bcg-matrix --model-cache-root --cleanup-model-cache keeps one cache for the group and writes a zero-residual cleanup ledger
- hold one idle GPU set for the complete A/B matrix and verify no foreign
process appears at run boundaries
cdto the repo root resolved fromsglang.__file__
Native Backend Gate
Performance numbers are useful only when the intended backend actually ran.
- Treat any log containing
Falling back to diffusers backend,Using diffusers backend, orLoaded diffusers pipelineas invalid for native SGLang performance tuning. - Use
--backend diffusersonly for an explicit diffusers baseline. For native recipes, leave the default backend or pin--backend sglang. - If a fallback happened, fix pipeline registration/model-path/config issues first, then rerun. Do not compare perf dumps collected from a fallback run.
- When the runtime auto-selects parallel settings because the user omitted them, keep the result as an auto-tuned baseline. For reproducible tuning, pin
--num-gpus,--ulysses-degree,--ring-degree, and--enable-cfg-parallelexplicitly.
Reference: SGLang-Diffusion Advanced Optimizations Blog
Section 1: Lossless Optimizations
These options are intended to preserve output quality. In practice, some paths (most notably torch.compile) can still introduce small floating-point drift, so validate on your target model when numerical parity matters.
| Option | CLI Flag / Env Var | What It Does | Speedup | Limitations / Notes | ||||
|---|---|---|---|---|---|---|---|---|
| Performance Mode | `--performance-mode auto\ | speed\ | memory\ | manual (--mode` alias) | Applies model-aware residency, FSDP/CFG, and compile defaults without overriding explicit flags. auto is the safe default; speed favors GPU residency; memory favors offload; manual leaves performance args explicit. | Fastest way to establish a sensible deployment baseline | speed may OOM and enables torch.compile only when the model deployment config allows it. Explicit offload/FSDP/parallelism/compile flags win. Use manual for controlled A/B benchmarks. | |
| torch.compile | --enable-torch-compile | Applies torch.compile to the DiT forward pass. Treat it as a measured comparator, not an assumed upgrade. | Model- and shape-dependent; recent B300 coverage found eager or valid BCG faster or within 1% for every valid compile control | First request is slow and some models time out or drift numerically. Keep eager as the ground truth, use a warmup watchdog, and validate the target model. See the H200/B300 survey. | ||||
| Breakable CUDA Graph | --enable-breakable-cuda-graph plus optional --warmup-resolutions <WxH...> and --bcg-text-buckets ... | Captures fixed-resolution DiT segments while leaving attention/collectives eager, reducing launch overhead on supported pipelines. | Large on launch-bound paths; merged SANA and LTX-2 cases show material e2e gains | Mutually exclusive with torch.compile and Cache-DiT; BCG takes priority. The model's default resolution is captured automatically; declare every additional production resolution. Current support is model-specific (Ideogram4, LTX-2/2.3, LongCat-Image, MiniMax-H3, Qwen-Image, SANA1.5, SANA-Video, Z-Image, GLM-Image), but an allowlisted model is not automatically a validated recipe. A valid run must log capture and no disable/failure/signature miss. --warmup-resolutions covers only WxH; video frame/conditioning mismatches can still fall back to Eager. MiniMax-H3 remains eager in the validated deployment because prompt-dependent packed host boundaries can miss the captured signature. | ||||
| Warmup | --warmup-mode request | Runs dummy forward passes to warm up CUDA caches, JIT, and torch.compile. Eliminates cold-start penalty. | Removes first-request latency spike | Adds startup time. Without --warmup-resolutions, warmup happens on first request. | ||||
| Warmup Resolutions | --warmup-resolutions 256x256 720x720 | Pre-compiles and warms up specific resolutions at server startup (instead of lazily on first request). | Faster first request per resolution | Each resolution adds to startup time. Serving mode only; useful when you know your target resolutions in advance. | ||||
| Multi-GPU (SP) | --num-gpus N --ulysses-degree N | Sequence parallelism across GPUs. Shards sequence tokens (not frames) to minimize padding. | Near-linear scaling with N GPUs | Requires NCCL; inter-GPU bandwidth matters. ulysses_degree * ring_degree = sp_degree. For Wan2.2 video, start by benchmarking pure Ulysses before assuming a mixed Ulysses/Ring layout is fastest. | ||||
| Cross-node SP | --nnodes, --node-rank, --dist-init-addr with total --num-gpus; combine node-local Ulysses with cross-node Ring | Extends sequence parallel groups across multiple nodes. | Capacity and long-sequence scaling beyond one host | Prefer Ulysses within a node and Ring across nodes; all-to-all is usually the least cross-node-friendly. Use --encoder-parallel replicate today and verify the model's Ring admission and determinism. MiniMax-H3 is the current end-to-end validated recipe. | ||||
| CFG Parallel | --enable-cfg-parallel | Runs conditional and unconditional CFG branches in parallel across GPUs. For CFG models on multi-GPU, benchmark this against pure Ulysses on your topology instead of assuming one always wins. | Often faster than pure SP for CFG models | Requires num_gpus >= 2. Halves the Ulysses group size (e.g. 8 GPU → two 4-GPU groups). Only for models that use CFG. Nightly coverage configs may intentionally use smaller Ulysses groups to keep ring behavior exercised; that does not automatically make them the lowest-latency choice. | ||||
| Layerwise Offload | --dit-layerwise-offload | Async layer-by-layer H2D prefetch with compute overlap. Only ~2 DiT layers reside on GPU at a time, dramatically reducing VRAM. For some video models the copy stream can be almost fully hidden behind compute. | Saves VRAM (40 GB → ~11 GB for Wan A14B); can be near-zero speed cost on the right workload | Enabled by default for Wan/MOVA video models. Compatible with Cache-DiT (skipped blocks are not streamed). For image models or highly parallelized setups (many GPUs, small per-GPU compute), the copy stream may not be fully hidden and can cause slowdown. | ||||
| Offload Prefetch Size | --dit-offload-prefetch-size F | Fine-grained control over layerwise offload: how many layers to prefetch ahead. 0.0 = 1 layer (min VRAM), 0.1 = 10% of layers, ≥1 = absolute layer count. | Tune for cases where default offload has copy stream interference (e.g. image models). 0.05–0.1 is a good starting point. | Values ≥ 0.5 approach no-offload VRAM with worse performance. Use lower values when copy overlap is weak; disable offload when memory allows and latency dominates. | ||||
| FSDP Inference | --use-fsdp-inference | Uses PyTorch FSDP to shard model weights across GPUs with prefetch. Low latency, low VRAM. | Reduces per-GPU VRAM | Mutually exclusive with --dit-layerwise-offload. More overhead than SP on high-bandwidth interconnects. | ||||
| CPU Offload (components) | --text-encoder-cpu-offload, --image-encoder-cpu-offload, --vae-cpu-offload, --dit-cpu-offload | Offloads specific pipeline components to CPU when not in use. | Reduces peak VRAM | Adds H2D transfer latency when the component is needed. Auto-enabled for low-VRAM GPUs (<30 GB). Tip: after the first request completes, the console prints a peak VRAM analysis with suggestions on which offload flags can be safely disabled — look for the "Components that could stay resident" log line. | ||||
| Pin CPU Memory | --pin-cpu-memory | Uses pinned (page-locked) memory for CPU offload transfers. | Faster H2D transfers | Slightly higher host memory usage. Enabled by default; disable only as workaround for CUDA errors. | ||||
| Attention Backend (lossless) | --attention-backend fa | Selects a lossless attention kernel for SGLang-native pipelines: fa (FlashAttention 2/3/4 alias) or torch_sdpa. | FA is usually faster than SDPA on long sequences | FA requires compatible GPU (Ampere+). For --backend diffusers, valid backend names differ; use the names documented in docs/docs/sglang-diffusion/attention_backends.mdx. | ||||
| Parallel Folding | (automatic when SP > 1) | Reuses the SP process group as TP for the T5 text encoder, so text encoding is parallelized "for free". | Faster text encoding on multi-GPU | Automatic; no user action needed. Only applies to T5-based pipelines. |
Choosing what goes in --layerwise-offload-components
Layerwise offload pays one H2D of a component's weights per pass over that component, overlapped with that pass's compute. So the question is not how big the component is, it is how many passes per request it makes — counted from the code, not from the pipeline diagram:
| Component | Passes per request | Placement | |
|---|---|---|---|
| DiT | one per denoising step | Stream it. The transfer amortizes over every step and hides behind attention/FFN. | |
| Video VAE | one per temporal chunk, not one | Declare it streamed and keep its blocks resident. | |
| Text / image encoder | one | Resident if it fits; otherwise streamed with its blocks resident. | |
| Vocab table | a gather, one row per token | Neither. Declare it in host_resident_table_names and leave it in host memory. |
"One-shot" is a property of the code, not of the diagram. _decode_temporal_streaming in runtime/models/vaes/minimax_h3_video_vae/klvae.py calls the whole video decoder once per temporal chunk, so streaming its 36 blocks pays 36 block transfers per chunk. On MiniMax-H3 at 864x480 / 124 frames that is 150 s of decode against 13 s with the blocks held.
There are three placements, not two. A component can be declared streamed and still hold its blocks:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingsglang/python/sglang/multimodal_gen/.claude/skills/sglang-diffusion-performance/SKILL.md
Popularity
- Repository stars
- 123
- Repository forks
- 19
- 7-day trend score
- 23
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/rh-runninghub/minimax-h3-multigpu-lightning/sglang-diffusion-performance)