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.softmax perform differently between cpu and cuda. #10469

Open Redmept1on opened 3 months ago

Redmept1on commented 3 months ago

Summary

oneflow.softmax perform differently between cpu and cuda.

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.softmax(x1)
print(y1.device,y1)

x1 = flow.tensor(np.array([[float('inf'), 0, -1, float('nan'), 5]], dtype=np.float32))
x1 = x1.cpu()
y2 = flow.softmax(x1)
print(y2.device,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))
# other_tensor = torch.tensor(np.array([[float('nan'), 0, -1, float('nan'), 5]], dtype=np.float32))
output_tensors = torch.nn.functional.softmax(input_tensor)

print(output_tensors)

image

System Information