(
self,
hidden_states: torch.FloatTensor,
res_hidden_states_tuple: Tuple[torch.FloatTensor, ...],
temb: Optional[torch.FloatTensor] = None,
upsample_size: Optional[int] = None,
scale: float = 1.0,
return_res_samples: Optional[bool]=False,
up_block_add_samples: Optional[torch.FloatTensor] = None,
)
| 2690 | self.resolution_idx = resolution_idx |
| 2691 | |
| 2692 | def forward( |
| 2693 | self, |
| 2694 | hidden_states: torch.FloatTensor, |
| 2695 | res_hidden_states_tuple: Tuple[torch.FloatTensor, ...], |
| 2696 | temb: Optional[torch.FloatTensor] = None, |
| 2697 | upsample_size: Optional[int] = None, |
| 2698 | scale: float = 1.0, |
| 2699 | return_res_samples: Optional[bool]=False, |
| 2700 | up_block_add_samples: Optional[torch.FloatTensor] = None, |
| 2701 | ) -> torch.FloatTensor: |
| 2702 | is_freeu_enabled = ( |
| 2703 | getattr(self, "s1", None) |
| 2704 | and getattr(self, "s2", None) |
| 2705 | and getattr(self, "b1", None) |
| 2706 | and getattr(self, "b2", None) |
| 2707 | ) |
| 2708 | if return_res_samples: |
| 2709 | output_states = () |
| 2710 | |
| 2711 | for resnet in self.resnets: |
| 2712 | # pop res hidden states |
| 2713 | res_hidden_states = res_hidden_states_tuple[-1] |
| 2714 | res_hidden_states_tuple = res_hidden_states_tuple[:-1] |
| 2715 | |
| 2716 | # FreeU: Only operate on the first two stages |
| 2717 | if is_freeu_enabled: |
| 2718 | hidden_states, res_hidden_states = apply_freeu( |
| 2719 | self.resolution_idx, |
| 2720 | hidden_states, |
| 2721 | res_hidden_states, |
| 2722 | s1=self.s1, |
| 2723 | s2=self.s2, |
| 2724 | b1=self.b1, |
| 2725 | b2=self.b2, |
| 2726 | ) |
| 2727 | |
| 2728 | hidden_states = torch.cat([hidden_states, res_hidden_states], dim=1) |
| 2729 | |
| 2730 | if self.training and self.gradient_checkpointing: |
| 2731 | |
| 2732 | def create_custom_forward(module): |
| 2733 | def custom_forward(*inputs): |
| 2734 | return module(*inputs) |
| 2735 | |
| 2736 | return custom_forward |
| 2737 | |
| 2738 | if is_torch_version(">=", "1.11.0"): |
| 2739 | hidden_states = torch.utils.checkpoint.checkpoint( |
| 2740 | create_custom_forward(resnet), hidden_states, temb, use_reentrant=False |
| 2741 | ) |
| 2742 | else: |
| 2743 | hidden_states = torch.utils.checkpoint.checkpoint( |
| 2744 | create_custom_forward(resnet), hidden_states, temb |
| 2745 | ) |
| 2746 | else: |
| 2747 | hidden_states = resnet(hidden_states, temb, scale=scale) |
| 2748 | |
| 2749 | if return_res_samples: |
nothing calls this directly
no test coverage detected