MaduRox commited on
Commit
81b6e37
·
1 Parent(s): b48d71c

Fix Phase Attention Benchmark to simulate GQA 2 KV heads

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -238,18 +238,20 @@ with gr.Blocks(title="Kalpanā API — ZeroGPU NVIDIA A100", theme=gr.themes.Sof
238
  res = {"context_length": seq_len}
239
 
240
  num_layers = 24
241
- num_heads = 14
 
242
  embed_dim = 896
243
  head_dim = 64
244
 
245
- # 1. Profile Kalpana (Full 24 Layers)
246
  torch.cuda.empty_cache()
247
  torch.cuda.reset_peak_memory_stats()
248
  try:
249
- Q_layer = torch.randn(1, num_heads, head_dim, device=device)
 
250
  phase_layers = []
251
  for i in range(num_layers):
252
- p_attn = TrueO1PhaseAttentionLayer(embed_dim=embed_dim, num_heads=num_heads, bands=2048, device=device)
253
  p_attn.current_t = seq_len
254
  phase_layers.append(p_attn)
255
 
@@ -262,18 +264,18 @@ with gr.Blocks(title="Kalpanā API — ZeroGPU NVIDIA A100", theme=gr.themes.Sof
262
  except Exception as e:
263
  res["kalpana_peak_vram_mb"] = f"OOM: {str(e)[:50]}..."
264
 
265
- # 2. Profile Standard SDPA (Full 24 Layers)
266
  torch.cuda.empty_cache()
267
  torch.cuda.reset_peak_memory_stats()
268
  try:
269
  K_list, V_list = [], []
270
- Q_std = torch.randn(1, num_heads, 1, head_dim, device=device)
271
  import torch.nn.functional as F
272
 
273
  with torch.inference_mode():
274
  for i in range(num_layers):
275
- K = torch.randn(1, num_heads, seq_len, head_dim, device=device)
276
- V = torch.randn(1, num_heads, seq_len, head_dim, device=device)
277
  K_list.append(K)
278
  V_list.append(V)
279
  _ = F.scaled_dot_product_attention(Q_std, K, V)
 
238
  res = {"context_length": seq_len}
239
 
240
  num_layers = 24
241
+ num_q_heads = 14
242
+ num_kv_heads = 2
243
  embed_dim = 896
244
  head_dim = 64
245
 
246
+ # 1. Profile Kalpana (Full 24 Layers, 2 KV Heads)
247
  torch.cuda.empty_cache()
248
  torch.cuda.reset_peak_memory_stats()
249
  try:
250
+ # Q is simulated for 14 heads but Kalpana state only needs 2 KV heads
251
+ Q_layer = torch.randn(1, num_kv_heads, head_dim, device=device) # using kv heads for simple projection test
252
  phase_layers = []
253
  for i in range(num_layers):
254
+ p_attn = TrueO1PhaseAttentionLayer(embed_dim=head_dim*num_kv_heads, num_heads=num_kv_heads, bands=2048, device=device)
255
  p_attn.current_t = seq_len
256
  phase_layers.append(p_attn)
257
 
 
264
  except Exception as e:
265
  res["kalpana_peak_vram_mb"] = f"OOM: {str(e)[:50]}..."
266
 
267
+ # 2. Profile Standard SDPA (Full 24 Layers, 2 KV Heads)
268
  torch.cuda.empty_cache()
269
  torch.cuda.reset_peak_memory_stats()
270
  try:
271
  K_list, V_list = [], []
272
+ Q_std = torch.randn(1, num_kv_heads, 1, head_dim, device=device)
273
  import torch.nn.functional as F
274
 
275
  with torch.inference_mode():
276
  for i in range(num_layers):
277
+ K = torch.randn(1, num_kv_heads, seq_len, head_dim, device=device)
278
+ V = torch.randn(1, num_kv_heads, seq_len, head_dim, device=device)
279
  K_list.append(K)
280
  V_list.append(V)
281
  _ = F.scaled_dot_product_attention(Q_std, K, V)