Oneflow-Inc / oneflow

OneFlow is a deep learning framework designed to be user-friendly, scalable and efficient.
http://www.oneflow.org
Apache License 2.0
5.79k stars 658 forks source link

oneflow.argsort perform differently between cpu and cuda when dim=1 #10476

Open Redmept1on opened 3 months ago

Redmept1on commented 3 months ago

Summary

oneflow.argsort perform differently between cpu and cuda when dim=1, cuda=pytorch, cpu not

Code to reproduce bug

import oneflow as flow
import numpy as np

x1 = flow.tensor(np.array([[float('inf'), 0, -1, float('nan'), 5]], dtype=np.float32))
x1 = x1.cuda()
y1 = flow.argsort(x1,dim=1)
print(y1)

x1 = flow.tensor(np.array([[float('inf'), 0, -1, float('nan'), 5]], dtype=np.float32))
x1 = x1.cpu()
y2 = flow.argsort(x1,dim=1)
print(y2)

image

pytorch

import torch
import numpy as np

input_tensor = torch.tensor(np.array([[float('inf'), 0, -1, float('nan'), 5]], dtype=np.float32))
output_tensors = torch.argsort(input_tensor,dim=1)

print(output_tensors)

image

System Information

Redmept1on commented 3 months ago

oneflow.sort has same bug

Redmept1on commented 3 months ago

oneflow.topk has the same bug

import oneflow as flow
import numpy as np

x1 = flow.tensor(np.array([[float('inf'), 0, -1, float('nan'), 5]], dtype=np.float32))
x1 = x1.cuda()
y1 = flow.topk(x1,k=2,dim=1)
print(y1)

x1 = flow.tensor(np.array([[float('inf'), 0, -1, float('nan'), 5]], dtype=np.float32))
x1 = x1.cpu()
y2 = flow.topk(x1,k=2,dim=1)
print(y2)

image