Skip to content

Fix: use cu_chunk instead of cu_seqlens for flash_attn during corner case where top-k equals 1 #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions moba/moba_efficient.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,14 @@ def moba_attn_varlen(
moba_topk = min(moba_topk - 1, num_filtered_chunk)
need_moba_attn = moba_topk > 0

self_attn_cu_seqlen = cu_chunk

# corner case: if no moba attn needed, just return self attn
if not need_moba_attn:
return flash_attn_varlen_func(
q, k, v, cu_seqlens, cu_seqlens, max_seqlen, max_seqlen, causal=True
q, k, v, self_attn_cu_seqlen, self_attn_cu_seqlen, max_seqlen, max_seqlen, causal=True
)

self_attn_cu_seqlen = cu_chunk

# filtered_kv is a dense matrix that only contains filtered chunk of kv
filtered_kv_indices = torch.arange(
0, moba_chunk_size, dtype=torch.int32, device=q.device
Expand Down