MCPcopy Create free account
hub / github.com/Monalissaa/DisenDiff / forward

Method forward

src/custom_modules.py:291–309  ·  view source on GitHub ↗
(self, text, t=None)

Source from the content-addressed store, hash-verified

289 param.requires_grad = False
290
291 def forward(self, text, t=None):
292 batch_encoding = self.tokenizer(text, truncation=True, max_length=self.max_length, return_length=True,
293 return_overflowing_tokens=False, padding="max_length", return_tensors="pt")
294 tokens = batch_encoding["input_ids"].to(self.device)
295
296 indices = tokens == self.modifier_token_id[-1]
297 for token_id in self.modifier_token_id:
298 indices |= tokens == token_id
299 indices = (indices*1).unsqueeze(-1)
300
301 input_shape = tokens.size()
302 tokens = tokens.view(-1, input_shape[-1])
303
304 hidden_states = self.transformer.text_model.embeddings(input_ids=tokens)
305 hidden_states = (1-indices)*hidden_states.detach() + indices*hidden_states
306
307 z = self.custom_forward(hidden_states, tokens)
308
309 return z
310
311 def encode(self, text, t=None):
312 return self(text, t)

Callers

nothing calls this directly

Calls 1

custom_forwardMethod · 0.95

Tested by

no test coverage detected