Reduce auto temporal tile size to 32f: avoids silent Metal conv2d corruption (gray-frame decodes) - #47
Open
kayadibi1 wants to merge 1 commit into
Open
Conversation
…v2d corruption With 512px spatial tiles, 64-frame temporal tiles push the Wan VAE Resample Conv2d input past ~2e9 elements, where MLX's Metal conv2d silently returns all-zero output (ml-explore/mlx#3979). Affected tiles decode as flat gray with no error raised anywhere. 32-frame tiles keep every conv input under the threshold. Validated against untiled ground truth on a 41-frame roundtrip (mean abs diff 4e-4, blend-zone noise only) and end-to-end on 81f 768x512 / 512x768 Wan 2.2 I2V renders (no gray regions, no seams). Cost: ~2x temporal tile count, decode 136s -> ~205s for 81f 768x512 on an M5 Pro 48GB. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Decoding Wan 2.1/2.2 videos at common sizes (e.g. 81 frames, 768x512) with the current auto tiling (spatial 512px / temporal 64f) produces flat gray output for the regions covered by large tiles — no exception, no warning. Smaller edge tiles decode correctly, so it presents as a blending bug: gray for the first ~40 frames and the left ~450px of every frame, content fading in near tile overlaps.
Root cause (isolated, not guessed)
MLX's Metal conv2d silently returns all zeros for large batched inputs — filed with a 30-line standalone repro as ml-explore/mlx#3979. At C_in=192 it breaks between 1.61e9 and 2.01e9 input elements (C_in=128 is still correct at 3.22e9, so it's a channel-dependent kernel path).
The Wan VAE hits it inside
Resample: frames are folded into batch ([B*T, H, W, C]) before the spatial-upsample Conv2d. With 64-frame temporal tiles at 512px spatial tiles, the 192→96 upsample stage receives[64, 512, 512, 192]= 3.2e9 elements → zeros. A layer bisect (real weights, random latents) shows activation std collapsing from 3.44 to 0.02 at exactly that stage.Change
TilingConfig.auto: temporal tiles 64 → 32 frames (overlap unchanged). Every conv input stays under the threshold.Validation
TilingConfig.default()still uses 64f — happy to change it too if you prefer;autois whatgenerateuses. Longer term, tile sizes could be computed dynamically to keep each Resample conv input under a safe element budget until the MLX kernel is fixed.🤖 Generated with Claude Code