Skip to content

Commit 35085ea

Browse files
committed
Workaround for upscale with large output tensors.
Fixes #10040.
1 parent c96bfa5 commit 35085ea

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/diffusers/models/upsampling.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ def forward(self, hidden_states: torch.Tensor, output_size: Optional[int] = None
165165
# if `output_size` is passed we force the interpolation output
166166
# size and do not make use of `scale_factor=2`
167167
if self.interpolate:
168+
# upsample_nearest_nhwc also fails when the number of output elements is large
169+
# https://github.com/pytorch/pytorch/issues/141831
170+
scale_factor = 2 if output_size is None else max(output_size)
171+
if hidden_states.numel() * scale_factor > pow(2, 31):
172+
hidden_states = hidden_states.contiguous()
173+
168174
if output_size is None:
169175
hidden_states = F.interpolate(hidden_states, scale_factor=2.0, mode="nearest")
170176
else:

0 commit comments

Comments
 (0)