(self, text, device)
| 378 | self.out = zero_module(nn.Linear(self.latent_dim, self.input_feats)) |
| 379 | |
| 380 | def encode_text(self, text, device): |
| 381 | with torch.no_grad(): |
| 382 | text = clip.tokenize(text, truncate=True).to(device) |
| 383 | x = self.clip.token_embedding(text).type(self.clip.dtype) # [batch_size, n_ctx, d_model] |
| 384 | |
| 385 | x = x + self.clip.positional_embedding.type(self.clip.dtype) |
| 386 | x = x.permute(1, 0, 2) # NLD -> LND |
| 387 | x = self.clip.transformer(x) |
| 388 | x = self.clip.ln_final(x).type(self.clip.dtype) |
| 389 | |
| 390 | # T, B, D |
| 391 | x = self.text_pre_proj(x) |
| 392 | xf_out = self.textTransEncoder(x) |
| 393 | xf_out = self.text_ln(xf_out) |
| 394 | xf_proj = self.text_proj(xf_out[text.argmax(dim=-1), torch.arange(xf_out.shape[1])]) |
| 395 | # B, T, D |
| 396 | xf_out = xf_out.permute(1, 0, 2) |
| 397 | return xf_proj, xf_out |
| 398 | |
| 399 | def generate_src_mask(self, T, length): |
| 400 | B = len(length) |
no test coverage detected