(
self, hidden_states: torch.FloatTensor, temb: Optional[torch.FloatTensor] = None, scale: float = 1.0,
down_block_add_samples: Optional[torch.FloatTensor] = None,
)
| 1455 | self.gradient_checkpointing = False |
| 1456 | |
| 1457 | def forward( |
| 1458 | self, hidden_states: torch.FloatTensor, temb: Optional[torch.FloatTensor] = None, scale: float = 1.0, |
| 1459 | down_block_add_samples: Optional[torch.FloatTensor] = None, |
| 1460 | ) -> Tuple[torch.FloatTensor, Tuple[torch.FloatTensor, ...]]: |
| 1461 | output_states = () |
| 1462 | |
| 1463 | for resnet in self.resnets: |
| 1464 | if self.training and self.gradient_checkpointing: |
| 1465 | |
| 1466 | def create_custom_forward(module): |
| 1467 | def custom_forward(*inputs): |
| 1468 | return module(*inputs) |
| 1469 | |
| 1470 | return custom_forward |
| 1471 | |
| 1472 | if is_torch_version(">=", "1.11.0"): |
| 1473 | hidden_states = torch.utils.checkpoint.checkpoint( |
| 1474 | create_custom_forward(resnet), hidden_states, temb, use_reentrant=False |
| 1475 | ) |
| 1476 | else: |
| 1477 | hidden_states = torch.utils.checkpoint.checkpoint( |
| 1478 | create_custom_forward(resnet), hidden_states, temb |
| 1479 | ) |
| 1480 | else: |
| 1481 | hidden_states = resnet(hidden_states, temb, scale=scale) |
| 1482 | |
| 1483 | if down_block_add_samples is not None: |
| 1484 | hidden_states = hidden_states + down_block_add_samples.pop(0) |
| 1485 | |
| 1486 | output_states = output_states + (hidden_states,) |
| 1487 | |
| 1488 | if self.downsamplers is not None: |
| 1489 | for downsampler in self.downsamplers: |
| 1490 | hidden_states = downsampler(hidden_states, scale=scale) |
| 1491 | |
| 1492 | if down_block_add_samples is not None: |
| 1493 | hidden_states = hidden_states + down_block_add_samples.pop(0) # todo: add before or after |
| 1494 | |
| 1495 | output_states = output_states + (hidden_states,) |
| 1496 | |
| 1497 | return hidden_states, output_states |
| 1498 | |
| 1499 | |
| 1500 | class DownEncoderBlock2D(nn.Module): |
nothing calls this directly
no test coverage detected