MCPcopy Create free account
hub / github.com/caoql98/DCPL / forward

Method forward

trainers/maple.py:52–66  ·  view source on GitHub ↗
(self, prompts, tokenized_prompts, compound_prompts_deeper_text)

Source from the content-addressed store, hash-verified

50 self.dtype = clip_model.dtype
51
52 def forward(self, prompts, tokenized_prompts, compound_prompts_deeper_text):
53 x = prompts + self.positional_embedding.type(self.dtype)
54 x = x.permute(1, 0, 2) # NLD -> LND
55 # Pass as the list, as nn.sequential cannot process multiple arguments in the forward pass
56 combined = [x, compound_prompts_deeper_text, 0] # third argument is the counter which denotes depth of prompt
57 outputs = self.transformer(combined)
58 x = outputs[0] # extract the x back from here
59 x = x.permute(1, 0, 2) # LND -> NLD
60 x = self.ln_final(x).type(self.dtype)
61
62 # x.shape = [batch_size, n_ctx, transformer.width]
63 # take features from the eot embedding (eot_token is the highest number in each sequence)
64 x = x[torch.arange(x.shape[0]), tokenized_prompts.argmax(dim=-1)] @ self.text_projection
65
66 return x
67
68
69class MultiModalPromptLearner(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected