| 8 | class 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 |