Skip to content

Conversation

@ccsuzzh
Copy link
Contributor

@ccsuzzh ccsuzzh commented Jun 18, 2025

PR Category

Execute Infrastructure

PR Types

Improvements

Description

infermeta修改设置维度
修改cpu/gpu kernel
当0-size Tensor时, out tensor的shape与输入保持一致(与torch保持一致)

PaddleAPITest测试通过
image

@paddle-bot
Copy link

paddle-bot bot commented Jun 18, 2025

你的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 Jun 18, 2025
@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Jun 19, 2025
@DanielSun11
Copy link
Contributor

paddleAPITest回测请优先使用accuracy模式( --accuracy=True),校验输出是否和torch一致

@ccsuzzh
Copy link
Contributor Author

ccsuzzh commented Jun 19, 2025

paddleAPITest回测请优先使用accuracy模式( --accuracy=True),校验输出是否和torch一致

因为paddle.unique_consecutive(Tensor([0],"float64"), return_inverse=True, return_counts=True, )输出shape刚刚全部都[0],所以没有回测出来。

@ccsuzzh
Copy link
Contributor Author

ccsuzzh commented Jun 20, 2025

/re-run all-failed

Comment on lines +5922 to +5934
if (axis.empty()) {
out->set_dims({0});
if (return_inverse) {
index->set_dims(in_dims);
}
} else {
out->set_dims(in_dims);
if (return_inverse) {
index->set_dims({0});
}
}
if (return_counts) {
counts->set_dims({0});
Copy link
Contributor

Choose a reason for hiding this comment

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

这个地方还是有些疑问。
out->set_dims({0}) 设置完后,tensor的shape是不是[0] ? shape [0] 和shape[ ] 是两个不同的shape,shape [0]的dims().size() 为1,是1d Tensor,尽管是0-size。shape [ ]的dims().size() 为0,是0d Tensor也是个标量。 试试out->set_dims({}),让tensor的shape为[ ]
请把

import torch
x = torch.randn([0,1,2])
output, inverse, counts = torch.unique_consecutive(x, return_inverse=True,return_counts=True)
print("x ",x)
print("output ",output)
print("inverse ",inverse)
print("counts ",counts)

转化为paddle的代码,跑一下,将结果贴到PR描述里。

@DanielSun11
Copy link
Contributor

请注意如下三种情况:

case1

import torch
x = torch.randn([0,1,2])
output, inverse, counts = torch.unique_consecutive(x, return_inverse=True,return_counts=True,dim = 0)
print("x ",x)
print("output ",output)
print("inverse ",inverse)
print("counts ",counts)

输出:

x  tensor([], size=(0, 1, 2))
output  tensor([], size=(0, 1, 2))
inverse  tensor([], dtype=torch.int64)
counts  tensor([], dtype=torch.int64)

case2

import torch
x = torch.randn([0,1,2])
output, inverse, counts = torch.unique_consecutive(x, return_inverse=True,return_counts=True)
print("x ",x)
print("output ",output)
print("inverse ",inverse)
print("counts ",counts)

输出:

x  tensor([], size=(0, 1, 2))
output  tensor([])
inverse  tensor([], size=(0, 1, 2), dtype=torch.int64)
counts  tensor([], dtype=torch.int64)

case3

import torch
x = torch.randn([0,1,2])
output, inverse, counts = torch.unique_consecutive(x, return_inverse=True,return_counts=True,dim=1)
print("x ",x)
print("output ",output)
print("inverse ",inverse)
print("counts ",counts)

输出:报错paddle error

Traceback (most recent call last):
  File "/home/code/test/test_unique.py", line 3, in <module>
    output, inverse, counts = torch.unique_consecutive(x, return_inverse=True,return_counts=True,dim=1)
  File "/usr/local/lib/python3.10/dist-packages/torch/_jit_internal.py", line 622, in fn
    return if_true(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/torch/_jit_internal.py", line 622, in fn
    return if_true(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/torch/functional.py", line 1046, in _unique_consecutive_impl
    output, inverse_indices, counts = _VF.unique_consecutive(  # type: ignore[attr-defined]
RuntimeError: There are 0 sized dimensions, and they aren't selected, so unique cannot be applied

请验证修复后如下三种情形的输出,并告知输出结果~

@DanielSun11
Copy link
Contributor

image

使用paddleAPITest在CPU和GPU上使用accuracy模式,跑如下测试case,非0size的Tensor不要求进行回测:

paddle.unique_consecutive(Tensor([0],"float64"), return_inverse=True, return_counts=True, )
paddle.unique_consecutive(Tensor([0],"float64"), return_inverse=True, return_counts=True, axis=-1, )
paddle.unique_consecutive(x=Tensor([0, 1],"float32"), return_inverse=True, )
paddle.unique_consecutive(x=Tensor([0, 1],"float32"), return_inverse=True, return_counts=True, )
paddle.unique_consecutive(x=Tensor([0, 4],"float32"), return_inverse=True, return_counts=True, axis=0, )
paddle.unique_consecutive(x=Tensor([3, 0],"float64"), axis=1, )
paddle.unique_consecutive(x=Tensor([4, 0],"float32"), return_inverse=True, )
paddle.unique_consecutive(x=Tensor([6, 0],"float32"), return_inverse=True, return_counts=True, )

@paddle-ci-bot
Copy link

paddle-ci-bot bot commented Jun 30, 2025

Sorry to inform you that 73bb142's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

@DanielSun11
Copy link
Contributor

已经被 #74305 修复

@ccsuzzh ccsuzzh deleted the 0-size_355 branch July 31, 2025 09:26
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.

3 participants