(self, prompts, tokenized_prompts)
| 49 | self.dtype = clip_model.dtype |
| 50 | |
| 51 | def forward(self, prompts, tokenized_prompts): |
| 52 | x = prompts + self.positional_embedding.type(self.dtype) |
| 53 | x = x.permute(1, 0, 2) # NLD -> LND |
| 54 | x = self.transformer(x) |
| 55 | x = x.permute(1, 0, 2) # LND -> NLD |
| 56 | x = self.ln_final(x).type(self.dtype) |
| 57 | |
| 58 | # x.shape = [batch_size, n_ctx, transformer.width] |
| 59 | # take features from the eot embedding (eot_token is the highest number in each sequence) |
| 60 | x = x[torch.arange(x.shape[0]), tokenized_prompts.argmax(dim=-1)] @ self.text_projection |
| 61 | |
| 62 | return x |
| 63 | |
| 64 | |
| 65 | class PromptLearner(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected