Conversation
…#14770) Allocate feat_map and conv_idx locally in _encode, _decode, tiled_encode, and tiled_decode instead of mutating module attributes, and replace mutable default argument feat_idx=[0] with feat_idx=None.
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.
What does this PR do?
Fixes #14770
This PR makes
AutoencoderKLWan(used in Wan2.1 and Wan2.2 models) stateless during execution so that it compiles cleanly withtorch.compilewithout graph breaks or issues from mutating internal module attributes.Key Changes
feat_map = [None] * self._cached_conv_counts[...]locally inside_encode,_decode,tiled_encode, andtiled_decodeand pass it down along with a localconv_idx = [0]list.feat_idx=[0]tofeat_idx=Nonein all residual / up / down / mid blocks.clear_cache()is preserved as a method onAutoencoderKLWanso existing external scripts callingvae.clear_cache()do not break.Verification & Performance
Tested on NVIDIA RTX 4090 (PyTorch 2.11 / CUDA 12.8, BF16, 5 frames 480x640):
max_abs_diff = 0.0(exact bitwise parity with eager baseline).tests/models/autoencoders/test_models_autoencoder_wan.pypass cleanly.84.43 mstorch.compile(mode="default"):61.10 ms(1.38x speedup)torch.compile(mode="max-autotune-no-cudagraphs"):58.38 ms(1.45x speedup)Self-Review Notes
src/diffusers/models/autoencoders/autoencoder_kl_wan.py.ruff checkandruff format.test_tiling_encode_shape,test_tiling_decode_shape).Before submitting
self-reviewskill on the diff?Who can review?
@yiyixuxu @dg845 @asomoza