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.
This commit is contained in:
octo-patch 2026-04-13 12:39:51 +08:00
parent c2657d5fb9
commit ce6b8b72de

View File

@ -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):