MCPcopy Create free account
hub / github.com/geekcomputers/Python / forward

Method forward

ML/src/python/neuralforge/nn/attention.py:196–207  ·  view source on GitHub ↗
(self, x)

Source from the content-addressed store, hash-verified

194 self.proj = nn.Linear(embed_dim, embed_dim)
195
196 def forward(self, x):
197 B, N, C = x.shape
198 qkv = self.qkv(x).reshape(B, N, 3, self.num_heads, self.head_dim).permute(2, 0, 3, 1, 4)
199 q, k, v = qkv[0], qkv[1], qkv[2]
200
201 attn = (q @ k.transpose(-2, -1)) * self.scale
202 attn = F.softmax(attn, dim=-1)
203
204 x = (attn @ v).transpose(1, 2).reshape(B, N, C)
205 x = self.proj(x)
206
207 return x

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected