From bbeddce8f6daa0223bd22569c0ac62c3df0b478f Mon Sep 17 00:00:00 2001 From: Juan Carrasquilla <68667541+JC-swEng@users.noreply.github.com> Date: Tue, 30 Aug 2022 23:26:16 -0500 Subject: [PATCH 1/2] Changed variable name from "h" to "hidden_states" Per issue #198 , changed variable name from "h" to "hidden_states" in the forward function only. I am happy to change any other variable names, please advise recommended new names. --- src/diffusers/models/resnet.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/diffusers/models/resnet.py b/src/diffusers/models/resnet.py index acce7b574e56..32781b04c558 100644 --- a/src/diffusers/models/resnet.py +++ b/src/diffusers/models/resnet.py @@ -329,38 +329,38 @@ def __init__( self.conv_shortcut = torch.nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=1, padding=0) def forward(self, x, temb, hey=False): - h = x + hidden_states = x # make sure hidden states is in float32 # when running in half-precision - h = self.norm1(h.float()).type(h.dtype) - h = self.nonlinearity(h) + hidden_states = self.norm1(hidden_states.float()).type(hidden_states.dtype) + hidden_states = self.nonlinearity(hidden_states) if self.upsample is not None: x = self.upsample(x) - h = self.upsample(h) + hidden_states = self.upsample(hidden_states) elif self.downsample is not None: x = self.downsample(x) - h = self.downsample(h) + hidden_states = self.downsample(hidden_states) - h = self.conv1(h) + hidden_states = self.conv1(hidden_states) if temb is not None: temb = self.time_emb_proj(self.nonlinearity(temb))[:, :, None, None] - h = h + temb + hidden_states = hidden_states + temb # make sure hidden states is in float32 # when running in half-precision - h = self.norm2(h.float()).type(h.dtype) - h = self.nonlinearity(h) + hidden_states = self.norm2(hidden_states.float()).type(hidden_states.dtype) + hidden_states = self.nonlinearity(hidden_states) - h = self.dropout(h) - h = self.conv2(h) + hidden_states = self.dropout(hidden_states) + hidden_states = self.conv2(hidden_states) if self.conv_shortcut is not None: x = self.conv_shortcut(x) - out = (x + h) / self.output_scale_factor + out = (x + hidden_states) / self.output_scale_factor return out From aef0b5e05c5dfbb3b76856d74cd2bbb701811595 Mon Sep 17 00:00:00 2001 From: Juan Carrasquilla <68667541+JC-swEng@users.noreply.github.com> Date: Wed, 31 Aug 2022 12:04:25 -0500 Subject: [PATCH 2/2] Update src/diffusers/models/resnet.py Co-authored-by: Patrick von Platen --- src/diffusers/models/resnet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffusers/models/resnet.py b/src/diffusers/models/resnet.py index 32781b04c558..50382bcab37d 100644 --- a/src/diffusers/models/resnet.py +++ b/src/diffusers/models/resnet.py @@ -328,7 +328,7 @@ def __init__( if self.use_nin_shortcut: self.conv_shortcut = torch.nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=1, padding=0) - def forward(self, x, temb, hey=False): + def forward(self, x, temb): hidden_states = x # make sure hidden states is in float32