Skip to content
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

Merged
merged 33 commits into from
Nov 27, 2024

Conversation

PolaKuma
Copy link
Contributor

@PolaKuma PolaKuma commented Nov 18, 2024

PR Category

User Experience

PR Types

New features

Description

Paddle Tensor 规范化:新增paddle.vecdot , paddle.linalg.vecdot,复用函数paddle.linalg.dot

Copy link

paddle-bot bot commented Nov 18, 2024

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Nov 18, 2024
[32, 64])

"""
return dot(x, y)
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omg sry,已修改,谢谢佬更正!

Copy link
Contributor

@HydrogenSulfate HydrogenSulfate Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 这是新增的API,不是OP,参考这几个文件写一下单测
    image

  2. 文件名建议改成test_linalg_vecdot.py

@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Nov 19, 2024
test/legacy_test/test_linalg_vecdot.py Show resolved Hide resolved
test/legacy_test/test_linalg_vecdot.py Outdated Show resolved Hide resolved
python/paddle/tensor/linalg.py Outdated Show resolved Hide resolved
python/paddle/tensor/linalg.py Outdated Show resolved Hide resolved
python/paddle/tensor/linalg.py Outdated Show resolved Hide resolved
@HydrogenSulfate
Copy link
Contributor

麻烦解决一下conflict

Comment on lines +123 to +127
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)
Copy link
Contributor

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):
Copy link
Contributor

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):
Copy link
Contributor

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",
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已加

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已加

这里是不是忘记加了?
image

@HydrogenSulfate
Copy link
Contributor

建议不要在网页上编辑,还是本地经过pre-commit比较好呢,
image

Comment on lines 1894 to 1907
>>> 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])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看下样例代码的输出的空格缩进是否与实际输出完全一致:
image

@PolaKuma
Copy link
Contributor Author

@HydrogenSulfate 应该可以了,老师您再看看ww



class VecDotTestCaseTypePromotion2(unittest.TestCase):
def test_float64_complex64_promotion(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个也是,所有complex类型的都加上对xpu的skip,否则CI过不了

Comment on lines 1895 to 1908
>>> 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])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

样例代码的输出部分,缩进修改一下,不然example code检测挂了:
image

@HydrogenSulfate
Copy link
Contributor

@PolaKuma 注意文档格式:尤其是缩进空格和末尾的小数点,建议手动运行一下样例代码,然后把终端里的输出粘贴上去
image

@HydrogenSulfate
Copy link
Contributor

HydrogenSulfate commented Nov 26, 2024

@PolaKuma 缩进空格也要相同,32的"3"要跟上面的"s"对齐

@PolaKuma
Copy link
Contributor Author

@PolaKuma 缩进空格也要相同,32的"3"要跟上面的"s"对齐

我换一个例子好了🥲我本地跑都没问题呜呜

@HydrogenSulfate HydrogenSulfate changed the title 【SCU】【Paddle Tensor No.25】新增paddle.vecdot , paddle.linalg.vecdot,复用函数paddle.linalg.dot 【SCU】【Paddle Tensor No.25】新增paddle.vecdot , paddle.linalg.vecdot Nov 27, 2024
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMeow 🐾

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@HydrogenSulfate HydrogenSulfate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants