unsloth/scripts
Daniel Han d58141b611 perf(video): generalize round-2 levers to Wan2.2 and LTX-2: per-family step cache, per-expert MagCache, TE quant audit
Extends the HunyuanVideo-1.5 round-1/2 optimization levers to wan2.2-ti2v-5b,
wan2.2-t2v-a14b (dual-expert MoE) and ltx-2, shipping only what beats the
incumbent on the measured accuracy-speed frontier (B200, LPIPS(AlexNet)
pairwise vs the same uncached compiled stack at identical seed/settings).

- Wan2.2-TI2V-5B auto step cache switches FBCache to calibrated MagCache:
  balanced (0.12, 3, 0.2) measures 1.65x at pairwise LPIPS 0.034 vs the
  incumbent FBCache 0.08 at 1.49x/0.031, and 1.73x/0.044 vs 1.71x/0.083 at
  the fast points (FBCache error grows unboundedly past its threshold while
  MagCache's budget caps it). A 50-step calibrated curve ships; cond/uncond
  branches agree within 0.0008 so one curve serves both CFG contexts.
- Per-expert MagCache plumbing for dual-expert MoEs: the experts split the
  schedule at the boundary timestep (Wan2.2-A14B: 16 + 34 of 50) and the hook
  counts each expert's own forwards from 0, so a shared full-schedule curve
  would be misaligned for both. apply_step_cache / maybe_toggle_step_cache /
  the loader now thread an expert name; a second expert resolves
  family::transformer_2 curves and sub-curves scale their configured step
  count by steps/50. Single-DiT behaviour unchanged.
- Wan2.2-A14B keeps FBCache: with per-expert curves, FBCache 0.12 at
  2.88x/0.128 dominates balanced MagCache (1.80x/0.145) and FBCache 0.08 sits
  at 1.28x/0.098; the 16-step high-noise expert starves MagCache's skip
  budget. No calibrated curve ships, so an explicit magcache request runs
  uncached with a warning instead of engaging a measured-worse mode.
- Wan2.2-A14B TE auto quant resolves dense: TE fp8_dynamic alone costs
  pairwise LPIPS 0.1195 for a 1.03x once-per-generation encode (146.7 to
  142.7 s e2e). Wan2.2-TI2V-5B shares the UMT5 encoder but stays quantized
  (0.0396 pairwise at a real 1.09x on its much faster DiT).
- LTX-2 TE fp8_dynamic family-denied: torchao per-row compute fp8 on the
  Gemma3-27B encoder black-frames the whole clip (mean luma 137.9 to 0.0,
  LPIPS 0.78; reproduced compiled and eager), while layerwise fp8 is
  near-lossless (pairwise 0.0043) at the same shrink, so auto falls through
  to it and explicit fp8_dynamic requests are refused.
- LTX-2 step caching deliberately stays unregistered, now documented on
  _EXTRA_BLOCK_METADATA: the block returns a joint (video, audio) stream pair
  and both cache hook families would substitute text embeddings into the
  audio slot on every skipped step; a dual-stream cache is required, and the
  distilled checkpoints run below FBCACHE_MIN_STEPS anyway.
- Compile parity (emulate_precision_casts) verified family-neutral and kept
  global: wan5b 1.75x/0.0029 on vs 1.54x/0.0082 off; ltx2 1.308x/0.0013 vs
  1.307x/0.0025; a14b 2711 vs 2717 ms/step. Cache-hook compile arming
  verified to generalize (wan5b fb@0.04 armed 1.216x vs raw 1.048x). Dual-GPU
  CFG stays HunyuanVideo-1.5-only: LTX-2 runs batch-CFG in one forward and
  the Wan pipelines consume each branch inline with no guider combine hook.
- video_speedmem_bench gains epc_off (compile-parity isolation) and
  fbcache_explicit / magcache_explicit configs plus expert-aware cache
  application mirroring the loader.

Measured via scripts/video_speedmem_bench.py and the round-3 single-load
probes; full data and per-family decision table in
outputs/video_families_optim_round3.md (workspace). Tests: 235 passing across
the five video inference suite files (9 new: per-expert curve resolution and
step scaling, uncalibrated-expert refusal, toggle expert threading, wan5b
magcache auto load/toggle, ltx2 deny auto+explicit, a14b TE auto-dense);
ruff clean.
2026-07-10 17:17:48 +00:00
..
data CI: scope GITHUB_TOKEN permissions, add MLX CI, unblock ~60 skipped tests (#5312) 2026-05-11 03:19:13 -07:00
build_prequant_checkpoint.py Restore fp8 DiT quant for Wan video via a per-family embedder exclude 2026-07-08 23:22:34 +00:00
check_frontend_dep_removal.py Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
check_new_install_scripts.py Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
compare_engines.py Studio diffusion (Phase 7): accuracy-preserving speed pass (2.2x via GGUF compile) (#6690) 2026-07-01 15:31:50 -03:00
compile_probe.py Studio diffusion (Phase 7): accuracy-preserving speed pass (2.2x via GGUF compile) (#6690) 2026-07-01 15:31:50 -03:00
diffusion_bench.py Studio diffusion (Phase 8): opt-in fast transformer (torchao int8/fp8/fp4 on a dense source) (#6694) 2026-07-01 15:36:43 -03:00
diffusion_quality.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2026-07-02 03:30:16 +00:00
enforce_kwargs_spacing.py Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
fbcache_flux_probe.py Studio diffusion (Phase 12): First-Block-Cache step caching for many-step DiT (#6703) 2026-07-01 15:40:52 -03:00
fp8_layer_ablation.py fix(review): portable bench scripts, accurate VAE auto docs, explicit TE deny 2026-07-10 06:13:48 +00:00
fp8_overflow_check.py Studio diffusion (Phase 8): opt-in fast transformer (torchao int8/fp8/fp4 on a dense source) (#6694) 2026-07-01 15:36:43 -03:00
hunyuan_attn_diag.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2026-07-09 06:13:22 +00:00
hunyuan_int8_profile.py fix(review): portable bench scripts, accurate VAE auto docs, explicit TE deny 2026-07-10 06:13:48 +00:00
hunyuan_trim_e2e.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2026-07-09 06:13:22 +00:00
hunyuan_trim_fp32ref.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2026-07-09 06:13:22 +00:00
hunyuan_trim_validate.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2026-07-09 06:13:22 +00:00
install_gemma4_mlx.sh Update Install Scripts (#5968) 2026-06-03 05:39:42 -07:00
install_qwen3_6_mlx.sh Update Install Scripts (#5968) 2026-06-03 05:39:42 -07:00
install_rocm_wsl_strixhalo.sh ROCm-on-WSL: support discrete Radeon (RDNA 3/4) in WSL, not just Strix Halo (#6915) 2026-07-07 02:29:37 -07:00
int8_linear_probe.py Studio diffusion (Phase 14): fix int8 dense quant on Flux / Qwen (skip M=1 modulation linears) (#6716) 2026-07-01 15:41:49 -03:00
leverage_probe.py Studio diffusion (Phase 7): accuracy-preserving speed pass (2.2x via GGUF compile) (#6690) 2026-07-01 15:31:50 -03:00
lint_workflow_triggers.py Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
lockfile_supply_chain_audit.py Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
notebook_to_python.py Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
notebook_validator.py Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
nvfp4_probe.py Studio diffusion (Phase 8): opt-in fast transformer (torchao int8/fp8/fp4 on a dense source) (#6694) 2026-07-01 15:36:43 -03:00
nvfp4_t211_probe.py Fix diffusion training validation, dataset upload atomicity, and LoRA error mapping 2026-07-04 03:17:12 -03:00
perf_levers_probe.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2026-07-02 03:30:16 +00:00
perf_verify.py Studio diffusion (Phase 7): accuracy-preserving speed pass (2.2x via GGUF compile) (#6690) 2026-07-01 15:31:50 -03:00
prequant_probe.py Studio diffusion (Phase 9): pre-quantized transformer loading (#6700) 2026-07-01 15:37:53 -03:00
quant_accuracy_sweep.py fix(review): portable bench scripts, accurate VAE auto docs, explicit TE deny 2026-07-10 06:13:48 +00:00
quant_probe.py Studio diffusion (Phase 8): opt-in fast transformer (torchao int8/fp8/fp4 on a dense source) (#6694) 2026-07-01 15:36:43 -03:00
quant_speedmem_bench.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2026-07-10 07:12:36 +00:00
run_ruff_format.py Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
scan_npm_packages.py scan_packages: key baseline on matched-code hash so payloads in baselined files are not auto-suppressed (#6552) 2026-07-01 04:03:59 -07:00
scan_npm_packages_baseline.json scan_packages: key baseline on matched-code hash so payloads in baselined files are not auto-suppressed (#6552) 2026-07-01 04:03:59 -07:00
scan_packages.py CI: baseline the fastapi/gguf scan findings for the studio dependency set 2026-07-02 02:04:28 +00:00
scan_packages_baseline.json Merge remote-tracking branch 'origin/main' into fold-integration 2026-07-07 05:52:16 +00:00
sd_cpp_smoke.py Studio diffusion (Phase 6): img2img / inpaint / edit / LoRA / upscale on the native engine (#6680) 2026-07-01 15:18:38 -03:00
sdpa_mask_backend_probe.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2026-07-09 06:13:22 +00:00
sparse_accum_probe.py Fix diffusion training validation, dataset upload atomicity, and LoRA error mapping 2026-07-04 03:17:12 -03:00
stamp_studio_release.py Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
sync_allow_scripts_pins.py Studio: auto-sync allowScripts pins after dependency bumps (#6136) 2026-06-10 02:35:37 -07:00
uninstall.ps1 Merge image-generation bug fixes (#6872) 2026-07-07 16:14:06 +00:00
uninstall.sh Keep an unowned default-mode sd.cpp checkout on uninstall 2026-07-07 10:22:40 +00:00
verify_comment_only_diff.py Reduce and tighten code comments and docstrings repo-wide (#6095) 2026-06-08 23:09:51 -07:00
verify_import_hoist.py studio: tool calling for DeepSeek (R1/V3/V3.1), GLM 4.x, Kimi K2 on safetensors + MLX (#5624) 2026-07-06 15:40:46 -07:00
verify_prequant_backend.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2026-07-02 03:30:16 +00:00
video_quality.py Fail video quality gate on candidate frame-count mismatch 2026-07-05 07:46:42 +00:00
video_speedmem_bench.py perf(video): generalize round-2 levers to Wan2.2 and LTX-2: per-family step cache, per-expert MagCache, TE quant audit 2026-07-10 17:17:48 +00:00