MCPcopy Create free account
hub / github.com/OpenImagingLab/FlashVSR / forward

Method forward

diffsynth/models/stepvideo_vae.py:823–867  ·  view source on GitHub ↗
(self, z, is_init=True)

Source from the content-addressed store, hash-verified

821
822 @torch.inference_mode()
823 def forward(self, z, is_init=True):
824 z = rearrange(z, "b t c h w -> b c t h w")
825
826 h = self.conv_in(z, is_init=is_init)
827 if self.version == 2:
828 shortcut = self.shortcut_in(z, is_init=is_init)
829 h = h.add_(shortcut)
830 shortcut = self.shortcut_unpathify(h, is_init=is_init)
831 h = self.conv_unpatchify(h, is_init=is_init)
832 h = h.add_(shortcut)
833
834 temb = None
835
836 h = h.permute(0,2,3,4,1).contiguous().permute(0,4,1,2,3)
837 h = self.mid.block_1(h, temb, is_init=is_init)
838 h = self.mid.attn_1(h)
839 h = h.permute(0,2,3,4,1).contiguous().permute(0,4,1,2,3)
840 h = self.mid.block_2(h, temb, is_init=is_init)
841
842 # upsampling
843 for i_level in reversed(range(self.num_resolutions)):
844 for i_block in range(self.num_res_blocks + 1):
845 h = h.permute(0,2,3,4,1).contiguous().permute(0,4,1,2,3)
846 h = self.up[i_level].block[i_block](h, temb, is_init=is_init)
847 if len(self.up[i_level].attn) > 0:
848 h = self.up[i_level].attn[i_block](h)
849 if i_level != 0:
850 if isinstance(self.up[i_level].upsample, Upsample2D) or (hasattr(self.up[i_level].upsample, "module") and isinstance(self.up[i_level].upsample.module, Upsample2D)):
851 B = h.size(0)
852 h = h.permute(0,2,3,4,1).flatten(0,1)
853 h = self.up[i_level].upsample(h)
854 h = h.unflatten(0, (B, -1)).permute(0,4,1,2,3)
855 else:
856 h = self.up[i_level].upsample(h, is_init=is_init)
857
858 # end
859 h = h.permute(0,2,3,4,1) # b c l h w -> b l h w c
860 self.norm_out.to(dtype=h.dtype, device=h.device) # To be updated
861 h = base_group_norm_with_zero_pad(h, self.norm_out, act_silu=True, pad_size=2)
862 h = self.conv_out(h)
863 h = h.permute(0,4,1,2,3)
864
865 if is_init:
866 h = h[:, :, (self.temporal_downsample - 1):]
867 return h
868
869
870

Callers

nothing calls this directly

Calls 2

toMethod · 0.45

Tested by

no test coverage detected