Open-Sora: Democratizing Efficient Video Production for All
Python
debug
shenchenhui41f7b9b01eb1
diff --git a/opensora/models/vae/vae_3d.py b/opensora/models/vae/vae_3d.pyindex 8bdce80..f896a35 100644--- a/opensora/models/vae/vae_3d.py+++ b/opensora/models/vae/vae_3d.py@@ -33,6 +33,7 @@ class ResBlock(nn.Module):activation_fn=nn.ReLU,use_conv_shortcut=False,num_groups=32,+ device="cpu",):super().__init__()self.filters = filters@@ -41,9 +42,9 @@ class ResBlock(nn.Module):self.use_conv_shortcut = use_conv_shortcut# SCH: MAGVIT uses GroupNorm by default- self.norm1 = nn.GroupNorm(num_groups, in_out_channels, dtype=dtype)+ self.norm1 = nn.GroupNorm(num_groups, in_out_channels, dtype=dtype, device=device)self.conv1 = conv_fn(in_out_channels, self.filters, kernel_size=(3, 3, 3), bias=False)- self.norm2 = nn.GroupNorm(num_groups, self.filters, dtype=dtype)+ self.norm2 = nn.GroupNorm(num_groups, self.filters, dtype=dtype, device=device)self.conv2 = conv_fn(self.filters, self.filters, kernel_size=(3, 3, 3), bias=False)if self.use_conv_shortcut:self.conv3 = conv_fn(self.filters, self.filters, kernel_size=(3, 3, 3), bias=False)@@ -88,6 +89,7 @@ class Encoder(nn.Module):custom_conv_padding = None,activation_fn = 'swish',dtype=torch.bfloat16,+ device="cpu",):super().__init__()self.dtype = dtype@@ -132,6 +134,7 @@ class Encoder(nn.Module):activation_fn=self.activation_fn,use_conv_shortcut=False,num_groups=self.num_groups,+ device=device,)self.conv1 = self.conv_fn(in_out_channels, self.filters, kernel_size=(3, 3, 3), bias=False)@@ -170,7 +173,7 @@ class Encoder(nn.Module):prev_filters = filters # update in_channels# MAGVIT uses Group Normalization- self.norm1 = nn.GroupNorm(self.num_groups, prev_filters, dtype=dtype) # SCH: separate <prev_filters> channels into 32 groups+ self.norm1 = nn.GroupNorm(self.num_groups, prev_filters, dtype=dtype, device=device) # SCH: separate <prev_filters> channels into 32 groupsself.conv2 = self.conv_fn(prev_filters, self.embedding_dim, kernel_size=(1, 1, 1))@@ -213,6 +216,7 @@ class Decoder(nn.Module):custom_conv_padding = None,activation_fn = 'swish',dtype=torch.bfloat16,+ device="cpu",):super().__init__()self.output_dim = in_out_channels@@ -260,6 +264,7 @@ class Decoder(nn.Module):activation_fn=self.activation_fn,use_conv_shortcut=False,num_groups=self.num_groups,+ device=device,)self.num_blocks = len(self.channel_multipliers)@@ -308,7 +313,7 @@ class Decoder(nn.Module):else:raise NotImplementedError(f'Unknown upsampler: {self.upsample}')- self.norm1 = nn.GroupNorm(self.num_groups, prev_filters, dtype=dtype)+ self.norm1 = nn.GroupNorm(self.num_groups, prev_filters, dtype=dtype, device=device)self.conv2 = self.conv_fn(prev_filters, self.output_dim, kernel_size=(3, 3, 3))@@ -362,6 +367,7 @@ class VAE_3D(nn.Module):kl_embed_dim = 64,kl_weight = 0.000001,dtype=torch.bfloat16,+ device="cpu",# precision: Any = jax.lax.Precision.DEFAULT):super().__init__()@@ -384,7 +390,8 @@ class VAE_3D(nn.Module):conv_downsample = conv_downsample,custom_conv_padding = custom_conv_padding,activation_fn = activation_fn,- dtype=dtype+ dtype=dtype,+ device=device,)self.decoder = Decoder(latent_embed_dim = latent_embed_dim,@@ -398,6 +405,7 @@ class VAE_3D(nn.Module):custom_conv_padding = custom_conv_padding,activation_fn = activation_fn,dtype=dtype,+ device=device,)# self.loss = model_utils.VEA3DLoss(kl_weight=kl_weight)diff --git a/scripts/train-vae.py b/scripts/train-vae.pyindex d9d36e2..c26cd25 100644--- a/scripts/train-vae.py+++ b/scripts/train-vae.py@@ -131,7 +131,7 @@ def main():# 4. build model# ======================================================# 4.1. build model- vae = build_module(cfg.model, MODELS)+ vae = build_module(cfg.model, MODELS, device=device)vae_numel, vae_numel_trainable = get_model_numel(vae)logger.info(f"Trainable vae params: {format_numel_str(vae_numel_trainable)}, Total model params: {format_numel_str(vae_numel)}"@@ -207,8 +207,8 @@ def main():# loss = vae.get_loss(x)loss_function = VEA3DLoss(kl_weight=cfg.model.kl_weight).to(device, dtype)- reconstructions, posterior = vae(x)breakpoint()+ reconstructions, posterior = vae(x)loss = loss_function(batch, reconstructions, posterior)# Backward & update