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

Method forward

clip/model.py:229–246  ·  view source on GitHub ↗
(self, x: torch.Tensor)

Source from the content-addressed store, hash-verified

227 self.proj = nn.Parameter(scale * torch.randn(width, output_dim))
228
229 def forward(self, x: torch.Tensor):
230 x = self.conv1(x) # shape = [*, width, grid, grid]
231 x = x.reshape(x.shape[0], x.shape[1], -1) # shape = [*, width, grid ** 2]
232 x = x.permute(0, 2, 1) # shape = [*, grid ** 2, width]
233 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]
234 x = x + self.positional_embedding.to(x.dtype)
235 x = self.ln_pre(x)
236
237 x = x.permute(1, 0, 2) # NLD -> LND
238 x = self.transformer(x)
239 x = x.permute(1, 0, 2) # LND -> NLD
240
241 x = self.ln_post(x[:, 0, :])
242
243 if self.proj is not None:
244 x = x @ self.proj
245
246 return x
247
248
249class CLIP(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected