Add decode latent to wan 2.1 models. Add gradinet checkpointing to wan vae.
This commit is contained in:
1 parent
4260a3c5b6
commit
963a9f42b2
2 files changed
+45
-11
No files matched your search
@@ -654,6 +654,31 @@ class Wan21(BaseModel):
|
||||
latents = (latents - latents_mean) * latents_std
|
||||
|
||||
return latents.to(device, dtype=dtype)
|
||||
|
||||
def decode_latents(self, latents: torch.Tensor, device=None, dtype=None):
|
||||
if device is None:
|
||||
device = self.vae_device_torch
|
||||
if dtype is None:
|
||||
dtype = self.vae_torch_dtype
|
||||
|
||||
if self.vae.device == torch.device('cpu'):
|
||||
self.vae.to(device)
|
||||
|
||||
latents = latents.to(device, dtype=dtype)
|
||||
|
||||
latents_mean = (
|
||||
torch.tensor(self.vae.config.latents_mean)
|
||||
.view(1, self.vae.config.z_dim, 1, 1, 1)
|
||||
.to(latents.device, latents.dtype)
|
||||
)
|
||||
latents_std = torch.tensor(self.vae.config.latents_std).view(
|
||||
1, self.vae.config.z_dim, 1, 1, 1
|
||||
).to(latents.device, latents.dtype)
|
||||
latents = latents * latents_std + latents_mean
|
||||
|
||||
images = self.vae.decode(latents).sample
|
||||
|
||||
return images.to(device, dtype=dtype)
|
||||
|
||||
def get_model_has_grad(self):
|
||||
return False
|
||||
|
||||
Reference in new issue
Block a user