| 70 | self.proj_out = torch.nn.Linear(inner_dim, in_channels) |
| 71 | |
| 72 | def forward(self, hidden_states, time_emb, text_emb, res_stack, batch_size=1): |
| 73 | batch, _, height, width = hidden_states.shape |
| 74 | residual = hidden_states |
| 75 | |
| 76 | hidden_states = self.norm(hidden_states) |
| 77 | inner_dim = hidden_states.shape[1] |
| 78 | hidden_states = hidden_states.permute(0, 2, 3, 1).reshape(batch, height * width, inner_dim) |
| 79 | hidden_states = self.proj_in(hidden_states) |
| 80 | |
| 81 | for block in self.transformer_blocks: |
| 82 | hidden_states = block( |
| 83 | hidden_states, |
| 84 | batch_size=batch_size |
| 85 | ) |
| 86 | |
| 87 | hidden_states = self.proj_out(hidden_states) |
| 88 | hidden_states = hidden_states.reshape(batch, height, width, inner_dim).permute(0, 3, 1, 2).contiguous() |
| 89 | hidden_states = hidden_states + residual |
| 90 | |
| 91 | return hidden_states, time_emb, text_emb, res_stack |
| 92 | |
| 93 | |
| 94 | class SDMotionModel(torch.nn.Module): |