fix: clone latent before TAESD preview decode to prevent corruption#13383
fix: clone latent before TAESD preview decode to prevent corruption#13383octo-patch wants to merge 1 commit intoComfy-Org:masterfrom
Conversation
…ixes Comfy-Org#13366) The TAESD preview decoders (TAESDPreviewerImpl and TAEHVPreviewerImpl) were passing tensor views (slices) of x0 directly to the decoder. This allowed the decoder's internal operations to potentially modify the original latent in-place, corrupting the midsampling latent. The fix clones the sliced tensor before passing it to the decoder, ensuring the original x0 is never affected by any in-place operations within the preview decode path. This specifically addresses the case where lighttaew2_1.safetensors (WanVAE) is used as the TAESD preview decoder for models using the Wan21 latent format (e.g., QwenImage), where the full VAE decode pipeline could write back to the input slice.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe pull request modifies the latent preview decoding implementations in 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #13366
Problem
The TAESD preview decoders (
TAESDPreviewerImplandTAEHVPreviewerImpl) were passing tensor views (slices ofx0) directly to the decoder'sdecode()call. Since these are views (not copies), any in-place operation within the decoder's pipeline could potentially write back through the view and corrupt the originalx0latent mid-sampling.This was specifically observed when:
Wan21latent format (e.g.,QwenImage)lighttaew2_1.safetensors(WanVAE) is present inmodels/vae_approx/In this configuration, the full VAE decode pipeline (including model management, conv operations, and CUDA kernel scheduling) processes the non-contiguous tensor slice, which can result in x0 being modified in-place.
Solution
Clone the tensor slice before passing it to the decoder:
This ensures the original
x0latent is never modified by any operations within the preview decode path, including any potential in-place writes in CUDA kernels or PyTorch operations that may operate directly on the underlying memory of non-contiguous views.Testing