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
e5da6e4d
Unverified
Commit
e5da6e4d
authored
May 31, 2024
by
Antoni Baum
Committed by
GitHub
May 31, 2024
Browse files
Fix out kwarg shape check with ngroups swapped (#4)
parent
03bf1f8a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
2 deletions
+8
-2
csrc/flash_attn/flash_api.cpp
csrc/flash_attn/flash_api.cpp
+8
-2
No files found.
csrc/flash_attn/flash_api.cpp
View file @
e5da6e4d
...
...
@@ -726,7 +726,9 @@ mha_fwd_kvcache(at::Tensor &q, // batch_size x seqlen_q x num_he
const
int
batch_size
=
sizes
[
0
];
int
seqlen_q
=
sizes
[
1
];
const
int
seqlen_q_og
=
seqlen_q
;
int
num_heads
=
sizes
[
2
];
const
int
num_heads_og
=
num_heads
;
const
int
head_size_og
=
sizes
[
3
];
const
int
max_num_blocks_per_seq
=
!
paged_KV
?
0
:
block_table
.
size
(
1
);
...
...
@@ -784,8 +786,12 @@ mha_fwd_kvcache(at::Tensor &q, // batch_size x seqlen_q x num_he
TORCH_CHECK
(
out
.
dtype
()
==
q_dtype
,
"Output must have the same dtype as inputs"
);
CHECK_DEVICE
(
out
);
TORCH_CHECK
(
out
.
stride
(
-
1
)
==
1
,
"Output tensor must have contiguous last dimension"
);
CHECK_SHAPE
(
out
,
batch_size
,
seqlen_q
,
num_heads
,
head_size_og
);
if
(
head_size_og
%
8
!=
0
)
{
out
=
torch
::
empty_like
(
q_padded
);
}
CHECK_SHAPE
(
out
,
batch_size
,
seqlen_q_og
,
num_heads_og
,
head_size_og
);
if
(
head_size_og
%
8
!=
0
)
{
out
=
torch
::
empty_like
(
q_padded
);
}
else
if
(
seqlenq_ngroups_swapped
)
{
out
=
out
.
reshape
({
batch_size
,
num_heads
,
seqlen_q
,
head_size_og
}).
transpose
(
1
,
2
);
}
}
else
{
out
=
torch
::
empty_like
(
q_padded
);
}
...
...
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