intel / torch-xpu-ops

Apache License 2.0
30 stars 21 forks source link

sort bool type has issue #1022

Closed guizili0 closed 3 weeks ago

guizili0 commented 3 weeks ago

🐛 Describe the bug

import torch
import random

torch.manual_seed(0)
random.seed(0)

xpu_device = torch.device("xpu")
cpu_device = torch.device("cpu")

#tensor_dtype = torch.int64
tensor_dtype = torch.bool
value_range = 2
a = torch.randint(value_range, (4099,)).to(dtype=tensor_dtype).to(xpu_device)

print(a)
print(a.shape)

for dim in reversed(range(a.dim())):
    #output, output_indices = torch.mode(a, dim)
    #print(output)
    sorted, indices = torch.sort(a)
    print(sorted)
    sorted, indices = a.sort()
    print(sorted)
    sorted, indices = a.sort(stable=True)
    print(sorted)
    sorted_cpu, indices = torch.sort(a.to(cpu_device))
    res = torch.equal(sorted.to(cpu_device), sorted_cpu)
    print(res)

Versions

sort result is wrong:

tensor([False, True, True, ..., False, True, True], device='xpu:0') torch.Size([4099]) tensor([False, True, True, ..., False, False, False], device='xpu:0') tensor([False, True, True, ..., False, False, False], device='xpu:0') tensor([False, True, True, ..., False, False, False], device='xpu:0') False