Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/diffusers/models/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ def _upsample_2d(self, x, weight=None, kernel=None, factor=2, gain=1):

stride = (factor, factor)
# Determine data dimensions.
stride = [1, 1, factor, factor]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F.conv_transpose2d should have a single int or a tuple of 2 integers for stride, not 4 integers.

output_shape = ((x.shape[2] - 1) * factor + convH, (x.shape[3] - 1) * factor + convW)
output_padding = (
output_shape[0] - (x.shape[2] - 1) * stride[0] - convH,
Expand All @@ -161,7 +160,7 @@ def _upsample_2d(self, x, weight=None, kernel=None, factor=2, gain=1):

# Transpose weights.
weight = torch.reshape(weight, (num_groups, -1, inC, convH, convW))
weight = weight[..., ::-1, ::-1].permute(0, 2, 1, 3, 4)
weight = torch.flip(weight, dims=[3, 4]).permute(0, 2, 1, 3, 4)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix, we got

ValueError: step must be greater than zero

The syntax ::-1 is for TF tensors, not for torch tensors.

weight = torch.reshape(weight, (num_groups * inC, -1, convH, convW))

x = F.conv_transpose2d(x, weight, stride=stride, output_padding=output_padding, padding=0)
Expand Down