JonusNattapong commited on
Commit
d66bc63
·
verified ·
1 Parent(s): b2e407b

Upload modeling.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. 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 - always use d_model for output projection
288
- context = context.transpose(1, 2).contiguous().view(batch_size, seq_len, self.d_model)
 
 
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