Skip to content

Conversation

@enkilee
Copy link
Contributor

@enkilee enkilee commented Jul 24, 2025

PR Category

Execute Infrastructure

PR Types

Bug fixes

Description

#73692

In pytorch:

import torch

x_cpu = torch.tensor([1, 1, float('nan'), float('nan')], dtype=torch.float32)
unique_cpu, counts_cpu = torch.unique(x_cpu, return_counts=True)
print("CPU Result:", unique_cpu, counts_cpu)

if torch.cuda.is_available():
    x_gpu = x_cpu.cuda()
    unique_gpu, counts_gpu = torch.unique(x_gpu, return_counts=True)
    print("GPU Result:", unique_gpu.cpu(), counts_gpu.cpu())
else:
    print("GPU not available")

The result is below:

CPU Result: tensor([1., nan, nan]) tensor([2, 1, 1])
GPU Result: tensor([1., nan, nan]) tensor([2, 1, 1])

So the value on pytorch when use cpu is same as gpu.

In paddle, maybe in the unique_functor.h:

std::set<InT> unique(in_data, in_data + in.numel());

The comparison behavior of std::set is undefined for NaN, which may lead to inconsistent results.

So try to fix it.

@paddle-bot
Copy link

paddle-bot bot commented Jul 24, 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 Jul 24, 2025
@luotao1 luotao1 added the HappyOpenSource 快乐开源活动issue与PR label Jul 24, 2025
@luotao1
Copy link
Contributor

luotao1 commented Jul 30, 2025

@ddchenhao66 审核下

@paddle-ci-bot
Copy link

paddle-ci-bot bot commented Aug 2, 2025

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

@enkilee
Copy link
Contributor Author

enkilee commented Aug 4, 2025

/re-run all-failed

@enkilee
Copy link
Contributor Author

enkilee commented Aug 8, 2025

/re-run all-failed

@luotao1 luotao1 merged commit 6fd3b71 into PaddlePaddle:develop Aug 11, 2025
107 of 110 checks passed
Enigmatisms pushed a commit to Enigmatisms/Paddle that referenced this pull request Aug 11, 2025
maxiaolong001 pushed a commit to maxiaolong001/Paddle that referenced this pull request Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers HappyOpenSource 快乐开源活动issue与PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants