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

Class PatchEmbed

diffsynth/models/stepvideo_dit.py:715–743  ·  view source on GitHub ↗

2D Image to Patch Embedding

Source from the content-addressed store, hash-verified

713
714
715class PatchEmbed(nn.Module):
716 """2D Image to Patch Embedding"""
717
718 def __init__(
719 self,
720 patch_size=64,
721 in_channels=3,
722 embed_dim=768,
723 layer_norm=False,
724 flatten=True,
725 bias=True,
726 ):
727 super().__init__()
728
729 self.flatten = flatten
730 self.layer_norm = layer_norm
731
732 self.proj = nn.Conv2d(
733 in_channels, embed_dim, kernel_size=(patch_size, patch_size), stride=patch_size, bias=bias
734 )
735
736 def forward(self, latent):
737 latent = self.proj(latent).to(latent.dtype)
738 if self.flatten:
739 latent = latent.flatten(2).transpose(1, 2) # BCHW -> BNC
740 if self.layer_norm:
741 latent = self.norm(latent)
742
743 return latent
744
745
746class StepVideoModel(torch.nn.Module):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected