Skip to content

Studio video: load the dense FastWan students with a 3-step DMD sampler - #18779

Merged
danielhanchen merged 5 commits into
mainfrom
nov21-distill-dmd
Nov 21, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
nov21-distill-dmd

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

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 WanTransformer3DModel distilled 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

  • New core/inference/video_dmd.py: a DMD scheduler that plugs into the diffusers scheduler interface and is swapped into pipe.scheduler for one render (always restored). For each trained timestep (1000, 757, 522) it predicts x0 = 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 returns x0 after 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 new prequant_excluded_bases keeps 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.

model, shape arm DiT calls wall s denoise s peak GiB CLIP-T PickScore
Wan2.2 5B, 832x480x49 base 20 steps CFG 5 40 103.7 68.4 13.69 29.15 20.13
FastWan 5B FullAttn 3 steps 3 40.7 5.1 13.67 29.17 20.84
Wan2.2 5B, 1280x704x121 (2 prompts) base 40 700.6 507.6 17.80 30.88 20.69
FastWan 5B FullAttn 3 232.0 38.2 17.72 32.02 21.31
Wan2.1 1.3B, 832x480x33 base 30 steps CFG 6 60 138.2 120.9 4.64 28.19 20.56
FastWan2.1 1.3B 3 steps 3 23.3 6.1 4.63 28.12 20.81

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.py covers:

  • detection and defaults for both students
  • the refusals that stay, and the hosted prequant exclusion
  • the sigma table against hand-derived values
  • the real WanPipeline.__call__ on a tiny random Wan, with expand_timesteps off and on, against an fp64 oracle loop: one forward per trained timestep, no CFG branch, scheduler restored

Existing rows in test_video_wan21_families.py were updated for the two students. A stale "VideoFamily has no prequant_excluded_bases" assertion in test_diffusion_more_families.py now checks that the field is empty. The new tests fail on main and pass here, and no existing test regressed.

Not proven here

  • The GPU numbers come from the diffusers pipeline driving this scheduler module, not a full Studio server. Studio compile, CUDA graphs, INT8 quantize-at-load on the student and TI2V image input with the DMD loop were not run on GPU.
  • The 1.3B checkpoint carries VSA gate tensors (to_gate_compress) that dense attention ignores. diffusers warns and loads, but Studio's own loader was not run on it.
  • Quality was checked with automatic metrics on 8 prompts with one seed. There was no blind human A/B and no AMD, Mac or T4 run.

Screenshots

BEFORE is the merge base (8b7cde7), AFTER is this branch (c7dd719), each a separate Studio install. No GPU was used.

FastWan download-plan responses
Live POST /api/inference/video/download-plan responses 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 by test_the_dense_students_pass_the_non_gguf_trust_gate.

Video page Steps and Guidance with FastWan2.1-T2V-1.3B resident
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.

…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T18:42:24.247465Z eede61d Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +139 to +141
noise = torch.randn(
tuple(sample.shape), generator = self._dmd_generator, dtype = torch.float32
).to(sample.device)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 21, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 21, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 2131c8fb22

ℹ️ 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".

…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.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: eede61d5f9

ℹ️ 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".

@danielhanchen
danielhanchen merged commit d66aa77 into main Nov 21, 2026
@danielhanchen
danielhanchen deleted the nov21-distill-dmd branch November 21, 2026 20:38
danielhanchen added a commit that referenced this pull request Nov 21, 2026
…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.
danielhanchen added a commit that referenced this pull request Nov 22, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant