MCPcopy Create free account
hub / github.com/adobe-research/custom-diffusion / get_text_embedding

Function get_text_embedding

src/diffusers_composenW.py:55–71  ·  view source on GitHub ↗
(prompts)

Source from the content-addressed store, hash-verified

53 tokenizer = pipe.tokenizer
54
55 def get_text_embedding(prompts):
56 with torch.no_grad():
57 uc = []
58 for text in prompts:
59 tokens = tokenizer(text,
60 truncation=True,
61 max_length=tokenizer.model_max_length,
62 return_length=True,
63 return_overflowing_tokens=False,
64 padding="do_not_pad",
65 ).input_ids
66 if 'photo of a' in text[:15]:
67 print(text)
68 uc.append(pipe.text_encoder(torch.cuda.LongTensor(tokens).reshape(1,-1))[0][:, 4:].reshape(-1, 768))
69 else:
70 uc.append(pipe.text_encoder(torch.cuda.LongTensor(tokens).reshape(1,-1))[0][:, 1:].reshape(-1, 768))
71 return torch.cat(uc, 0).float()
72
73 embeds = {}
74 count = 1

Callers 1

composeFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected