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

Class VAEAttentionBlock

diffsynth/models/svd_vae_decoder.py:8–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6
7
8class VAEAttentionBlock(torch.nn.Module):
9
10 def __init__(self, num_attention_heads, attention_head_dim, in_channels, num_layers=1, norm_num_groups=32, eps=1e-5):
11 super().__init__()
12 inner_dim = num_attention_heads * attention_head_dim
13
14 self.norm = torch.nn.GroupNorm(num_groups=norm_num_groups, num_channels=in_channels, eps=eps, affine=True)
15
16 self.transformer_blocks = torch.nn.ModuleList([
17 Attention(
18 inner_dim,
19 num_attention_heads,
20 attention_head_dim,
21 bias_q=True,
22 bias_kv=True,
23 bias_out=True
24 )
25 for d in range(num_layers)
26 ])
27
28 def forward(self, hidden_states, time_emb, text_emb, res_stack):
29 batch, _, height, width = hidden_states.shape
30 residual = hidden_states
31
32 hidden_states = self.norm(hidden_states)
33 inner_dim = hidden_states.shape[1]
34 hidden_states = hidden_states.permute(0, 2, 3, 1).reshape(batch, height * width, inner_dim)
35
36 for block in self.transformer_blocks:
37 hidden_states = block(hidden_states)
38
39 hidden_states = hidden_states.reshape(batch, height, width, inner_dim).permute(0, 3, 1, 2).contiguous()
40 hidden_states = hidden_states + residual
41
42 return hidden_states, time_emb, text_emb, res_stack
43
44
45class TemporalResnetBlock(torch.nn.Module):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected