MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / prep_text

Method prep_text

diffusers/examples/community/magic_mix.py:50–71  ·  view source on GitHub ↗
(self, prompt)

Source from the content-addressed store, hash-verified

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,

Callers 1

__call__Method · 0.95

Calls 1

toMethod · 0.45

Tested by

no test coverage detected