(self, x: torch.Tensor)
| 221 | self.proj = nn.Parameter(scale * torch.randn(width, output_dim)) |
| 222 | |
| 223 | def forward(self, x: torch.Tensor): |
| 224 | x = self.conv1(x) # shape = [*, width, grid, grid] |
| 225 | x = x.reshape(x.shape[0], x.shape[1], -1) # shape = [*, width, grid ** 2] |
| 226 | x = x.permute(0, 2, 1) # shape = [*, grid ** 2, width] |
| 227 | x = torch.cat([self.class_embedding.to(x.dtype) + torch.zeros(x.shape[0], 1, x.shape[-1], dtype=x.dtype, device=x.device), x], dim=1) # shape = [*, grid ** 2 + 1, width] |
| 228 | x = x + self.positional_embedding.to(x.dtype) |
| 229 | x = self.ln_pre(x) |
| 230 | |
| 231 | x = x.permute(1, 0, 2) # NLD -> LND |
| 232 | x = self.transformer(x) |
| 233 | x = x.permute(1, 0, 2) # LND -> NLD |
| 234 | |
| 235 | x = self.ln_post(x[:, 0, :]) |
| 236 | |
| 237 | if self.proj is not None: |
| 238 | x = x @ self.proj |
| 239 | |
| 240 | return x |
| 241 | |
| 242 | |
| 243 | class CLIP(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected