MaduRox commited on
Commit
4c632bd
·
1 Parent(s): 8f21dbc

Fix Phase Attention Benchmark to simulate 24 layers

Browse files
Files changed (1) hide show
  1. app.py +31 -16
app.py CHANGED
@@ -237,34 +237,49 @@ with gr.Blocks(title="Kalpanā API — ZeroGPU NVIDIA A100", theme=gr.themes.Sof
237
  for seq_len in ctx_lengths:
238
  res = {"context_length": seq_len}
239
 
240
- # 1. Profile Phase Attention
 
 
 
 
 
241
  torch.cuda.empty_cache()
242
  torch.cuda.reset_peak_memory_stats()
243
- phase_attn = TrueO1PhaseAttentionLayer(embed_dim=64, num_heads=2, bands=2048, device=device)
244
- Q = torch.randn(1, 2, 32, device=device) # dim=32
245
- phase_attn.current_t = seq_len
246
- # Simulate forward pass
247
  try:
248
- _ = phase_attn.forward(Q)
 
 
 
 
 
 
 
 
 
249
  res["kalpana_peak_vram_mb"] = round(torch.cuda.max_memory_allocated() / (1024*1024), 2)
 
250
  except Exception as e:
251
- res["kalpana_peak_vram_mb"] = f"OOM or Error: {str(e)}"
252
- del phase_attn, Q
253
 
254
- # 2. Profile Standard SDPA (Generation Step)
255
  torch.cuda.empty_cache()
256
  torch.cuda.reset_peak_memory_stats()
257
  try:
258
- # Standard KV cache: [batch, heads, seq_len, dim]
259
- K = torch.randn(1, 2, seq_len, 32, device=device)
260
- V = torch.randn(1, 2, seq_len, 32, device=device)
261
- Q_std = torch.randn(1, 2, 1, 32, device=device)
262
  import torch.nn.functional as F
263
- _ = F.scaled_dot_product_attention(Q_std, K, V)
 
 
 
 
 
 
 
264
  res["standard_peak_vram_mb"] = round(torch.cuda.max_memory_allocated() / (1024*1024), 2)
265
- del K, V, Q_std
266
  except Exception as e:
267
- res["standard_peak_vram_mb"] = f"OOM or Error: {str(e)}"
268
 
269
  results.append(res)
270
 
 
237
  for seq_len in ctx_lengths:
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
+
256
+ for p_attn in phase_layers:
257
+ _ = p_attn.forward(Q_layer)
258
+
259
  res["kalpana_peak_vram_mb"] = round(torch.cuda.max_memory_allocated() / (1024*1024), 2)
260
+ del phase_layers, Q_layer
261
  except Exception as e:
262
+ res["kalpana_peak_vram_mb"] = f"OOM: {str(e)[:50]}..."
 
263
 
264
+ # 2. Profile Standard SDPA (Full 24 Layers)
265
  torch.cuda.empty_cache()
266
  torch.cuda.reset_peak_memory_stats()
267
  try:
268
+ K_list, V_list = [], []
269
+ Q_std = torch.randn(1, num_heads, 1, head_dim, device=device)
 
 
270
  import torch.nn.functional as F
271
+
272
+ for i in range(num_layers):
273
+ K = torch.randn(1, num_heads, seq_len, head_dim, device=device)
274
+ V = torch.randn(1, num_heads, seq_len, head_dim, device=device)
275
+ K_list.append(K)
276
+ V_list.append(V)
277
+ _ = F.scaled_dot_product_attention(Q_std, K, V)
278
+
279
  res["standard_peak_vram_mb"] = round(torch.cuda.max_memory_allocated() / (1024*1024), 2)
280
+ del K_list, V_list, Q_std
281
  except Exception as e:
282
+ res["standard_peak_vram_mb"] = f"OOM: {str(e)[:50]}..."
283
 
284
  results.append(res)
285