ajsbsd commited on
Commit
14b4780
·
verified ·
1 Parent(s): fd6e294

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -21
app.py CHANGED
@@ -44,30 +44,16 @@ def patch_fa3_module():
44
  orig_fa_forward = module._flash_attention_forward
45
 
46
  def patched_fa_forward(
47
- query_states,
48
- key_states,
49
- value_states,
50
- attention_mask,
51
- query_length,
52
- is_causal,
53
- dropout=0.0,
54
- position_ids=None,
55
- softmax_scale=None,
56
- sliding_window=None,
57
- use_top_left_mask=False,
58
- softcap=None,
59
- deterministic=None,
60
- cu_seq_lens_q=None,
61
- cu_seq_lens_k=None,
62
- max_length_q=None,
63
- max_length_k=None,
64
- target_dtype=None,
65
- **kwargs,
66
  ):
67
  # FIX: Override cu_seq_lens to perfectly match the actual number of tokens in query_states
68
  if cu_seq_lens_q is not None and query_states is not None:
69
- # query_states shape at this point is (batch_size, num_heads, q_len, head_dim)
70
- total_tokens = query_states.shape[0] * query_states.shape[2]
71
 
72
  cu_seq_lens_q = torch.tensor([0, total_tokens], device=query_states.device, dtype=torch.int32)
73
  cu_seq_lens_k = torch.tensor([0, total_tokens], device=key_states.device, dtype=torch.int32)
 
44
  orig_fa_forward = module._flash_attention_forward
45
 
46
  def patched_fa_forward(
47
+ query_states, key_states, value_states, attention_mask, query_length, is_causal,
48
+ dropout=0.0, position_ids=None, softmax_scale=None, sliding_window=None,
49
+ use_top_left_mask=False, softcap=None, deterministic=None,
50
+ cu_seq_lens_q=None, cu_seq_lens_k=None, max_length_q=None,
51
+ max_length_k=None, target_dtype=None, **kwargs,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  ):
53
  # FIX: Override cu_seq_lens to perfectly match the actual number of tokens in query_states
54
  if cu_seq_lens_q is not None and query_states is not None:
55
+ # Flash Attention expects: (batch_size, q_len, num_heads, head_dim)
56
+ total_tokens = query_states.shape[0] * query_states.shape[1]
57
 
58
  cu_seq_lens_q = torch.tensor([0, total_tokens], device=query_states.device, dtype=torch.int32)
59
  cu_seq_lens_k = torch.tensor([0, total_tokens], device=key_states.device, dtype=torch.int32)