CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[PHI] implement masked_fill_op and optimize bool setitem indexing #72788
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
[PHI] implement masked_fill_op and optimize bool setitem indexing #72788
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
@@ -0,0 +1,114 @@ | |||
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. |
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.
// Copyright (c) 2025
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.
done
python/paddle/tensor/manipulation.py
Outdated
@@ -6433,8 +6432,7 @@ def masked_fill_( | |||
if np.isscalar(value): | |||
value = paddle.full([], value, x.dtype) | |||
|
|||
mask = paddle.logical_not(mask) | |||
out = paddle.where_(mask, x, value) | |||
out = _C_ops.masked_fill(x, mask, value) |
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.
这里得是masked_fill_
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.
done
|
||
namespace phi { | ||
namespace funcs { | ||
inline bool CanShortCutMaskFill(const DDim& input_dim, const DDim& mask_dim) { |
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.
这里换个体现函数实际比对功能的名字比较好
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.
done
inline static bool MaskedFillDispatching(const paddle::Tensor& tensor, | ||
const paddle::Tensor& value, | ||
std::vector<paddle::Tensor>* indices) { | ||
if (value.numel() != 1) return 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.
mask_fill kernel 只支持value 是单值的?
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.
根据python/paddle/tensor/manipulation.py中对masked_fill参数定义:
value (Scalar or 0-D Tensor): The value used to fill the target tensor.
因此只有value为单值时才可以使用masked_fill
auto x_grad_dims = x_grad->dims(); | ||
auto mask_dims = mask.dims(); |
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.
这种一般用 const auto&,避免拷贝开销
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.
好的,后面会提交pr修改
auto x_dims = x.dims(); | ||
auto mask_dims = mask.dims(); |
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.
同上
15e2e47
into
PaddlePaddle:develop
PR Category
Performance Optimization
PR Types
Improvements
Description
pcard-67164
Kernel Optimization
Masked_Fill forward kernel performance
Masked_Fill backward kernel performance
Logical Optimization
SetItem forward performance
SetItem backward performance