Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
flash-attention
Commits
29956362
Commit
29956362
authored
Jul 23, 2024
by
Tri Dao
Browse files
Fix test with alibi and cache_leftpad
parent
4488acee
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
2 deletions
+6
-2
tests/test_flash_attn.py
tests/test_flash_attn.py
+6
-2
No files found.
tests/test_flash_attn.py
View file @
29956362
...
...
@@ -27,7 +27,7 @@ is_sm90 = torch.cuda.get_device_capability("cuda") == (9, 0)
def
attn_bias_from_alibi_slopes
(
slopes
,
seqlen_q
,
seqlen_k
,
query_padding_mask
=
None
,
key_padding_mask
=
None
,
causal
=
False
slopes
,
seqlen_q
,
seqlen_k
,
query_padding_mask
=
None
,
key_padding_mask
=
None
,
causal
=
False
,
key_leftpad
=
None
):
batch
,
nheads
=
slopes
.
shape
device
=
slopes
.
device
...
...
@@ -37,6 +37,10 @@ def attn_bias_from_alibi_slopes(
else
:
row_idx
=
rearrange
(
torch
.
arange
(
seqlen_q
,
device
=
device
,
dtype
=
torch
.
long
),
"s -> s 1"
)
col_idx
=
torch
.
arange
(
seqlen_k
,
device
=
device
,
dtype
=
torch
.
long
)
if
key_leftpad
is
not
None
:
key_leftpad
=
rearrange
(
key_leftpad
,
"b -> b 1 1 1"
)
col_idx
=
repeat
(
col_idx
,
"s -> b 1 1 s"
,
b
=
key_leftpad
.
shape
[
0
])
col_idx
=
torch
.
where
(
col_idx
>=
key_leftpad
,
col_idx
-
key_leftpad
,
2
**
32
)
sk
=
(
seqlen_k
if
key_padding_mask
is
None
...
...
@@ -1993,7 +1997,7 @@ def test_flash_attn_kvcache(
if
alibi
:
alibi_slopes
=
torch
.
rand
(
batch_size
,
nheads
,
device
=
device
,
dtype
=
torch
.
float32
)
*
0.3
attn_bias
=
attn_bias_from_alibi_slopes
(
alibi_slopes
,
seqlen_q
,
seqlen_k
,
None
,
key_padding_mask
,
causal
=
causal
alibi_slopes
,
seqlen_q
,
seqlen_k
,
None
,
key_padding_mask
,
causal
=
causal
,
key_leftpad
=
cache_leftpad
)
else
:
alibi_slopes
,
attn_bias
=
None
,
None
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment