MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / forward

Method forward

src/diffusers/models/resnet.py:152–192  ·  view source on GitHub ↗
(
        self,
        input_tensor: torch.FloatTensor,
        temb: torch.FloatTensor,
        scale: float = 1.0,
    )

Source from the content-addressed store, hash-verified

150 )
151
152 def forward(
153 self,
154 input_tensor: torch.FloatTensor,
155 temb: torch.FloatTensor,
156 scale: float = 1.0,
157 ) -> torch.FloatTensor:
158 hidden_states = input_tensor
159
160 hidden_states = self.norm1(hidden_states, temb)
161
162 hidden_states = self.nonlinearity(hidden_states)
163
164 if self.upsample is not None:
165 # upsample_nearest_nhwc fails with large batch sizes. see https://github.com/huggingface/diffusers/issues/984
166 if hidden_states.shape[0] >= 64:
167 input_tensor = input_tensor.contiguous()
168 hidden_states = hidden_states.contiguous()
169 input_tensor = self.upsample(input_tensor, scale=scale)
170 hidden_states = self.upsample(hidden_states, scale=scale)
171
172 elif self.downsample is not None:
173 input_tensor = self.downsample(input_tensor, scale=scale)
174 hidden_states = self.downsample(hidden_states, scale=scale)
175
176 hidden_states = self.conv1(hidden_states, scale) if not USE_PEFT_BACKEND else self.conv1(hidden_states)
177
178 hidden_states = self.norm2(hidden_states, temb)
179
180 hidden_states = self.nonlinearity(hidden_states)
181
182 hidden_states = self.dropout(hidden_states)
183 hidden_states = self.conv2(hidden_states, scale) if not USE_PEFT_BACKEND else self.conv2(hidden_states)
184
185 if self.conv_shortcut is not None:
186 input_tensor = (
187 self.conv_shortcut(input_tensor, scale) if not USE_PEFT_BACKEND else self.conv_shortcut(input_tensor)
188 )
189
190 output_tensor = (input_tensor + hidden_states) / self.output_scale_factor
191
192 return output_tensor
193
194
195class ResnetBlock2D(nn.Module):

Callers

nothing calls this directly

Calls 1

downsampleMethod · 0.80

Tested by

no test coverage detected