(self, text_prompts: List[str])
| 41 | return torch.cuda.current_device() |
| 42 | |
| 43 | def forward(self, text_prompts: List[str]) -> dict: |
| 44 | ids, mask = self.tokenizer( |
| 45 | text_prompts, return_mask=True, add_special_tokens=True) |
| 46 | ids = ids.to(self.device) |
| 47 | mask = mask.to(self.device) |
| 48 | seq_lens = mask.gt(0).sum(dim=1).long() |
| 49 | context = self.text_encoder(ids, mask) |
| 50 | for u, v in zip(context, seq_lens): |
| 51 | u[v:] = 0.0 # set padding to 0.0 |
| 52 | |
| 53 | return { |
| 54 | "prompt_embeds": context |
| 55 | } |
| 56 | |
| 57 | |
| 58 | class WanVAEWrapper(torch.nn.Module): |