From ce6b8b72de901389f65551f39105347bcf57bf6d Mon Sep 17 00:00:00 2001 From: octo-patch Date: Mon, 13 Apr 2026 12:39:51 +0800 Subject: [PATCH] fix: clone latent before TAESD preview decode to prevent corruption (fixes #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. --- latent_preview.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/latent_preview.py b/latent_preview.py index a9d777661..4d353186a 100644 --- a/latent_preview.py +++ b/latent_preview.py @@ -41,12 +41,14 @@ class TAESDPreviewerImpl(LatentPreviewer): self.taesd = taesd def decode_latent_to_preview(self, x0): - x_sample = self.taesd.decode(x0[:1])[0].movedim(0, 2) + # Clone to prevent the decoder from modifying the latent in-place + x_sample = self.taesd.decode(x0[:1].clone())[0].movedim(0, 2) return preview_to_image(x_sample) class TAEHVPreviewerImpl(TAESDPreviewerImpl): def decode_latent_to_preview(self, x0): - x_sample = self.taesd.decode(x0[:1, :, :1])[0][0] + # Clone to prevent the decoder from modifying the latent in-place + x_sample = self.taesd.decode(x0[:1, :, :1].clone())[0][0] return preview_to_image(x_sample, do_scale=False) class Latent2RGBPreviewer(LatentPreviewer):