Commit 4564b2f5 authored by zhuwenwen's avatar zhuwenwen
Browse files

update prefix cache interface and vdim padding strategy

parent b99b5676
...@@ -535,23 +535,37 @@ class MLACommonImpl(MLAAttentionImpl[T], Generic[T]): ...@@ -535,23 +535,37 @@ class MLACommonImpl(MLAAttentionImpl[T], Generic[T]):
# v with 0s to match the qk head dim # v with 0s to match the qk head dim
# v_padded = torch.nn.functional.pad(v, [0, q.shape[-1] - v.shape[-1]], # v_padded = torch.nn.functional.pad(v, [0, q.shape[-1] - v.shape[-1]],
# value=0) # value=0)
v_padded = torch.nn.functional.pad(v, [0, (q.shape[-1] - v.shape[-1]-32)],
attn_output = flash_attn_varlen_func( value=0)
q=q,
k=k, if torch.cuda.get_device_properties(torch.cuda.current_device()).multi_processor_count == 120:
# v=v_padded, attn_output = flash_attn_varlen_func(
v=v, q=q,
cu_seqlens_q=seq_start_loc, k=k,
cu_seqlens_k=seq_start_loc, v=v_padded,
max_seqlen_q=max_prefill_seq_len, cu_seqlens_q=seq_start_loc,
max_seqlen_k=max_prefill_seq_len, cu_seqlens_k=seq_start_loc,
softmax_scale=self.scale, max_seqlen_q=max_prefill_seq_len,
causal=True, max_seqlen_k=max_prefill_seq_len,
) softmax_scale=self.scale,
# attn_output = attn_output\ causal=True,
# .view(-1, self.num_heads, q.shape[-1])[..., :v.shape[-1]]\ )
# .reshape(-1, self.num_heads * v.shape[-1]) attn_output = attn_output\
attn_output = attn_output\ .view(-1, self.num_heads, q.shape[-1])[..., :v.shape[-1]]\
.reshape(-1, self.num_heads * v.shape[-1]) .reshape(-1, self.num_heads * v.shape[-1])
else:
attn_output = flash_attn_varlen_func(
q=q,
k=k,
v=v,
cu_seqlens_q=seq_start_loc,
cu_seqlens_k=seq_start_loc,
max_seqlen_q=max_prefill_seq_len,
max_seqlen_k=max_prefill_seq_len,
softmax_scale=self.scale,
causal=True,
)
attn_output = attn_output\
.reshape(-1, self.num_heads * v.shape[-1])
return self.o_proj(attn_output)[0] return self.o_proj(attn_output)[0]
...@@ -790,6 +790,7 @@ class ROCmFlashAttentionImpl(AttentionImpl): ...@@ -790,6 +790,7 @@ class ROCmFlashAttentionImpl(AttentionImpl):
prefill_meta.block_tables, prefill_meta.block_tables,
prefill_meta.query_start_loc, prefill_meta.query_start_loc,
prefill_meta.seq_lens_tensor, prefill_meta.seq_lens_tensor,
prefill_meta.context_lens_tensor,
prefill_meta.max_query_len, prefill_meta.max_query_len,
self.alibi_slopes, self.alibi_slopes,
self.sliding_window[0], self.sliding_window[0],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment