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

Method forward

diffsynth/models/stepvideo_vae.py:626–673  ·  view source on GitHub ↗
(self, x, video_frame_num, is_init=True)

Source from the content-addressed store, hash-verified

624
625 @torch.inference_mode()
626 def forward(self, x, video_frame_num, is_init=True):
627 # timestep embedding
628 temb = None
629
630 t = video_frame_num
631
632 # downsampling
633 h = self.conv_in(x, is_init)
634
635 # make it real channel last, but behave like normal layout
636 h = h.permute(0,2,3,4,1).contiguous().permute(0,4,1,2,3)
637
638 for i_level in range(self.num_resolutions):
639 for i_block in range(self.num_res_blocks):
640 h = self.down[i_level].block[i_block](h, temb, is_init)
641 if len(self.down[i_level].attn) > 0:
642 h = self.down[i_level].attn[i_block](h)
643
644 if i_level != self.num_resolutions - 1:
645 if isinstance(self.down[i_level].downsample, Downsample2D):
646 _, _, t, _, _ = h.shape
647 h = rearrange(h, "b c t h w -> (b t) h w c", t=t)
648 h = self.down[i_level].downsample(h)
649 h = rearrange(h, "(b t) h w c -> b c t h w", t=t)
650 else:
651 h = self.down[i_level].downsample(h, is_init)
652
653 h = self.mid.block_1(h, temb, is_init)
654 h = self.mid.attn_1(h)
655 h = self.mid.block_2(h, temb, is_init)
656
657 h = h.permute(0,2,3,4,1).contiguous() # b c l h w -> b l h w c
658 if self.version == 2:
659 h = base_group_norm(h, self.norm_out, act_silu=True, channel_last=True)
660 h = h.permute(0,4,1,2,3).contiguous()
661 shortcut = self.shortcut_pathify(h, is_init)
662 h = self.conv_patchify(h, is_init)
663 h = h.add_(shortcut)
664 shortcut = self.shortcut_out(h, is_init).permute(0,2,3,4,1)
665 h = self.conv_out(h.permute(0,2,3,4,1).contiguous(), is_init)
666 h = h.add_(shortcut)
667 else:
668 h = base_group_norm_with_zero_pad(h, self.norm_out, act_silu=True, pad_size=2)
669 h = self.conv_out(h, is_init)
670 h = h.permute(0,4,1,2,3) # b l h w c -> b c l h w
671
672 h = rearrange(h, "b c t h w -> b t c h w")
673 return h
674
675
676class Res3DBlockUpsample(nn.Module):

Callers

nothing calls this directly

Calls 2

base_group_normFunction · 0.85

Tested by

no test coverage detected