| 48 | |
| 49 | # convert prompt into text embeddings, also unconditional embeddings |
| 50 | def prep_text(self, prompt): |
| 51 | text_input = self.tokenizer( |
| 52 | prompt, |
| 53 | padding="max_length", |
| 54 | max_length=self.tokenizer.model_max_length, |
| 55 | truncation=True, |
| 56 | return_tensors="pt", |
| 57 | ) |
| 58 | |
| 59 | text_embedding = self.text_encoder(text_input.input_ids.to(self.device))[0] |
| 60 | |
| 61 | uncond_input = self.tokenizer( |
| 62 | "", |
| 63 | padding="max_length", |
| 64 | max_length=self.tokenizer.model_max_length, |
| 65 | truncation=True, |
| 66 | return_tensors="pt", |
| 67 | ) |
| 68 | |
| 69 | uncond_embedding = self.text_encoder(uncond_input.input_ids.to(self.device))[0] |
| 70 | |
| 71 | return torch.cat([uncond_embedding, text_embedding]) |
| 72 | |
| 73 | def __call__( |
| 74 | self, |