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

Class TemporalResnetBlock

diffsynth/models/svd_vae_decoder.py:45–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43
44
45class TemporalResnetBlock(torch.nn.Module):
46
47 def __init__(self, in_channels, out_channels, groups=32, eps=1e-5):
48 super().__init__()
49 self.norm1 = torch.nn.GroupNorm(num_groups=groups, num_channels=in_channels, eps=eps, affine=True)
50 self.conv1 = torch.nn.Conv3d(in_channels, out_channels, kernel_size=(3, 1, 1), stride=1, padding=(1, 0, 0))
51 self.norm2 = torch.nn.GroupNorm(num_groups=groups, num_channels=out_channels, eps=eps, affine=True)
52 self.conv2 = torch.nn.Conv3d(out_channels, out_channels, kernel_size=(3, 1, 1), stride=1, padding=(1, 0, 0))
53 self.nonlinearity = torch.nn.SiLU()
54 self.mix_factor = torch.nn.Parameter(torch.Tensor([0.5]))
55
56 def forward(self, hidden_states, time_emb, text_emb, res_stack, **kwargs):
57 x_spatial = hidden_states
58 x = rearrange(hidden_states, "T C H W -> 1 C T H W")
59 x = self.norm1(x)
60 x = self.nonlinearity(x)
61 x = self.conv1(x)
62 x = self.norm2(x)
63 x = self.nonlinearity(x)
64 x = self.conv2(x)
65 x_temporal = hidden_states + x[0].permute(1, 0, 2, 3)
66 alpha = torch.sigmoid(self.mix_factor)
67 hidden_states = alpha * x_temporal + (1 - alpha) * x_spatial
68 return hidden_states, time_emb, text_emb, res_stack
69
70
71class SVDVAEDecoder(torch.nn.Module):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected