JonusNattapong commited on
Commit
d65d658
·
verified ·
1 Parent(s): 9fe0b36

Upload modeling.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. modeling.py +9 -2
modeling.py CHANGED
@@ -19,7 +19,7 @@ from transformers.modeling_outputs import CausalLMOutputWithPast
19
  class ZombitThaiGPTConfig(PretrainedConfig):
20
  """Configuration class for Zombit Thai GPT model"""
21
 
22
- model_type = "model"
23
  keys_to_ignore_at_inference = ["past_key_values"]
24
 
25
  def __init__(
@@ -284,7 +284,14 @@ class GroupedQueryAttention(nn.Module):
284
  attention = self.dropout(attention)
285
  context = torch.matmul(attention, v)
286
 
287
- context = context.transpose(1, 2).contiguous().view(batch_size, seq_len, self.d_model)
 
 
 
 
 
 
 
288
  output = self.W_o(context)
289
 
290
  return output
 
19
  class ZombitThaiGPTConfig(PretrainedConfig):
20
  """Configuration class for Zombit Thai GPT model"""
21
 
22
+ model_type = "ZombitThaiGPT"
23
  keys_to_ignore_at_inference = ["past_key_values"]
24
 
25
  def __init__(
 
284
  attention = self.dropout(attention)
285
  context = torch.matmul(attention, v)
286
 
287
+ # Fix context reshaping to handle grouped query attention properly
288
+ if self.heads_per_group > 1:
289
+ # For GQA, we need to account for the repeated heads
290
+ context = context.transpose(1, 2).contiguous().view(batch_size, seq_len, self.num_heads * self.d_k)
291
+ else:
292
+ # For standard attention where num_heads == num_kv_heads
293
+ context = context.transpose(1, 2).contiguous().view(batch_size, seq_len, self.d_model)
294
+
295
  output = self.W_o(context)
296
 
297
  return output