| 2565 | |
| 2566 | |
| 2567 | class UpBlock2D(nn.Module): |
| 2568 | def __init__( |
| 2569 | self, |
| 2570 | in_channels: int, |
| 2571 | prev_output_channel: int, |
| 2572 | out_channels: int, |
| 2573 | temb_channels: int, |
| 2574 | resolution_idx: Optional[int] = None, |
| 2575 | dropout: float = 0.0, |
| 2576 | num_layers: int = 1, |
| 2577 | resnet_eps: float = 1e-6, |
| 2578 | resnet_time_scale_shift: str = "default", |
| 2579 | resnet_act_fn: str = "swish", |
| 2580 | resnet_groups: int = 32, |
| 2581 | resnet_pre_norm: bool = True, |
| 2582 | output_scale_factor: float = 1.0, |
| 2583 | add_upsample: bool = True, |
| 2584 | ): |
| 2585 | super().__init__() |
| 2586 | resnets = [] |
| 2587 | |
| 2588 | for i in range(num_layers): |
| 2589 | res_skip_channels = in_channels if (i == num_layers - 1) else out_channels |
| 2590 | resnet_in_channels = prev_output_channel if i == 0 else out_channels |
| 2591 | |
| 2592 | resnets.append( |
| 2593 | ResnetBlock2D( |
| 2594 | in_channels=resnet_in_channels + res_skip_channels, |
| 2595 | out_channels=out_channels, |
| 2596 | temb_channels=temb_channels, |
| 2597 | eps=resnet_eps, |
| 2598 | groups=resnet_groups, |
| 2599 | dropout=dropout, |
| 2600 | time_embedding_norm=resnet_time_scale_shift, |
| 2601 | non_linearity=resnet_act_fn, |
| 2602 | output_scale_factor=output_scale_factor, |
| 2603 | pre_norm=resnet_pre_norm, |
| 2604 | ) |
| 2605 | ) |
| 2606 | |
| 2607 | self.resnets = nn.ModuleList(resnets) |
| 2608 | |
| 2609 | if add_upsample: |
| 2610 | self.upsamplers = nn.ModuleList([Upsample2D(out_channels, use_conv=True, out_channels=out_channels)]) |
| 2611 | else: |
| 2612 | self.upsamplers = None |
| 2613 | |
| 2614 | self.gradient_checkpointing = False |
| 2615 | self.resolution_idx = resolution_idx |
| 2616 | |
| 2617 | def forward( |
| 2618 | self, |
| 2619 | hidden_states: torch.Tensor, |
| 2620 | res_hidden_states_tuple: Tuple[torch.Tensor, ...], |
| 2621 | temb: Optional[torch.Tensor] = None, |
| 2622 | upsample_size: Optional[int] = None, |
| 2623 | *args, |
| 2624 | **kwargs, |
no outgoing calls
no test coverage detected