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

Method forward

clip/model.py:66–90  ·  view source on GitHub ↗
(self, x)

Source from the content-addressed store, hash-verified

64 self.num_heads = num_heads
65
66 def forward(self, x):
67 x = x.reshape(x.shape[0], x.shape[1], x.shape[2] * x.shape[3]).permute(2, 0, 1) # NCHW -> (HW)NC
68 x = torch.cat([x.mean(dim=0, keepdim=True), x], dim=0) # (HW+1)NC
69 x = x + self.positional_embedding[:, None, :].to(x.dtype) # (HW+1)NC
70 x, _ = multi_head_attention_forward(
71 query=x, key=x, value=x,
72 embed_dim_to_check=x.shape[-1],
73 num_heads=self.num_heads,
74 q_proj_weight=self.q_proj.weight,
75 k_proj_weight=self.k_proj.weight,
76 v_proj_weight=self.v_proj.weight,
77 in_proj_weight=None,
78 in_proj_bias=torch.cat([self.q_proj.bias, self.k_proj.bias, self.v_proj.bias]),
79 bias_k=None,
80 bias_v=None,
81 add_zero_attn=False,
82 dropout_p=0,
83 out_proj_weight=self.c_proj.weight,
84 out_proj_bias=self.c_proj.bias,
85 use_separate_proj_weight=True,
86 training=self.training,
87 need_weights=False
88 )
89
90 return x[0]
91
92
93class ModifiedResNet(nn.Module):

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected