Skip to content

[Python array API standard] Support Tensor.mT in eager/static mode #68833

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

Merged
merged 4 commits into from
Oct 23, 2024

Conversation

HydrogenSulfate
Copy link
Contributor

@HydrogenSulfate HydrogenSulfate commented Oct 21, 2024

PR Category

User Experience

PR Types

New features

Description

Pcard-75624

根据 https://data-apis.org/array-api/latest/API_specification/generated/array_api.array.mT.html#mt,为动静态图的张量添加 .mT 接口以获取高维张量的矩阵转置

Copy link

paddle-bot bot commented Oct 21, 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.

@HydrogenSulfate HydrogenSulfate changed the title [Ppython array API standard] Support Tensor.mT in eager/static mode [Python array API standard] Support Tensor.mT in eager/static mode Oct 21, 2024
if len(self.shape) == 1:
return self
perm = list(range(len(self.shape)))
perm[-1], perm[-2] = perm[-2], perm[-1]
Copy link
Member

Choose a reason for hiding this comment

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

静态图相关单测需要验证在包含动态 shape 场景下的正确性,包括 shape[-1] = 0shape[-2] = 0shape[-1] = 0shape[-2] = 0 的情况

perm = list(range(len(self.meta.shape)))
perm[-1], perm[-2] = perm[-2], perm[-1]

perm_var = ListVariable(perm, self.graph, tracker=ConstTracker(perm))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
perm_var = ListVariable(perm, self.graph, tracker=ConstTracker(perm))
perm_var = ListVariable(perm, self.graph, tracker=DummyTracker(self))

perm[-1], perm[-2] = perm[-2], perm[-1]

perm_var = ListVariable(perm, self.graph, tracker=ConstTracker(perm))
assert perm_var is not None
Copy link
Member

Choose a reason for hiding this comment

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

这行应该是没有必要的,因为上面的构造函数结果一定是 ListVariable

@@ -90,6 +94,12 @@ def test_middle_tensor_name(self):
y = paddle.rand([42, 24])
self.assert_results(middle_tensor_name, x, y)

def test_tensor_method_property_mT(self):
x = paddle.rand([42, 24], dtype='float64')
y = paddle.rand([42, 24], dtype='float32')
Copy link
Member

Choose a reason for hiding this comment

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

这个换一个更高维的测一下?只改 dtype 好像差别不大

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 🐾

@HydrogenSulfate HydrogenSulfate merged commit bb5d143 into PaddlePaddle:develop Oct 23, 2024
27 checks passed
@HydrogenSulfate HydrogenSulfate deleted the add_mT branch October 23, 2024 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants