-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
[Paddle Tensor No.23] 新增TensorA[mask] = TensorB
#69480
[Paddle Tensor No.23] 新增TensorA[mask] = TensorB
#69480
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
paddle/fluid/pybind/eager_method.cc
Outdated
transed_sub_tensor = | ||
index_put__ad_func(transed_sub_tensor, transed_index, value_tensor); |
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.
跟切片API负责人讨论了一下,结论是:
- 原来的where优化是有BUG的,v在不是单个元素的张量的前提下,极大概率不能跟x[mask]进行where计算
- 原先这样写是为了优化
x[mask] = 0-D/1-D Tensor
,即“将单个值赋值给x中mask为True的位置上”,原先的写法就可以把v广播到x的形状上,然后以out = where(mask, x, broadcasted_v)
作为结果,这样速度会比index_put
快一些。
所以是否可以把此处的代码保留,但是把逻辑(判断条件)改一下,让仅含有单个元素的v可以执行
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.
好嘞
@LittleHeroZZZX 我想了下,单测里是否可以考虑v本身可以广播的情况?如下所示 import torch
x = torch.zeros(2, 2, 3)
mask = torch.tensor(
[
[True, False],
[False, True],
],
)
y = torch.arange(1, 4, dtype=torch.float32)
print(x[0, 0])
print(x[0, 1])
print(x[1, 0])
print(x[1, 1])
print(mask)
x[mask] = y
print(x[0, 0])
print(x[0, 1])
print(x[1, 0])
print(x[1, 1]) 可以测试下你这个代码是否能处理 |
这个case测试了没问题,与 PyTorch行为一样。 |
好的,那我先合入了,后面麻烦再提交一个PR,补充一个广播的单测 |
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
hi, @LittleHeroZZZX
|
PR Category
User Experience
PR Types
New features
Description
Paddle Tensor 规范化:修改
Tensor.__setitem__
的 C++ 实现,实现当 index 是布尔类型,且右侧的输入是 Tensor 时的计算逻辑。