CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[XPU] support flash attention for xpu when causal is false #63644
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
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
|
||
const float* bias_data = nullptr; | ||
if (attn_mask.get_ptr() != nullptr) { | ||
bias_data = attn_mask->data<float>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
由于fa接口中暂不支持attn_mask,因此通过attn_mask获取数据并作为bias传入
@@ -246,6 +243,10 @@ void FlashAttnKernel(const Context& ctx, | |||
XPUType* out_data = reinterpret_cast<XPUType*>(out->data<T>()); | |||
float* softmax_lse_data = softmax_lse->data<float>(); | |||
|
|||
const float* bias_data = nullptr; | |||
if (attn_mask.get_ptr() != nullptr) { | |||
bias_data = attn_mask->data<float>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
@@ -39,9 +39,6 @@ void FlashAttnGradKernel(const Context& ctx, | |||
DenseTensor* dk, | |||
DenseTensor* dv) { | |||
#ifdef PADDLE_WITH_XPU_XHPC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前fa已支持is_causal=false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -121,7 +121,11 @@ void FlashAttnGradKernel(const Context& ctx, | |||
num_heads_k, // head_num_k | |||
head_size, // head_dim | |||
1.0f / std::sqrt(head_size), // softmax_scale | |||
dropout // p_dropout | |||
dropout, // p_dropout | |||
0x45678901, // seed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是否提供一种控制seed的方式?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已根据GPU的实现补上了这个功能
#include "paddle/phi/backends/xpu/enforce_xpu.h" | ||
#include "paddle/phi/core/enforce.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个不需要吧?因为paddle/phi/backends/xpu/enforce_xpu.h里面包括了paddle/phi/core/enforce.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
下一个版本需要做:
1、不需要的include干掉
2、增加对应的单测
…dle#63644) * [XPU] support flash attention when causal=false * support generate seed from input params like gpu
PR Category
Operator Mechanism
PR Types
New features
Description
support flash attention for xpu when causal is false,and enable pass bias as attn_mask