Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

ValueError: some of the strides of a given numpy array are negative. This is currently not supported, #99

Closed
thammegowda opened this issue Nov 29, 2018 · 15 comments

Comments

@thammegowda
Copy link
Contributor

Trying to use pretrained InferSent2 Model ( i.e. fastext) to encode sentences.
The pretrained model works perfectly on CPU (where I have torch=0.4.1)
However, it crashes with cuda backend (where I have torch 1.0.0.dev20181017)

 File ".../InferSent/models.py", line 224, in encode
    batch = self.forward((batch, lengths[stidx:stidx + bsize])).data.cpu().numpy()
  File ".../InferSent/models.py", line 66, in forward
    sent_packed = nn.utils.rnn.pack_padded_sequence(sent, sent_len_sorted)
  File ".../python3.7/site-packages/torch/nn/utils/rnn.py", line 147, in pack_padded_sequence
    lengths = torch.as_tensor(lengths, dtype=torch.int64)
ValueError: some of the strides of a given numpy array are negative. This is currently not supported, but will be added in future releases.
 $ python --version
Python 3.7.0
$ pip list | grep torch
torch           1.0.0.dev20181017
$ nvidia-smi
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.48                 Driver Version: 390.48                    |
|-------------------------------+----------------------+----------------------+
@thammegowda
Copy link
Contributor Author

@mgalbato
Copy link

I also get the exact same error, even on the CPU. I'm using Python 2.7 and Torch 1.0 without CUDA.

@sashaostr
Copy link

+1 on CPU, Python 3.6, torch==1.0.0

@badri-thinker
Copy link

any resolution to stride error?

@sashaostr
Copy link

wait for this PR to be merged: #100
or
alter models.py manually - add this line sent_len_sorted = sent_len_sorted.copy()
here:

       # Sort by length (keep idx)
        sent_len_sorted, idx_sort = np.sort(sent_len)[::-1], np.argsort(-sent_len)	               
        sent_len_sorted = sent_len_sorted.copy()
        idx_unsort = np.argsort(idx_sort)	       

@badri-thinker
Copy link

badri-thinker commented Dec 11, 2018 via email

@aconneau
Copy link
Contributor

Merged PR. Thanks!

@kaumilturabit
Copy link

This error is still occuring despite being merged. Can anyone help me finding solution to this problem?

@fooSynaptic
Copy link

@sashaostr still not work with the latest version of this rep

@sashaostr
Copy link

@fooSynaptic
I didn't tried the latest version, I've added the fix manually and it worked for me. The PR made the same, so it's strange, but anyway manual fix worked:

wait for this PR to be merged: #100
or
alter models.py manually - add this line sent_len_sorted = sent_len_sorted.copy()
here:

       # Sort by length (keep idx)
        sent_len_sorted, idx_sort = np.sort(sent_len)[::-1], np.argsort(-sent_len)	               
        sent_len_sorted = sent_len_sorted.copy()
        idx_unsort = np.argsort(idx_sort)	       

@fooSynaptic
Copy link

@sashaostr thanks, i modified a lot of the source code and it works for me. I believe its the data process issue for i use different dataset.

@datduong
Copy link

datduong commented Jan 30, 2019

@kaumilturabit, I added copy() like this and it works

sent_len,idx_sort = np.sort(sent_len)[::-1].copy(), np.argsort(-sent_len)

@MahmudRana
Copy link

wait for this PR to be merged: #100
or
alter models.py manually - add this line sent_len_sorted = sent_len_sorted.copy()
here:

       # Sort by length (keep idx)
        sent_len_sorted, idx_sort = np.sort(sent_len)[::-1], np.argsort(-sent_len)	               
        sent_len_sorted = sent_len_sorted.copy()
        idx_unsort = np.argsort(idx_sort)	       

Thanks for the answer and also please change sent_len to sent_len_sorted in the later part of the code. (In case, someone missed that, like me :))

@amitlohan
Copy link

amitlohan commented Mar 16, 2020

Convert the numpy array to np.int16 or np.int32 before converting it to tensor.

@ynuwm
Copy link

ynuwm commented May 20, 2020

This also works for me, thanks very much.

sent_len_sorted, idx_sort = np.sort(sent_len)[::-1], np.argsort(-sent_len)	               
sent_len_sorted = sent_len_sorted.copy()
idx_unsort = np.argsort(idx_sort)

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

No branches or pull requests