MCPcopy Create free account
hub / github.com/MotrixLab/insactor / forward

Method forward

diffplanner/models/transformers/text_transformer.py:72–90  ·  view source on GitHub ↗
(self, text, token=None, device=None)

Source from the content-addressed store, hash-verified

70 )
71
72 def forward(self, text, token=None, device=None):
73 with torch.no_grad():
74 text = clip.tokenize(text, truncate=True).to(device)
75 x = self.clip.token_embedding(text).type(self.clip.dtype)
76
77 x = x + self.clip.positional_embedding.type(self.clip.dtype)
78 x = x.permute(1, 0, 2)
79 x = self.clip.transformer(x)
80 x = self.clip.ln_final(x).type(self.clip.dtype)
81
82 x = self.text_pre_proj(x)
83 xf_out = self.textTransEncoder(x)
84 xf_out = self.text_ln(xf_out)
85 if self.use_text_proj:
86 xf_proj = self.text_proj(xf_out[text.argmax(dim=-1), torch.arange(xf_out.shape[1])])
87 return xf_proj
88 else:
89 xf_out = xf_out.permute(1, 0, 2)
90 return xf_out
91
92 def load_pretrained(self, ckpt_path):
93 checkpoint = torch.load(ckpt_path, map_location='cpu')

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected