r"""The forward method of the `Decoder` class.
(
self,
sample: torch.Tensor,
latent_embeds: Optional[torch.Tensor] = None,
)
| 282 | self.gradient_checkpointing = False |
| 283 | |
| 284 | def forward( |
| 285 | self, |
| 286 | sample: torch.Tensor, |
| 287 | latent_embeds: Optional[torch.Tensor] = None, |
| 288 | ) -> torch.Tensor: |
| 289 | r"""The forward method of the `Decoder` class.""" |
| 290 | |
| 291 | sample = self.conv_in(sample) |
| 292 | |
| 293 | upscale_dtype = next(iter(self.up_blocks.parameters())).dtype |
| 294 | if self.training and self.gradient_checkpointing: |
| 295 | |
| 296 | def create_custom_forward(module): |
| 297 | def custom_forward(*inputs): |
| 298 | return module(*inputs) |
| 299 | |
| 300 | return custom_forward |
| 301 | |
| 302 | if is_torch_version(">=", "1.11.0"): |
| 303 | # middle |
| 304 | sample = torch.utils.checkpoint.checkpoint( |
| 305 | create_custom_forward(self.mid_block), |
| 306 | sample, |
| 307 | latent_embeds, |
| 308 | use_reentrant=False, |
| 309 | ) |
| 310 | sample = sample.to(upscale_dtype) |
| 311 | |
| 312 | # up |
| 313 | for up_block in self.up_blocks: |
| 314 | sample = torch.utils.checkpoint.checkpoint( |
| 315 | create_custom_forward(up_block), |
| 316 | sample, |
| 317 | latent_embeds, |
| 318 | use_reentrant=False, |
| 319 | ) |
| 320 | else: |
| 321 | # middle |
| 322 | sample = torch.utils.checkpoint.checkpoint( |
| 323 | create_custom_forward(self.mid_block), sample, latent_embeds |
| 324 | ) |
| 325 | sample = sample.to(upscale_dtype) |
| 326 | |
| 327 | # up |
| 328 | for up_block in self.up_blocks: |
| 329 | sample = torch.utils.checkpoint.checkpoint(create_custom_forward(up_block), sample, latent_embeds) |
| 330 | else: |
| 331 | # middle |
| 332 | sample = self.mid_block(sample, latent_embeds) |
| 333 | sample = sample.to(upscale_dtype) |
| 334 | |
| 335 | # up |
| 336 | for up_block in self.up_blocks: |
| 337 | sample = up_block(sample, latent_embeds) |
| 338 | |
| 339 | # post-process |
| 340 | if latent_embeds is None: |
| 341 | sample = self.conv_norm_out(sample) |
nothing calls this directly
no test coverage detected