| 548 | |
| 549 | |
| 550 | class DownBlock3D(nn.Module): |
| 551 | def __init__( |
| 552 | self, |
| 553 | in_channels: int, |
| 554 | out_channels: int, |
| 555 | temb_channels: int, |
| 556 | dropout: float = 0.0, |
| 557 | num_layers: int = 1, |
| 558 | resnet_eps: float = 1e-6, |
| 559 | resnet_time_scale_shift: str = "default", |
| 560 | resnet_act_fn: str = "swish", |
| 561 | resnet_groups: int = 32, |
| 562 | resnet_pre_norm: bool = True, |
| 563 | output_scale_factor: float = 1.0, |
| 564 | add_downsample: bool = True, |
| 565 | downsample_padding: int = 1, |
| 566 | ): |
| 567 | super().__init__() |
| 568 | resnets = [] |
| 569 | temp_convs = [] |
| 570 | |
| 571 | for i in range(num_layers): |
| 572 | in_channels = in_channels if i == 0 else out_channels |
| 573 | resnets.append( |
| 574 | ResnetBlock2D( |
| 575 | in_channels=in_channels, |
| 576 | out_channels=out_channels, |
| 577 | temb_channels=temb_channels, |
| 578 | eps=resnet_eps, |
| 579 | groups=resnet_groups, |
| 580 | dropout=dropout, |
| 581 | time_embedding_norm=resnet_time_scale_shift, |
| 582 | non_linearity=resnet_act_fn, |
| 583 | output_scale_factor=output_scale_factor, |
| 584 | pre_norm=resnet_pre_norm, |
| 585 | ) |
| 586 | ) |
| 587 | temp_convs.append( |
| 588 | TemporalConvLayer( |
| 589 | out_channels, |
| 590 | out_channels, |
| 591 | dropout=0.1, |
| 592 | norm_num_groups=resnet_groups, |
| 593 | ) |
| 594 | ) |
| 595 | |
| 596 | self.resnets = nn.ModuleList(resnets) |
| 597 | self.temp_convs = nn.ModuleList(temp_convs) |
| 598 | |
| 599 | if add_downsample: |
| 600 | self.downsamplers = nn.ModuleList( |
| 601 | [ |
| 602 | Downsample2D( |
| 603 | out_channels, |
| 604 | use_conv=True, |
| 605 | out_channels=out_channels, |
| 606 | padding=downsample_padding, |
| 607 | name="op", |