Repository navigation
Studio video: load the dense FastWan students with a 3-step DMD sampler - #18779
Conversation
…pler The dense-attention FastWan2.2 5B student loads as the Wan2.2 TI2V 5B family instead of being refused with the sparse-attention FastWan releases. A DMD scheduler swapped in for the render samples its trained timesteps (1000, 757, 522) at CFG 1: predict x0 from the flow output, re-noise to the next level with seeded CPU noise, return x0 at the end. The stock Wan loop, step callback, compile, graphs and quant paths run unchanged. Defaults are 3 steps at CFG 1, and the hosted base prequant never stands in for the student's weights.
Sampled with dense attention, the 1.3B student matches the 30-step Wan2.1 1.3B base on CLIP-T and PickScore over 8 prompts (L4), at 3 transformer calls instead of 60. It loads as the Wan2.1 T2V 1.3B family with the same 3-step DMD recipe. GGUF and single-file FastWan copies and the 14B / QAD / sparse releases stay refused.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c7dd7191a1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| noise = torch.randn( | ||
| tuple(sample.shape), generator = self._dmd_generator, dtype = torch.float32 | ||
| ).to(sample.device) |
There was a problem hiding this comment.
Use an independent noise stream for DMD re-noising
For CPU and MPS renders, VideoBackend.generate creates a CPU generator seeded with the request seed, and WanPipeline.prepare_latents draws the initial float32 latent noise from it. This scheduler independently resets another CPU generator to that same seed, so its first re-noising draw, with the same shape and dtype, exactly repeats the initial latent noise instead of providing fresh independent noise. That changes the DMD sampling distribution and can degrade generated results on these devices; the CUDA benchmark does not exercise this case. Continue the pipeline generator's stream or seed a separate re-noising stream independently, while retaining deterministic resets for retries.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in the latest commit. The DMD re-noise generator is now seeded from a hash of the request seed, so it stays deterministic per request (an OOM retry redraws the same noise) but never repeats the initial latent stream. The new test shows the old code's first re-noise draw equals the initial noise exactly for seeds 0, 7, 42 and 2^31-1, and that the new draw is uncorrelated.
…atent On CPU / MPS the pipeline draws the initial latent from a CPU generator seeded with the request seed, and the DMD scheduler seeded its own CPU generator with the same seed, so the first re-noise draw (same shape and dtype) repeated the initial noise exactly. The re-noise stream is now seeded from a hash of the request seed: still deterministic per request (an OOM retry redraws the same noise), never the same stream. [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…keys, no hosted base denoiser - dmd_timesteps reads model_identity(), as family detection and the defaults table do, so a student opened from its HF cache snapshot gets the DMD sampler instead of 3 stock UniPC steps. - The defaults table names the two students exactly; a FastWan-named file with no DMD recipe keeps its family's defaults. - denoiser_prequant_sources returns None for any DMD student id (copies, re-uploads, local paths), not only the FastVideo repo, so no student load takes the base model's hosted denoiser.
…usal points to [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…p dunders spreading the decode-rewrap scan (#18815) ## Problem `(Python 3.13, diffusion)` fails on `main` and on every PR based on it (for example #18806) with two failures: ``` test_diffusion_family_data_freeze.py::test_family_data_resolves_identically AssertionError: tables test_diffusion_vae_oom.py::test_every_decode_rewrap_site_restores_the_oom_scope 510 sites flagged, first ('diffusion.py', 'DiffusionBackend.__init__') ``` Both reproduce locally on `main` (`d8ff4de6a1`). Running both tests on each Studio inference commit since the last green `main` attributes them: | commit | freeze | decode rewrap | |---|---|---| | `8d41610c50` (#18800) | pass | pass | | `d66aa77cee` (#18779) | fail | pass | | `6f4c2a7bd9` (#18780) | fail | fail | ## Causes **Family data freeze (#18779).** #18779 adds the dense FastWan students as trusted video repos. The frozen table was not regenerated, so the only difference is two new `trusted_video_repos` entries, `fastvideo/fastwan2.1-t2v-1.3b-diffusers` and `fastvideo/fastwan2.2-ti2v-5b-fullattn-diffusers`. The PR is right; the fixture is behind. **Decode-rewrap scan (#18780).** The test seeds every function that assigns `.decode`, then marks any function that calls one of those *by bare name* as a rewrap helper too, to a fixpoint. #18780's opt-in draft decode is a context manager, `TinyVaeDraftDecode`, which swaps `vae.decode` in `__enter__` and restores it in `__exit__`. That made `__enter__` and `__exit__` seeds, and a bare-name match on `__exit__` / `__enter__` reaches every function that drives any context manager by hand, so the fixpoint spread to 510 functions. The draft swap itself is scoped and restores the previous `decode` on exit, and its fallback calls the decode it replaced, so the OOM scope is intact. The PR is right; the scan's name matching is too loose for dunders. ## Fix Test-only: - `tests/fixtures/diffusion_family_data_freeze.json`: regenerated with `UNSLOTH_FREEZE_UPDATE=1`. The diff is exactly the two FastWan repos (2 lines added). - `test_every_decode_rewrap_site_restores_the_oom_scope`: dunder method names are not propagated by name. A dunder is reached through `with` or an object protocol, never by a call to that name, so matching it by name cannot identify a caller. Named helpers such as `install_untiled_decode` still propagate as before. ## Verification - `test_diffusion_family_data_freeze.py`, `test_diffusion_vae_oom.py`, `test_video_tiny_vae.py`, `test_video_tiny_vae_wiring.py`: 134 passed, 5 skipped. - Sabotage: adding `def _sabotage_leak(vae): install_untiled_decode(vae)` to `video.py` fails the rewrap test with `[('video.py', '_sabotage_leak')]`, so a real unguarded rewrap is still caught. Restored afterwards. - The freeze fails on `main` without the regenerated fixture, as on CI.
…DMD diffusers skip, risky loader lint) (#18824) ## Summary Four checks are red on `main` itself, so every open PR currently inherits them in the Backend CI shards and the risky loader lint. Each was reproduced on a clean `main` checkout before fixing. | Failing check | Introduced by | Which side was wrong | Fix | |---|---|---|---| | `tests/test_diffusion_rocm_tag_detect.py::test_no_diffusion_or_video_gate_reads_version_hip_directly` | #18793 (`diffusion_regional_compile.py`) and #18792 (`diffusion_vae_strips.py`) | Code. Both new gates read `torch.version.hip` directly, which the ROCm tag guard exists to forbid (a CUDA wheel with a stray `hip` attribute, or a ROCm wheel reporting it differently, takes the wrong branch). | Route both through the shared `is_rocm_torch(torch)` helper from `rocm_bf16`. Behaviour on CUDA and ROCm is unchanged. | | `tests/test_h3_quantised_offload.py::test_a_streamed_torchao_render_runs_under_no_grad_and_the_rest_keep_inference_mode` | #18780 added `draft_ctx` to the denoise `with` | Test. The invariant (the denoise loop enters `grad_ctx` together with its progress context) still holds; the test pinned one exact spelling of the `with` line. | Parse the `with` statements and assert `grad_ctx` and `progress_ctx()` are entered together, regardless of what other contexts join them. Verified it still fails when `grad_ctx` is dropped from the statement. | | `tests/test_video_dmd.py::test_dmd_scheduler_reseeds_per_render`, `::test_renoise_stream_is_independent_of_the_initial_latent_noise` | #18779 | Test. `make_dmd_scheduler` builds on a diffusers scheduler, but these two tests only skipped on missing torch, so they error with `No module named 'diffusers'` in the shard that runs without diffusers. | `pytest.importorskip("diffusers")`, matching the existing scheduler test in the same file. | | `scripts/lint_risky_loaders.py` (`diffusion_ddp.py:440 [dynamic-import] __import__`) | #18771 | Code. The rank bootstrap imported two fixed modules through `__import__` in a loop. | Import `utils.native_tls` and `utils.happy_eyeballs` by name, each in its own `try`, so a failure in one still does not stop the rank or skip the other. No baseline entry needed. | ## Testing - `tests/test_diffusion_rocm_tag_detect.py`, `tests/test_h3_quantised_offload.py`, `tests/test_video_dmd.py`, `tests/test_diffusion_ddp.py`, `tests/test_diffusion_training.py`, the native TLS and happy eyeballs suites, and the regional compile and VAE strip suites: all pass. - `tests/test_video_dmd.py` with diffusers blocked from import: 26 passed, 7 skipped (previously 2 errors). - `python scripts/lint_risky_loaders.py`: all call sites recorded. - Sabotage: restoring either original `torch.version.hip` read makes the ROCm tag guard fail; restoring the `__import__` loop makes the risky loader lint fail.
Studio refused every FastVideo FastWan checkpoint by name, on the grounds that FastWan needs FastVideo's few-step sampler and sparse attention. That is true for the sparse-attention releases, but FastWan2.2-TI2V-5B-FullAttn is a plain dense
WanTransformer3DModeldistilled with DMD, and FastWan2.1-T2V-1.3B also samples well with dense attention. The only missing piece was the 3-step DMD sampler.Change
core/inference/video_dmd.py: a DMD scheduler that plugs into the diffusers scheduler interface and is swapped intopipe.schedulerfor one render (always restored). For each trained timestep (1000, 757, 522) it predictsx0 = x_t - sigma_t * v, re-noises to the next level with seeded CPU noise (reseeded per render, so an OOM retry draws the same noise), and returnsx0after the last step. Sigmas are the nearest entries of the 1000-step shift-8 training table (1.0, 28/37, 12/23). The stock Wan pipeline loop, step callback, compile, CUDA graphs, quant and offload paths are unchanged.video.py: when the loaded model is a DMD student, a render runs its trained 3 steps at CFG 1 with no negative prompt (a different request is logged and pinned). A non-Diffusers engine with a student id raises.video_families.py: the FastWan refusal now lets through only the two dense students as Diffusers repos. GGUF / single-file copies, the 14B, QAD and sparse-attention releases stay refused, with a clearer message. The students resolve to the Wan2.2 TI2V 5B and Wan2.1 T2V 1.3B families, defaults are 3 steps at CFG 1, and a newprequant_excluded_baseskeeps the hosted base FP8 / INT8 denoiser from standing in for the student's weights.Results
Colab L4, bf16 DiT, fp32 tiled VAE for every arm, the same prompt embeddings and seed, arms interleaved per prompt, 8 prompts. CLIP-T (ViT-L/14) and PickScore are averaged over the first, middle and last frames. The student arms use this module through the Wan pipeline loop.
The 5B student wins PickScore on all 8 prompts and ties CLIP-T. Its denoise is 13x faster, and end to end it is 2.5x faster at 480p and 3.0x at 720p, where the VAE decode is now most of the time. The 1.3B student ties the base on both metrics at 5.9x end to end. Memory is unchanged. Timing spread within each arm is under 0.3%.
Tests
tests/test_video_dmd.pycovers:WanPipeline.__call__on a tiny random Wan, withexpand_timestepsoff and on, against an fp64 oracle loop: one forward per trained timestep, no CFG branch, scheduler restoredExisting rows in
test_video_wan21_families.pywere updated for the two students. A stale "VideoFamily has no prequant_excluded_bases" assertion intest_diffusion_more_families.pynow checks that the field is empty. The new tests fail on main and pass here, and no existing test regressed.Not proven here
to_gate_compress) that dense attention ignores. diffusers warns and loads, but Studio's own loader was not run on it.Screenshots
BEFORE is the merge base (8b7cde7), AFTER is this branch (c7dd719), each a separate Studio install. No GPU was used.
Live
POST /api/inference/video/download-planresponses from each install, rendered as text. The FastWan name refusal no longer fires for FastWan2.1-T2V-1.3B; the sparse FastWan2.2-TI2V-5B repo stays refused with the narrowed message. At this AFTER head the dense 1.3B Hub repo then stopped at the trusted-repo check; a later commit (2e03390343) trusts both dense student repos, covered bytest_the_dense_students_pass_the_non_gguf_trust_gate.Video page with FastWan2.1-T2V-1.3B resident (each side's own
status()over a stub resident pipeline): Steps / Guidance 30 / 6 before, 3 / 1 after.