| 132 | self.conv = conv |
| 133 | |
| 134 | def forward(self, hidden_states: torch.FloatTensor, scale: float = 1.0) -> torch.FloatTensor: |
| 135 | assert hidden_states.shape[1] == self.channels |
| 136 | |
| 137 | if self.norm is not None: |
| 138 | hidden_states = self.norm(hidden_states.permute(0, 2, 3, 1)).permute(0, 3, 1, 2) |
| 139 | |
| 140 | if self.use_conv and self.padding == 0: |
| 141 | pad = (0, 1, 0, 1) |
| 142 | hidden_states = F.pad(hidden_states, pad, mode="constant", value=0) |
| 143 | |
| 144 | assert hidden_states.shape[1] == self.channels |
| 145 | |
| 146 | if not USE_PEFT_BACKEND: |
| 147 | if isinstance(self.conv, LoRACompatibleConv): |
| 148 | hidden_states = self.conv(hidden_states, scale) |
| 149 | else: |
| 150 | hidden_states = self.conv(hidden_states) |
| 151 | else: |
| 152 | hidden_states = self.conv(hidden_states) |
| 153 | |
| 154 | return hidden_states |
| 155 | |
| 156 | |
| 157 | class FirDownsample2D(nn.Module): |