(
self,
x,
t,
context,
seq_len,
clip_fea=None,
y=None,
audio=None,
ref_target_masks=None,
)
| 595 | self.enable_teacache = False |
| 596 | |
| 597 | def forward( |
| 598 | self, |
| 599 | x, |
| 600 | t, |
| 601 | context, |
| 602 | seq_len, |
| 603 | clip_fea=None, |
| 604 | y=None, |
| 605 | audio=None, |
| 606 | ref_target_masks=None, |
| 607 | ): |
| 608 | assert clip_fea is not None and y is not None |
| 609 | |
| 610 | _, T, H, W = x[0].shape |
| 611 | N_t = T // self.patch_size[0] |
| 612 | N_h = H // self.patch_size[1] |
| 613 | N_w = W // self.patch_size[2] |
| 614 | |
| 615 | if y is not None: |
| 616 | x = [torch.cat([u, v], dim=0) for u, v in zip(x, y)] |
| 617 | x[0] = x[0].to(context[0].dtype) |
| 618 | |
| 619 | # embeddings |
| 620 | x = [self.patch_embedding(u.unsqueeze(0)) for u in x] |
| 621 | grid_sizes = torch.stack( |
| 622 | [torch.tensor(u.shape[2:], dtype=torch.long) for u in x]) |
| 623 | x = [u.flatten(2).transpose(1, 2) for u in x] |
| 624 | seq_lens = torch.tensor([u.size(1) for u in x], dtype=torch.long) |
| 625 | assert seq_lens.max() <= seq_len |
| 626 | x = torch.cat([ |
| 627 | torch.cat([u, u.new_zeros(1, seq_len - u.size(1), u.size(2))], |
| 628 | dim=1) for u in x |
| 629 | ]) |
| 630 | |
| 631 | # time embeddings |
| 632 | with amp.autocast(dtype=torch.float32): |
| 633 | e = self.time_embedding( |
| 634 | sinusoidal_embedding_1d(self.freq_dim, t).float()) |
| 635 | e0 = self.time_projection(e).unflatten(1, (6, self.dim)) |
| 636 | assert e.dtype == torch.float32 and e0.dtype == torch.float32 |
| 637 | |
| 638 | # text embedding |
| 639 | context_lens = None |
| 640 | context = self.text_embedding( |
| 641 | torch.stack([ |
| 642 | torch.cat( |
| 643 | [u, u.new_zeros(self.text_len - u.size(0), u.size(1))]) |
| 644 | for u in context |
| 645 | ])) |
| 646 | |
| 647 | # clip embedding |
| 648 | if clip_fea is not None: |
| 649 | context_clip = self.img_emb(clip_fea) |
| 650 | context = torch.concat([context_clip, context], dim=1).to(x.dtype) |
| 651 | |
| 652 | |
| 653 | audio_cond = audio.to(device=x.device, dtype=x.dtype) |
| 654 | first_frame_audio_emb_s = audio_cond[:, :1, ...] |
nothing calls this directly
no test coverage detected