-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
【SCU】【Paddle Tensor No.25】新增paddle.vecdot
, paddle.linalg.vecdot
#69477
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
python/paddle/tensor/linalg.py
Outdated
[32, 64]) | ||
|
||
""" | ||
return dot(x, y) |
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规范定义,vecdot应该是逐元素乘法后再在axis轴上求和:https://data-apis.org/array-api/latest/API_specification/generated/array_api.vecdot.html#array_api.vecdot
所以可以参考如下实现(复用乘法和sum)
https://github.com/pytorch/pytorch/blob/main/torch/_refs/linalg/__init__.py#L307
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.
omg sry,已修改,谢谢佬更正!
test/legacy_test/test_dot_op.py
Outdated
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.
Co-authored-by: HydrogenSulfate <490868991@qq.com>
Co-authored-by: HydrogenSulfate <490868991@qq.com>
麻烦解决一下conflict |
def test_dtype_mismatch(self): | ||
with self.assertRaises(TypeError): | ||
x = paddle.rand([3, 4], dtype="float32") | ||
y = paddle.rand([3, 4], dtype="int32") | ||
paddle.vecdot(x, y, axis=-1) |
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.
这个单测需要跳过XPU:
@unittest.skipIf(
core.is_compiled_with_xpu(),
"Skip XPU for not support uniform(dtype=int)",
)
paddle.vecdot(x, y, axis=-1) | ||
|
||
|
||
class VecDotTestCaseComplex(unittest.TestCase): |
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.
这个类跳过XPU:
@unittest.skipIf(
core.is_compiled_with_xpu(),
"Skip XPU for not support complex",
)
) | ||
|
||
|
||
class VecDotTestCaseTypePromotion2(unittest.TestCase): |
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.
同上,跳过XPU,
@unittest.skipIf(
core.is_compiled_with_xpu(),
"Skip XPU for not support complex",
)
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.
python/paddle/tensor/linalg.py
Outdated
>>> import paddle | ||
>>> x = paddle.to_tensor([1, 2, 3], dtype='float32') | ||
>>> y = paddle.to_tensor([4, 5, 6], dtype='float32') | ||
>>> result = paddle.linalg.vecdot(x, y) | ||
>>> print(result) | ||
Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True, | ||
[32.0]) | ||
|
||
>>> x2 = paddle.to_tensor([[1, 2, 3], [4, 5, 6]], dtype='float32') | ||
>>> y2 = paddle.to_tensor([[1, 2, 3], [4, 5, 6]], dtype='float32') | ||
>>> result2 = paddle.linalg.vecdot(x2, y2, axis=1) | ||
>>> print(result2) | ||
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True, | ||
[14.0, 77.0]) |
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.
@HydrogenSulfate 应该可以了,老师您再看看ww |
|
||
|
||
class VecDotTestCaseTypePromotion2(unittest.TestCase): | ||
def test_float64_complex64_promotion(self): |
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.
这个也是,所有complex类型的都加上对xpu的skip,否则CI过不了
python/paddle/tensor/linalg.py
Outdated
>>> import paddle | ||
>>> x = paddle.to_tensor([1, 2, 3], dtype='float32') | ||
>>> y = paddle.to_tensor([4, 5, 6], dtype='float32') | ||
>>> result = paddle.linalg.vecdot(x, y) | ||
>>> print(result) | ||
Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True, | ||
[32.0]) | ||
|
||
>>> x2 = paddle.to_tensor([[1, 2, 3], [4, 5, 6]], dtype='float32') | ||
>>> y2 = paddle.to_tensor([[1, 2, 3], [4, 5, 6]], dtype='float32') | ||
>>> result2 = paddle.linalg.vecdot(x2, y2, axis=1) | ||
>>> print(result2) | ||
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True, | ||
[14.0, 77.0]) |
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.
@PolaKuma 注意文档格式:尤其是缩进空格和末尾的小数点,建议手动运行一下样例代码,然后把终端里的输出粘贴上去 |
@PolaKuma 缩进空格也要相同,32的"3"要跟上面的"s"对齐 |
我换一个例子好了🥲我本地跑都没问题呜呜 |
paddle.vecdot
, paddle.linalg.vecdot
,复用函数paddle.linalg.dot
paddle.vecdot
, paddle.linalg.vecdot
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.
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
PR Category
User Experience
PR Types
New features
Description
Paddle Tensor 规范化:新增
paddle.vecdot
,paddle.linalg.vecdot
,复用函数paddle.linalg.dot