Upload modeling.py with huggingface_hub
Browse files- modeling.py +4 -2
modeling.py
CHANGED
|
@@ -284,8 +284,10 @@ class GroupedQueryAttention(nn.Module):
|
|
| 284 |
attention = self.dropout(attention)
|
| 285 |
context = torch.matmul(attention, v)
|
| 286 |
|
| 287 |
-
# Fix context reshaping -
|
| 288 |
-
context
|
|
|
|
|
|
|
| 289 |
|
| 290 |
output = self.W_o(context)
|
| 291 |
|
|
|
|
| 284 |
attention = self.dropout(attention)
|
| 285 |
context = torch.matmul(attention, v)
|
| 286 |
|
| 287 |
+
# Fix context reshaping - properly handle grouped query attention output
|
| 288 |
+
# context shape: [batch_size, num_heads, seq_len, d_k]
|
| 289 |
+
# We need to reshape it to [batch_size, seq_len, d_model] where d_model = num_heads * d_k
|
| 290 |
+
context = context.transpose(1, 2).contiguous().view(batch_size, seq_len, self.num_heads * self.d_k)
|
| 291 |
|
| 292 |
output = self.W_o(context)
|
| 293 |
|