Skip to content

Open-Sora: Democratizing Efficient Video Production for All

Python

debug

shenchenhuid927619833c0
diff --git a/opensora/models/vae/model_utils.py b/opensora/models/vae/model_utils.py
index 99454e8..2737fec 100644
--- a/opensora/models/vae/model_utils.py
+++ b/opensora/models/vae/model_utils.py
@@ -81,7 +81,9 @@ class DiagonalGaussianDistribution(object):
self,
parameters,
deterministic=False,
+ dtype=torch.bfloat16,
):
+ self.dtype = dtype
self.parameters = parameters
self.mean, self.logvar = torch.chunk(parameters, 2, dim=1) # SCH: channels dim
self.logvar = torch.clamp(self.logvar, -30.0, 20.0)
@@ -89,10 +91,10 @@ class DiagonalGaussianDistribution(object):
self.std = torch.exp(0.5 * self.logvar)
self.var = torch.exp(self.logvar)
if self.deterministic:
- self.var = self.std = torch.zeros_like(self.mean).to(device=self.parameters.device)
+ self.var = self.std = torch.zeros_like(self.mean).to(device=self.parameters.device, dtype=dtype)
def sample(self):
- x = self.mean + self.std * torch.randn(self.mean.shape).to(device=self.parameters.device)
+ x = self.mean + self.std * torch.randn(self.mean.shape).to(device=self.parameters.device, dtype=self.dtype)
return x
def kl(self, other=None):
diff --git a/opensora/models/vae/vae_3d.py b/opensora/models/vae/vae_3d.py
index 74ae75f..5aea368 100644
--- a/opensora/models/vae/vae_3d.py
+++ b/opensora/models/vae/vae_3d.py
@@ -414,6 +414,7 @@ class VAE_3D(nn.Module):
self.quant_conv = nn.Conv3d(latent_embed_dim, 2*kl_embed_dim, 1, dtype=dtype, device=device)
self.post_quant_conv = nn.Conv3d(kl_embed_dim, latent_embed_dim, 1, dtype=dtype, device=device)
+ self.dtype = dtype
def encode(
self,
@@ -421,7 +422,7 @@ class VAE_3D(nn.Module):
):
encoded_feature = self.encoder(x)
moments = self.quant_conv(encoded_feature)
- posterior = model_utils.DiagonalGaussianDistribution(moments)
+ posterior = model_utils.DiagonalGaussianDistribution(moments, dtype=self.dtype)
return posterior
def decode(