(
self,
hidden_states: torch.FloatTensor,
res_hidden_states_tuple: Tuple[torch.FloatTensor, ...],
temb: Optional[torch.FloatTensor] = None,
upsample_size=None,
scale: float = 1.0,
num_frames: int = 1,
)
| 1511 | self.resolution_idx = resolution_idx |
| 1512 | |
| 1513 | def forward( |
| 1514 | self, |
| 1515 | hidden_states: torch.FloatTensor, |
| 1516 | res_hidden_states_tuple: Tuple[torch.FloatTensor, ...], |
| 1517 | temb: Optional[torch.FloatTensor] = None, |
| 1518 | upsample_size=None, |
| 1519 | scale: float = 1.0, |
| 1520 | num_frames: int = 1, |
| 1521 | ) -> torch.FloatTensor: |
| 1522 | is_freeu_enabled = ( |
| 1523 | getattr(self, "s1", None) |
| 1524 | and getattr(self, "s2", None) |
| 1525 | and getattr(self, "b1", None) |
| 1526 | and getattr(self, "b2", None) |
| 1527 | ) |
| 1528 | |
| 1529 | blocks = zip(self.resnets, self.motion_modules) |
| 1530 | |
| 1531 | for resnet, motion_module in blocks: |
| 1532 | # pop res hidden states |
| 1533 | res_hidden_states = res_hidden_states_tuple[-1] |
| 1534 | res_hidden_states_tuple = res_hidden_states_tuple[:-1] |
| 1535 | |
| 1536 | # FreeU: Only operate on the first two stages |
| 1537 | if is_freeu_enabled: |
| 1538 | hidden_states, res_hidden_states = apply_freeu( |
| 1539 | self.resolution_idx, |
| 1540 | hidden_states, |
| 1541 | res_hidden_states, |
| 1542 | s1=self.s1, |
| 1543 | s2=self.s2, |
| 1544 | b1=self.b1, |
| 1545 | b2=self.b2, |
| 1546 | ) |
| 1547 | |
| 1548 | hidden_states = torch.cat([hidden_states, res_hidden_states], dim=1) |
| 1549 | |
| 1550 | if self.training and self.gradient_checkpointing: |
| 1551 | |
| 1552 | def create_custom_forward(module): |
| 1553 | def custom_forward(*inputs): |
| 1554 | return module(*inputs) |
| 1555 | |
| 1556 | return custom_forward |
| 1557 | |
| 1558 | if is_torch_version(">=", "1.11.0"): |
| 1559 | hidden_states = torch.utils.checkpoint.checkpoint( |
| 1560 | create_custom_forward(resnet), |
| 1561 | hidden_states, |
| 1562 | temb, |
| 1563 | use_reentrant=False, |
| 1564 | ) |
| 1565 | else: |
| 1566 | hidden_states = torch.utils.checkpoint.checkpoint( |
| 1567 | create_custom_forward(resnet), hidden_states, temb |
| 1568 | ) |
| 1569 | hidden_states = torch.utils.checkpoint.checkpoint( |
| 1570 | create_custom_forward(resnet), |
nothing calls this directly
no outgoing calls
no test coverage detected