Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] When there is a negative number in index, 'mindspore.ops.index_select' should throw an error message #270

Closed
Redmept1on opened this issue Apr 10, 2024 · 2 comments

Comments

@Redmept1on
Copy link

Environment

Hardware Environment(Ascend/GPU/CPU):

device gpu

Software Environment:

  • MindSpore version (source or binary): v2.2.13
  • Python version (e.g., Python 3.7.5): 3.8.18
  • OS platform and distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 18.04

Describe the current behavior

[[7. 8. 9.]]

Describe the expected behavior

IndexError: index out of range in self

Steps to reproduce the issue

import mindspore as mind
import numpy as np

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

index_tensor = mind.tensor([-1])

output_tensor = mind.ops.index_select(input_tensor, axis=-2, index=index_tensor)

print(output_tensor)

image

#pytorch v2.0.0+cu117

import torch
import numpy as np

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

index_tensor = torch.tensor([-1])

output_tensor = torch.index_select(input_tensor, axis=-2, index=index_tensor)

print(output_tensor)

image

Special notes for this issue

The index parameter lacks a range check

@Redmept1on Redmept1on changed the title When there is a negative number in index, 'mindspore.ops.index_select' should throw an error message [Bug] When there is a negative number in index, 'mindspore.ops.index_select' should throw an error message Apr 10, 2024
@Ash-Lee233
Copy link

did you test the case on cpu?
we test the case on gpu, it reports the same info as torch
but the cpu gave [[7,8,9]], we will fix it in the next version

@Redmept1on
Copy link
Author

Thanks for your quick response, sorry for wrong information, after verification I found that my code was running on the CPU.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants