(
self,
hidden_states,
res_hidden_states_tuple,
temb=None,
upsample_size=None,
encoder_hidden_states=None,
)
| 880 | self.gradient_checkpointing = False |
| 881 | |
| 882 | def forward( |
| 883 | self, |
| 884 | hidden_states, |
| 885 | res_hidden_states_tuple, |
| 886 | temb=None, |
| 887 | upsample_size=None, |
| 888 | encoder_hidden_states=None, |
| 889 | ): |
| 890 | for resnet, motion_module in zip(self.resnets, self.motion_modules): |
| 891 | # pop res hidden states |
| 892 | res_hidden_states = res_hidden_states_tuple[-1] |
| 893 | res_hidden_states_tuple = res_hidden_states_tuple[:-1] |
| 894 | hidden_states = torch.cat([hidden_states, res_hidden_states], dim=1) |
| 895 | |
| 896 | # print(f"UpBlock3D {self.gradient_checkpointing = }") |
| 897 | if self.training and self.gradient_checkpointing: |
| 898 | |
| 899 | def create_custom_forward(module): |
| 900 | def custom_forward(*inputs): |
| 901 | return module(*inputs) |
| 902 | |
| 903 | return custom_forward |
| 904 | |
| 905 | hidden_states = torch.utils.checkpoint.checkpoint( |
| 906 | create_custom_forward(resnet), hidden_states, temb |
| 907 | ) |
| 908 | if motion_module is not None: |
| 909 | hidden_states = torch.utils.checkpoint.checkpoint( |
| 910 | create_custom_forward(motion_module), |
| 911 | hidden_states.requires_grad_(), |
| 912 | temb, |
| 913 | encoder_hidden_states, |
| 914 | ) |
| 915 | else: |
| 916 | hidden_states = resnet(hidden_states, temb) |
| 917 | hidden_states = ( |
| 918 | motion_module( |
| 919 | hidden_states, temb, encoder_hidden_states=encoder_hidden_states |
| 920 | ) |
| 921 | if motion_module is not None |
| 922 | else hidden_states |
| 923 | ) |
| 924 | |
| 925 | if self.upsamplers is not None: |
| 926 | for upsampler in self.upsamplers: |
| 927 | hidden_states = upsampler(hidden_states, upsample_size) |
| 928 | |
| 929 | return hidden_states |
nothing calls this directly
no outgoing calls
no test coverage detected