| 872 | self.gradient_checkpointing = False |
| 873 | |
| 874 | def forward(self, x, feat_cache=None, feat_idx=[0], first_chunk=False): |
| 875 | ## conv1 |
| 876 | if feat_cache is not None: |
| 877 | idx = feat_idx[0] |
| 878 | cache_x = x[:, :, -CACHE_T:, :, :].clone() |
| 879 | if cache_x.shape[2] < 2 and feat_cache[idx] is not None: |
| 880 | # cache last frame of last two chunk |
| 881 | cache_x = torch.cat([feat_cache[idx][:, :, -1, :, :].unsqueeze(2).to(cache_x.device), cache_x], dim=2) |
| 882 | x = self.conv_in(x, feat_cache[idx]) |
| 883 | feat_cache[idx] = cache_x |
| 884 | feat_idx[0] += 1 |
| 885 | else: |
| 886 | x = self.conv_in(x) |
| 887 | |
| 888 | ## middle |
| 889 | x = self.mid_block(x, feat_cache, feat_idx) |
| 890 | |
| 891 | ## upsamples |
| 892 | for up_block in self.up_blocks: |
| 893 | x = up_block(x, feat_cache, feat_idx, first_chunk=first_chunk) |
| 894 | |
| 895 | ## head |
| 896 | x = self.norm_out(x) |
| 897 | x = self.nonlinearity(x) |
| 898 | if feat_cache is not None: |
| 899 | idx = feat_idx[0] |
| 900 | cache_x = x[:, :, -CACHE_T:, :, :].clone() |
| 901 | if cache_x.shape[2] < 2 and feat_cache[idx] is not None: |
| 902 | # cache last frame of last two chunk |
| 903 | cache_x = torch.cat([feat_cache[idx][:, :, -1, :, :].unsqueeze(2).to(cache_x.device), cache_x], dim=2) |
| 904 | x = self.conv_out(x, feat_cache[idx]) |
| 905 | feat_cache[idx] = cache_x |
| 906 | feat_idx[0] += 1 |
| 907 | else: |
| 908 | x = self.conv_out(x) |
| 909 | return x |
| 910 | |
| 911 | |
| 912 | def patchify(x, patch_size): |