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.88k stars 667 forks source link

When there is a negative number in index, 'oneflow.index_select' should throw an error message instead of core dumped #10460

Open Redmept1on opened 6 months ago

Redmept1on commented 6 months ago

Summary

When there is a negative number in index, 'oneflow.index_select' should throw an error message instead of core dumped

Code to reproduce bug

oneflow

import oneflow as flow
import numpy as np

input_tensor = flow.tensor(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=np.float32))

index_tensor = flow.tensor([-1])

# Select elements from the input tensor along dimension 1
output_tensor = flow.index_select(input_tensor, dim=-2, index=index_tensor)

# Print the output tensor
print("OneFlow Tensor:\n", output_tensor)

image pytorch

import torch
import numpy as np

# Create an input tensor
input_tensor = torch.tensor(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]],dtype=np.float32))

index_tensor = torch.tensor([-1])

# Select elements from the input tensor along dimension 1
output_tensor = torch.index_select(input_tensor, dim=-2, index=index_tensor)

# Print the output tensor
print("PyTorch Tensor:\n", output_tensor)

image

System Information