Repository navigation
Studio Mac: keep the Qwen-Image VAE causal conv zero-pad patch on MPS - #19616
Conversation
QwenImageCausalConv3d (Qwen-Image, Krea-2, Anima VAEs) has the same 6-tuple causal padding and F.pad forward as WanCausalConv3d, so it takes the same zero-buffer forward on MPS. The single-frame speed pass bound its own forward over it and fell back to the class forward, which discarded the zero-buffer patch; its fallback now calls the forward bound before it. macos-15 (M1, 7.9 GiB cap), Qwen-Image VAE 512^2 decode x20, fresh process per arm: stock ran out of MPS memory in 1 of 3 runs on torch 2.13 and 3 of 3 on 2.14.1, and its driver memory reached 7.7-8.1 GiB; the zero-buffer forward stayed at 4.39 / 4.28 GiB, byte-identical output to stock, 8.2-8.5 vs 10.5-12.2 s per decode on 2.13.
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 |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
[skip ci]
…only Multi-frame and cached calls keep the stock forward: only the one-frame, no-cache image path was measured on MPS. Adds CPU routing tests and an MPS-only decode check against CPU. [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! 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". |
Summary
On MPS before torch 2.15, a 5-D
F.padcosts far more driver memory than the conv it feeds. #18932 fixed this for Wan'sWanCausalConv3dby padding into a zero buffer.QwenImageCausalConv3d, used by the Qwen-Image VAE (Qwen-Image, Krea-2, Anima), has the same 6-tuple causal_paddingand the sameF.padforward, but was not covered.This change:
QwenImageCausalConv3dto_CAUSAL_PAD_CLASSES, so it takes the same zero-buffer forward on MPS, but only on one-frame calls without a cache. That is the call shape every image encode and decode makes, and the one measured below. Multi-frame and cached calls keep the stock forward, since their MPS numerics through the zero buffer are not established (see Not covered).diffusion_vae_single_frame). It runs after the MPS pad fix and binds its own forward on every causal conv. On every call it did not take itself (tiled decodes, more than one frame, a cache), it fell back to the classforward, the stockF.pad. That silently discarded the zero-buffer patch, so adding the class alone would have done nothing on speed-on loads. The fallback now calls the forward that was bound before it, if there is one.Other devices are untouched:
install_frame_pad_fixreturns early off MPS.Measurements
GitHub macos-15 runner (M1, MPS cap 7.93 GiB):
Qwen/Qwen-Imagevae/, the Krea-2 VAE), fp32.Every patched run patched all 61 causal convs.
Tests
tests/test_diffusion_mps_qwen_causal_pad.py(CPU) checks the following:test_diffusion_device.pyandtest_diffusion_vae_single_frame.pypass (113 passed, 1 skipped).Not covered
QwenImage21CausalConv3d(a Conv2d with 4-D padding) is not covered. Only 5-D pads were measured.