Skip to content

Commit 1c726f3

Browse files
Fix (#154)
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
1 parent 2c839c3 commit 1c726f3

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

flash_attn/cute/mask.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ def apply_mask(
323323
col_limit_right = row_idx + local_row_offset_right
324324
else:
325325
col_limit_right = self.tile_n
326+
if const_expr(self.dynamic_causal is not None):
327+
col_limit_right = (
328+
row_idx + causal_row_offset
329+
if self.dynamic_causal
330+
else col_limit_right
331+
)
326332
if const_expr(mask_seqlen):
327333
col_limit_right = cutlass.min(col_limit_right, seqlenk_col_limit)
328334
col_limit_left = (
@@ -382,6 +388,17 @@ def mask_gen_fn(s: int) -> Uint32:
382388
else 0
383389
)
384390
)
391+
if const_expr(self.dynamic_causal is not None):
392+
causal_row_limit_top = (
393+
self.tile_m
394+
if col0 >= seqlenk_col_limit and mask_seqlen
395+
else col0 - causal_row_offset
396+
)
397+
row_limit_top = (
398+
causal_row_limit_top
399+
if self.dynamic_causal
400+
else row_limit_top
401+
)
385402
row_limit_bot = (
386403
col0 - causal_row_offset + self.window_size_left
387404
if const_expr(self.window_size_left is not None)

0 commit comments

Comments
 (0)