"git@developer.sourcefind.cn:OpenDAS/megatron-lm.git" did not exist on "1016e98a8351e7b1fd630c6930aa4fbb491df895"
Unverified Commit ab079f27 authored by Nouamane Tazi's avatar Nouamane Tazi Committed by GitHub
Browse files

fix `F.interpolate()` for large batch sizes (#1006)

* fix `upsample_nearest_nhwc` for large bsz

* fix `upsample_nearest_nhwc` for large bsz
parent 1e07b6b3
...@@ -48,6 +48,10 @@ class Upsample2D(nn.Module): ...@@ -48,6 +48,10 @@ class Upsample2D(nn.Module):
if dtype == torch.bfloat16: if dtype == torch.bfloat16:
hidden_states = hidden_states.to(torch.float32) hidden_states = hidden_states.to(torch.float32)
# upsample_nearest_nhwc fails with large batch sizes. see https://github.com/huggingface/diffusers/issues/984
if hidden_states.shape[0] >= 64:
hidden_states = hidden_states.contiguous()
# if `output_size` is passed we force the interpolation output # if `output_size` is passed we force the interpolation output
# size and do not make use of `scale_factor=2` # size and do not make use of `scale_factor=2`
if output_size is None: if output_size is None:
...@@ -376,6 +380,10 @@ class ResnetBlock2D(nn.Module): ...@@ -376,6 +380,10 @@ class ResnetBlock2D(nn.Module):
hidden_states = self.nonlinearity(hidden_states) hidden_states = self.nonlinearity(hidden_states)
if self.upsample is not None: if self.upsample is not None:
# upsample_nearest_nhwc fails with large batch sizes. see https://github.com/huggingface/diffusers/issues/984
if hidden_states.shape[0] >= 64:
input_tensor = input_tensor.contiguous()
hidden_states = hidden_states.contiguous()
input_tensor = self.upsample(input_tensor) input_tensor = self.upsample(input_tensor)
hidden_states = self.upsample(hidden_states) hidden_states = self.upsample(hidden_states)
elif self.downsample is not None: elif self.downsample is not None:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment