Skip to content

Open-Sora: Democratizing Efficient Video Production for All

Python

debug

shenchenhuib3f2dacc69da
diff --git a/opensora/models/vae/model_utils.py b/opensora/models/vae/model_utils.py
index 7f1de46..a964323 100644
--- a/opensora/models/vae/model_utils.py
+++ b/opensora/models/vae/model_utils.py
@@ -37,43 +37,43 @@ import torch
# x = upsample(x)
# return x
-class Conv(nn.Conv3d):
- """Convolution with custom padding.
-
- Attributes:
- custom_padding: padding mode accepted by jnp.pad. When using this, must set
- padding=VALID to disable padding in nn.Conv.
- """
-
- def __init__(
- self,
- in_channels,
- out_channels,
- kernel_size,
- dtype = "bf16",
- padding = "same",
- use_bias=False,
- custom_padding:Optional[str] = None,
- ):
- super(Conv, self).__init__(in_channels, out_channels, kernel_size, dtype=dtype, padding=padding)
- self.custom_padding = custom_padding
-
- def forward(self, x):
- if self.custom_padding is not None:
- assert self.padding == 'valid', 'Must use valid padding for raw Conv.'
- assert self.dilation == 1, 'Kernel dilation not supported.'
- pads = [((k - 1) // 2, k // 2) for k in self.kernel_size]
- pads = [(0, 0)] + pads + [(0, 0)]
- if self.custom_padding.startswith('reflect_') \
- or self.custom_padding.startswith('symmetric_'):
- custom_padding, reflect_type = self.custom_padding.split('_')
- pad_kwargs = {'reflect_type': reflect_type}
- else:
- custom_padding = self.custom_padding
- pad_kwargs = {}
+# class Conv(nn.Conv3d):
+# """Convolution with custom padding.
+
+# Attributes:
+# custom_padding: padding mode accepted by jnp.pad. When using this, must set
+# padding=VALID to disable padding in nn.Conv.
+# """
+
+# def __init__(
+# self,
+# in_channels,
+# out_channels,
+# kernel_size,
+# dtype = "bf16",
+# padding = "same",
+# use_bias=False,
+# custom_padding:Optional[str] = None,
+# ):
+# super(Conv, self).__init__(in_channels, out_channels, kernel_size, dtype=dtype, padding=padding)
+# self.custom_padding = custom_padding
+
+# def forward(self, x):
+# if self.custom_padding is not None:
+# assert self.padding == 'valid', 'Must use valid padding for raw Conv.'
+# assert self.dilation == 1, 'Kernel dilation not supported.'
+# pads = [((k - 1) // 2, k // 2) for k in self.kernel_size]
+# pads = [(0, 0)] + pads + [(0, 0)]
+# if self.custom_padding.startswith('reflect_') \
+# or self.custom_padding.startswith('symmetric_'):
+# custom_padding, reflect_type = self.custom_padding.split('_')
+# pad_kwargs = {'reflect_type': reflect_type}
+# else:
+# custom_padding = self.custom_padding
+# pad_kwargs = {}
- x = np.pad(x, pads, mode=custom_padding, **pad_kwargs)
- return super(Conv, self).__call__(x)
+# x = np.pad(x, pads, mode=custom_padding, **pad_kwargs)
+# return super(Conv, self).__call__(x)
class DiagonalGaussianDistribution(object):
diff --git a/opensora/models/vae/vae_3d.py b/opensora/models/vae/vae_3d.py
index 9f0badb..cf0ced3 100644
--- a/opensora/models/vae/vae_3d.py
+++ b/opensora/models/vae/vae_3d.py
@@ -116,10 +116,10 @@ class Encoder(nn.Module):
self.activate = self.activation_fn()
self.conv_fn = functools.partial(
- model_utils.Conv,
+ nn.Conv3d,
dtype=self.dtype,
padding='valid' if self.custom_conv_padding is not None else 'same', # SCH: lower letter for pytorch
- custom_padding=self.custom_conv_padding
+ # custom_padding=self.custom_conv_padding
)
# self.norm_fn = model_utils.get_norm_layer(
@@ -242,10 +242,11 @@ class Decoder(nn.Module):
self.activate = self.activation_fn()
self.conv_fn = functools.partial(
- model_utils.Conv,
+ nn.Conv3d,
dtype=self.dtype,
- padding='VALID' if self.custom_conv_padding is not None else 'SAME',
- custom_padding=self.custom_conv_padding)
+ padding='valid' if self.custom_conv_padding is not None else 'same', # SCH: lower letter for pytorch
+ # custom_padding=self.custom_conv_padding
+ )
self.conv_t_fn = functools.partial(nn.ConvTranspose3d, dtype=self.dtype)