Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
16f69e7a
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2301
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
16f69e7a
编写于
4月 29, 2023
作者:
C
Chitsing KUI
提交者:
GitHub
4月 29, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
extend num_split for flash attn (#53402)
Co-authored-by:
N
sneaxiy
<
32832641+sneaxiy@users.noreply.github.com
>
上级
8e63a960
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
28 addition
and
1 deletion
+28
-1
cmake/external/flashattn.cmake
cmake/external/flashattn.cmake
+1
-1
paddle/phi/kernels/gpu/flash_attn_grad_kernel.cu
paddle/phi/kernels/gpu/flash_attn_grad_kernel.cu
+14
-0
paddle/phi/kernels/gpu/flash_attn_kernel.cu
paddle/phi/kernels/gpu/flash_attn_kernel.cu
+13
-0
未找到文件。
cmake/external/flashattn.cmake
浏览文件 @
16f69e7a
...
...
@@ -20,7 +20,7 @@ set(FLASHATTN_PREFIX_DIR ${THIRD_PARTY_PATH}/flashattn)
set
(
FLASHATTN_SOURCE_SUBDIR csrc/flash_attn
)
set
(
FLASHATTN_INSTALL_DIR
${
THIRD_PARTY_PATH
}
/install/flashattn
)
set
(
FLASHATTN_REPOSITORY
${
GIT_URL
}
/PaddlePaddle/flash-attention.git
)
set
(
FLASHATTN_TAG
f0edf243a813a65d05c75fcb331b2a95faf96bbc
)
set
(
FLASHATTN_TAG
5ff4bbf56ad066750407c4aef16ac740ebda0717
)
set
(
FLASHATTN_INCLUDE_DIR
"
${
FLASHATTN_INSTALL_DIR
}
/include"
...
...
paddle/phi/kernels/gpu/flash_attn_grad_kernel.cu
浏览文件 @
16f69e7a
...
...
@@ -13,8 +13,10 @@
// limitations under the License.
#include "paddle/phi/kernels/flash_attn_grad_kernel.h"
#include "glog/logging.h" // For VLOG()
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/common/bfloat16.h"
#include "paddle/phi/core/flags.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
#include "paddle/phi/kernels/arange_kernel.h"
...
...
@@ -25,6 +27,8 @@
#include "paddle/phi/backends/dynload/flashattn.h"
#endif
DECLARE_bool
(
cudnn_deterministic
);
namespace
phi
{
template
<
typename
T
,
typename
Context
>
...
...
@@ -67,10 +71,17 @@ void FlashAttnUnpaddedGradKernel(const Context& ctx,
int
num_splits
=
0
;
// 0 for an internal heuristic, which is optimal
bool
zero_tensors
=
false
;
if
(
FLAGS_cudnn_deterministic
)
{
num_splits
=
1
;
}
const
int64_t
*
seed_offset_data
=
seed_offset
.
data
<
int64_t
>
();
uint64_t
seed
=
static_cast
<
uint64_t
>
(
seed_offset_data
[
0
]);
uint64_t
offset
=
static_cast
<
uint64_t
>
(
seed_offset_data
[
1
]);
VLOG
(
4
)
<<
"FlashAttn bwd seed: "
<<
seed
<<
", offset: "
<<
offset
<<
", num_splits:"
<<
num_splits
;
int64_t
seq_len_q
=
((
max_seqlen_q
+
16
-
1
)
/
16
)
*
16
;
DenseTensor
dsoftmax
=
Empty
<
float
>
(
ctx
,
{
batch_size
,
num_heads
,
seq_len_q
});
...
...
@@ -187,6 +198,9 @@ void FlashAttnGradKernel(const Context& ctx,
float
scale
=
1.0
f
/
std
::
sqrt
(
head_size
);
VLOG
(
4
)
<<
"FlashAttn bwd dims q["
<<
q
.
dims
()
<<
"], k["
<<
k
.
dims
()
<<
"], v["
<<
v
.
dims
()
<<
"]"
;
DenseTensor
q_t_s
,
k_t_s
,
v_t_s
;
q_t_s
.
ShareDataWith
(
q
).
Resize
({
total_q
,
num_heads
,
head_size
});
k_t_s
.
ShareDataWith
(
k
).
Resize
({
total_k
,
num_heads
,
head_size
});
...
...
paddle/phi/kernels/gpu/flash_attn_kernel.cu
浏览文件 @
16f69e7a
...
...
@@ -14,9 +14,11 @@
#include "paddle/phi/kernels/flash_attn_kernel.h"
#include "glog/logging.h" // For VLOG()
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/common/data_type.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/phi/core/flags.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/core/tensor_utils.h"
...
...
@@ -28,6 +30,8 @@
#include "paddle/phi/backends/dynload/flashattn.h"
#endif
DECLARE_bool
(
cudnn_deterministic
);
namespace
phi
{
template
<
typename
T
,
typename
Context
>
...
...
@@ -73,6 +77,9 @@ void FlashAttnUnpaddedKernel(const Context& ctx,
int64_t
batch_size
=
cu_seqlens_q
.
numel
()
-
1
;
int
num_splits
=
0
;
// 0 for an internal heuristic, which is optimal
if
(
FLAGS_cudnn_deterministic
)
{
num_splits
=
1
;
}
bool
zero_tensors
=
false
;
auto
gen
=
ctx
.
GetGenerator
();
...
...
@@ -82,6 +89,9 @@ void FlashAttnUnpaddedKernel(const Context& ctx,
uint64_t
seed
=
seed_offset_pair
.
first
;
uint64_t
offset
=
seed_offset_pair
.
second
;
VLOG
(
4
)
<<
"FlashAttn fwd seed: "
<<
seed
<<
", offset: "
<<
offset
<<
", num_splits:"
<<
num_splits
;
seed_offset
->
Resize
({
2
});
auto
*
seed_offset_data
=
ctx
.
template
HostAlloc
<
int64_t
>(
seed_offset
);
seed_offset_data
[
0
]
=
static_cast
<
int64_t
>
(
seed
);
...
...
@@ -217,6 +227,9 @@ void FlashAttnKernel(const Context& ctx,
float
scale
=
1.0
f
/
std
::
sqrt
(
head_size
);
VLOG
(
4
)
<<
"FlashAttn fwd dims q["
<<
q
.
dims
()
<<
"], k["
<<
k
.
dims
()
<<
"], v["
<<
v
.
dims
()
<<
"]"
;
DenseTensor
q_t_s
,
k_t_s
,
v_t_s
;
q_t_s
.
ShareDataWith
(
q
).
Resize
({
total_q
,
num_heads
,
head_size
});
k_t_s
.
ShareDataWith
(
k
).
Resize
({
total_k
,
num_heads
,
head_size
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录