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

Fix error message when using as_strided with negative striding #33290

Open
daniilhayrapetyan opened this issue Feb 13, 2020 · 2 comments · May be fixed by #33392
Open

Fix error message when using as_strided with negative striding #33290

daniilhayrapetyan opened this issue Feb 13, 2020 · 2 comments · May be fixed by #33392

Comments

@daniilhayrapetyan
Copy link

@daniilhayrapetyan daniilhayrapetyan commented Feb 13, 2020

🐛 Bug

To Reproduce

Run following from jupyter lab console

import torch
foo = torch.arange(5)
foo.as_strided((5,), (-1,), storage_offset=4)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/daniil/.local/lib/python3.6/site-packages/torch/tensor.py", line 159, in __repr__
    return torch._tensor_str._str(self)
  File "/home/daniil/.local/lib/python3.6/site-packages/torch/_tensor_str.py", line 311, in _str
    tensor_str = _tensor_str(self, indent)
  File "/home/daniil/.local/lib/python3.6/site-packages/torch/_tensor_str.py", line 209, in _tensor_str
    formatter = _Formatter(get_summarized_data(self) if summarize else self)
  File "/home/daniil/.local/lib/python3.6/site-packages/torch/_tensor_str.py", line 82, in __init__
    for value in tensor_view:
  File "/home/daniil/.local/lib/python3.6/site-packages/torch/tensor.py", line 462, in <lambda>
    return iter(imap(lambda i: self[i], range(self.size(0))))
RuntimeError: setStorage: sizes [], strides [], and storage offset 5 requiring a storage size of 6 are out of bounds for storage with numel 5

Expected behavior

Give output:

tensor([4, 3, 2, 1, 0])

Environment

PyTorch version: 1.4.0
Is debug build: No
CUDA used to build PyTorch: 10.1

OS: Ubuntu 18.04.3 LTS
GCC version: (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
CMake version: version 3.10.2

Python version: 3.6
Is CUDA available: Yes
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: GeForce RTX 2080
Nvidia driver version: 440.33.01
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.4
/usr/local/cuda-10.0/targets/x86_64-linux/lib/libcudnn.so.7

Versions of relevant libraries:
[pip3] numpy==1.17.4
[pip3] torch==1.4.0
[pip3] torchvision==0.4.2

@SsnL
Copy link
Collaborator

@SsnL SsnL commented Feb 13, 2020

negative strides are not yet supported, but yes we should fix the error message.

@pbelevich pbelevich changed the title Exception when using as_strided with negative striding. Fix error message when using as_strided with negative striding Feb 13, 2020
@ayush-1506
Copy link

@ayush-1506 ayush-1506 commented Feb 16, 2020

I have a PR that should fix this: #33392. @SsnL could you review it?

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

Successfully merging a pull request may close this issue.

4 participants
You can’t perform that action at this time.