-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Closed
Closed
Copy link
Labels
Description
bug描述 Describe the Bug
When using paddle.unique on a tensor containing NaN values, the function produces different results depending on whether the operation is performed on the CPU or the GPU.
On the CPU, paddle.unique treats all NaN values as a single unique entity and they are collapsed into one, with their counts aggregated.
On the GPU, paddle.unique treats each NaN value as a distinct and unique entity. This leads to an output tensor where each NaN from the input is preserved as a unique element, and their corresponding counts are all 1.
import paddle
paddle.set_device('cpu')
x = paddle.to_tensor([1, 1, paddle.nan, paddle.nan])
res = paddle.unique(x, return_counts=True)
print(res)
paddle.set_device('gpu:0')
x_gpu = paddle.to_tensor([1, 1, paddle.nan, paddle.nan])
res_gpu = paddle.unique(x_gpu, return_counts=True)
print(res_gpu)
(Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
[1.]), Tensor(shape=[1], dtype=int64, place=Place(cpu), stop_gradient=True,
[2]))
(Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
[1. , nan, nan]), Tensor(shape=[3], dtype=int64, place=Place(gpu:0), stop_gradient=True,
[2, 1, 1]))
其他补充信息 Additional Supplementary Information
No response