| 90 | layers_modified[i] = 'model.diffusion_model' + layers_modified[i] + '.weight' |
| 91 | |
| 92 | def get_text_embedding(prompts): |
| 93 | with torch.no_grad(): |
| 94 | uc = [] |
| 95 | for text in prompts: |
| 96 | tokens = tokenizer(text, |
| 97 | truncation=True, |
| 98 | max_length=77, |
| 99 | return_length=True, |
| 100 | return_overflowing_tokens=False, |
| 101 | padding="max_length", |
| 102 | return_tensors="pt") |
| 103 | |
| 104 | tokens = tokens["input_ids"] |
| 105 | end = torch.nonzero(tokens == 49407)[:, 1].min() |
| 106 | if 'photo of a' in text[:15]: |
| 107 | print(text) |
| 108 | uc.append((model.get_learned_conditioning(1 * [text])[:, 4:end+1]).reshape(-1, 768)) |
| 109 | else: |
| 110 | uc.append((model.get_learned_conditioning(1 * [text])[:, 1:end+1]).reshape(-1, 768)) |
| 111 | |
| 112 | return torch.cat(uc, 0) |
| 113 | |
| 114 | tokenizer = model.cond_stage_model.tokenizer |
| 115 | embeds = [] |