guqiong96/lsglang/sglang-diffusion-cache-dit
Claude Code and agent skill by guqiong96/lsglang
- community
Checking that the SKILL.md file is still in the repository.
Workflow for upgrading/integrating cache-dit in SGLang diffusion (multimodal_gen): DBCache, DMD calibrator, TaylorSeer, SVDQuant DQ; porting upstream PRs and resolving conflicts against the per-request knob system; adding new cache knobs; building the sglang generate CLI test matrix; precision validation (PSNR / log evidence); troubleshooting environment issues (wheel ABI, svdq extension, flashinfer conflicts). Use when upgrading or integrating cache-dit in sglang diffusion, porting cache-dit P…
Install
npx vskill@latest install guqiong96/lsglang/sglang-diffusion-cache-ditSKILL.md
SGLang Diffusion × Cache-DiT Integration
Path placeholders used throughout: <sglang_dir> = sglang repo root, <cache_dit_dir> = local cache-dit repo root (if not present locally, clone it: git clone https://github.com/vipshop/cache-dit), <flux_model_dir> = the DiT model weights actually under test (if the user has not specified the model, ask for the model name and checkpoint path first — the workflow is not FLUX-specific; FLUX.1-dev is only the reference run), <cuda_home> = CUDA toolkit root (typically /usr/local/cuda), <gpu_id> = a free GPU index.
GATE CHECK (confirm before starting)
Hard rules
- Conflict resolution: keep the target branch's refactored structure (the knob system in §2). If the upstream PR's direct-write style targets code that has since been refactored, re-inject it following the new pattern; never revert the target branch's refactor.
- After touching cache-related modules, run all
test/unit/test_cache_dit*.py(not just one file — a skipped stub test once left a 9/9 ImportError that only surfaced at CLI stage).
1. Integration map (4 files on the sglang side)
| File | Responsibility | |
|---|---|---|
python/pyproject.toml | cache-dit==x.y.z version pin in the diffusion extra | |
python/sglang/multimodal_gen/envs.py | env vars: annotation section + lazy getters + _CACHE_DIT_SECONDARY_CONFIGS + special bool getters | |
python/sglang/multimodal_gen/runtime/cache/cache_dit_integration.py | CacheDitConfig, enable_cache_on_transformer (single/dual transformer), custom BlockAdapter, per-request knob validation set, calibrator construction | |
python/sglang/multimodal_gen/runtime/pipelines_core/stages/denoising.py | _build_cache_dit_config() + _cache_dit_knob() — the single injection point for new cache parameters |
Data flow: env (with secondary fallback) → knob (request > env) → CacheDitConfig fields → mutual-exclusion guard → cache-dit Config (DBCacheConfig / DMDCalibratorConfig / TaylorSeerCalibratorConfig)
Key facts:
- Knob priority: request override (
sampling_params.cache_dit_params) > env; a secondary knob first inherits the request-level primary value, then falls back toSGLANG_CACHE_DIT_SECONDARY_*, then to the primary env default. - A single change in
_build_cache_dit_configautomatically covers both the primary/secondary call sites and the minimax_h3 subclass (its override callssuper()). - Dual-transformer models (wan2.2 etc.) can reuse the primary config wholesale for the secondary transformer (
_cache_dit_secondary_uses_primary_config()); new fields are inherited for free. - The calibrator is a single slot: DMD × TaylorSeer are mutually exclusive;
_assert_calibrator_exclusive(config, label)guards both enable entry points (enabling both raises ValueError).
2. Standard six steps to add a cache knob (DMD as the example)
- envs.py annotation section: add the primary + secondary variables (e.g.
SGLANG_CACHE_DIT_DMD: bool = False). - envs.py getter: non-bool → add a
(SUFFIX, type, default)tuple to_CACHE_DIT_SECONDARY_CONFIGS(auto-generates the secondary fallback); bool → write a dedicated_secondary_xxx_getter(get_bool_env_var(SECONDARY_X, default=os.getenv(PRIMARY_X, "false"))) and register it. - cache_dit_integration.py: add the field to
CacheDitConfig(with docstring and default). - cache_dit_integration.py: add the key to
CACHE_DIT_REQUEST_KNOB_KEYS(symmetric with taylorseer; automatically joins the request/secondary validation sets and the remount detectioncache_dit_overrides_key). - denoising.py: append a knob() entry after taylorseer_order inside
_build_cache_dit_config:
enable_dmd=knob("enable_dmd", envs.SGLANG_CACHE_DIT_DMD, envs.SGLANG_CACHE_DIT_SECONDARY_DMD, secondary=secondary)
- Calibrator/special logic: construct the corresponding cache-dit Config inside
enable_cache_on_transformerandenable_cache_on_dual_transformer(DMD:if enable_dmd: DMDCalibratorConfig(...) elif enable_taylorseer: ...), and add the field to the log format string (placeholder and argument counts must stay aligned).
Conflict forecast when porting an upstream PR: denoising.py always conflicts (the PR's direct envs.XXX → Config construction was refactored away on the target branch) → apply only step 5; cache_dit_integration.py conflicts locally (the per-request knob system added on the target branch sits right next to the PR's insertion points) → keep the target branch's frozenset and append the new keys.
3. Environment setup (dedicated env)
Environment principle (mandatory, top priority): everything — pip installs/uninstalls, source builds, unit tests and CLI runs — happens inside the dedicated env (e.g. conda activate sgl). It is fully isolated from the cache-dit/ffpa dev envs: never install/uninstall packages in other envs, and never let sglang dependency changes (torch, cache-dit, flashinfer, ...) leak into them. If the env does not exist yet, create a dedicated one before continuing — do not reuse any existing env:
(Any other virtualenv mechanism works as well; what matters is dedicated and isolated. After switching envs, confirm versions with pip show sglang cache-dit before testing.)
Other environment pitfalls:
- A stale
flashinfer-cubinthat mismatches the flashinfer main package → blocks every sglang import; if the installed flashinfer has no matching cubin release (e.g. 0.6.18),pip uninstall flashinfer-cubindirectly. - The dedicated env may lack pytest → the test files use
unittest.main()style; runpython <test_file.py>directly. test_cache_dit_integration.pyreplaces the cache_dit module with a stub (no real install required): after changing top-level imports incache_dit_integration.py, sync the stub's top-level symbols in_install_cache_dit_stub()(missing BlockAdapterRegister/Parallelism*/DMDCalibratorConfig once caused 9/9 ImportError).
4. CLI test matrix (reference run: PRO 5000, FLUX.1-dev, 1024×1024, 28 steps)
Nine-case design (backend × acceleration feature combos):
| # | backend | feature | driven by | |
|---|---|---|---|---|
| 1-3 | SGLD (default) | baseline / DBCache / +DMD | env: SGLANG_CACHE_DIT_ENABLED=true (+SGLANG_CACHE_DIT_DMD=true) | |
| 4-6 | diffusers | baseline / DBCache / +DMD | yaml: cache.yaml / cache_dmd.yaml (<cache_dit_dir>/examples/configs/) | |
| 7-9 | diffusers | SVDQ nvfp4 / +compile / +compile+DBCache+DMD | yaml: blackwell/quantize_svdq.yaml / blackwell/cache_dmd_svdq.yaml + --enable-torch-compile |
Common args: --model-path=$FLUX_DIR --log-level=info --prompt='...' --width=1024 --height=1024 --num-inference-steps=28 --warmup-mode request --warmup-steps 1 --dit-cpu-offload false --text-encoder-cpu-offload false --save-output --output-path .tmp/{task}/outputs; compile cases add --warmup-steps 28; the blackwell yaml is already svdq_nvfp4_r128_dq (nvfp4, not int4) — grep to confirm before running.
run_case script pattern (saved as .tmp/{task}/run_matrix.sh):
timeout <1800~3600>guard + stdout redirect tologs/{name}.log+summary.logrecordsPASS/FAIL(dual criteria: rc + png existence) + a failure does not abort the remaining cases.- When several cases fail with a common root cause, fix it and re-run only the failed segment via a small sub-script, not the whole matrix.
- Submit in the background; then do a one-shot health check (
sleep 45-60 && tail -3 logs/<first_case>.log && nvidia-smi -i <gpu_id>) to confirm the model is loading without CLI errors, then stop and wait for the completion notification — never poll. - Save long verification scripts (PSNR / perf extraction) as
.pyfiles; avoid longpython -cone-liners (nested f-strings are error-prone).
Fixed failure-diagnosis order:
- Check
summary.logand whether the output files were produced (EOFError/worker did not terminate gracefully, forcing/ leaked-semaphore lines in the tail are multiprocess shutdown noise, not the failure itself); grep -iE 'error|assert|exception|raise' logs/{case}.log | headto find the first traceback (the real cause is often mid-log, e.g.AssertionError: Quantization backend ... not supported);- Use package-level diagnostics when available (
svdq_is_available()/svdq_get_load_error()).
4.1 Full command reference (battle-tested during the 1.5.1 upgrade; adapt and reuse)
Unit tests + negatives (mandatory after touching cache modules):
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingpython/sglang/multimodal_gen/.agents/skills/sglang-diffusion-cache-dit/SKILL.md
Popularity
- Repository stars
- 155
- Repository forks
- 17
- 7-day trend score
- 0
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/guqiong96/lsglang/sglang-diffusion-cache-dit)