| 1310 | |
| 1311 | |
| 1312 | class DownBlock2D(nn.Module): |
| 1313 | def __init__( |
| 1314 | self, |
| 1315 | in_channels: int, |
| 1316 | out_channels: int, |
| 1317 | temb_channels: int, |
| 1318 | dropout: float = 0.0, |
| 1319 | num_layers: int = 1, |
| 1320 | resnet_eps: float = 1e-6, |
| 1321 | resnet_time_scale_shift: str = "default", |
| 1322 | resnet_act_fn: str = "swish", |
| 1323 | resnet_groups: int = 32, |
| 1324 | resnet_pre_norm: bool = True, |
| 1325 | output_scale_factor: float = 1.0, |
| 1326 | add_downsample: bool = True, |
| 1327 | downsample_padding: int = 1, |
| 1328 | ): |
| 1329 | super().__init__() |
| 1330 | resnets = [] |
| 1331 | |
| 1332 | for i in range(num_layers): |
| 1333 | in_channels = in_channels if i == 0 else out_channels |
| 1334 | resnets.append( |
| 1335 | ResnetBlock2D( |
| 1336 | in_channels=in_channels, |
| 1337 | out_channels=out_channels, |
| 1338 | temb_channels=temb_channels, |
| 1339 | eps=resnet_eps, |
| 1340 | groups=resnet_groups, |
| 1341 | dropout=dropout, |
| 1342 | time_embedding_norm=resnet_time_scale_shift, |
| 1343 | non_linearity=resnet_act_fn, |
| 1344 | output_scale_factor=output_scale_factor, |
| 1345 | pre_norm=resnet_pre_norm, |
| 1346 | ) |
| 1347 | ) |
| 1348 | |
| 1349 | self.resnets = nn.ModuleList(resnets) |
| 1350 | |
| 1351 | if add_downsample: |
| 1352 | self.downsamplers = nn.ModuleList( |
| 1353 | [ |
| 1354 | Downsample2D( |
| 1355 | out_channels, use_conv=True, out_channels=out_channels, padding=downsample_padding, name="op" |
| 1356 | ) |
| 1357 | ] |
| 1358 | ) |
| 1359 | else: |
| 1360 | self.downsamplers = None |
| 1361 | |
| 1362 | self.gradient_checkpointing = False |
| 1363 | |
| 1364 | def forward( |
| 1365 | self, hidden_states: torch.Tensor, temb: Optional[torch.Tensor] = None, *args, **kwargs |
| 1366 | ) -> Tuple[torch.Tensor, Tuple[torch.Tensor, ...]]: |
| 1367 | if len(args) > 0 or kwargs.get("scale", None) is not None: |
| 1368 | deprecation_message = "The `scale` argument is deprecated and will be ignored. Please remove it, as passing it will raise an error in the future. `scale` should directly be passed while calling the underlying pipeline component i.e., via `cross_attention_kwargs`." |
| 1369 | deprecate("scale", "1.0.0", deprecation_message) |
no outgoing calls
no test coverage detected