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

Segmentation fault (core dumped) when passing empty Tensors to pack_padded_sequence #20529

Closed
JamieCT opened this issue May 15, 2019 · 5 comments
Closed

Comments

@JamieCT
Copy link

@JamieCT JamieCT commented May 15, 2019

Passing an empty tensor (so with shape (0,n,m)) to pack_padded_sequence causes a "segmentation fault (core dumped)"

Produce the error:

import torch
from torch.nn.utils.rnn import pack_padded_sequence
#bs, max_sequence_len, emb_dim
x = torch.zeros([16,10,20])
length = torch.zeros([16])
mask = [length != 0]
masked_x = x[mask]
masked_length = length[mask]
print(masked_x.shape, masked_length.shape)
pack_padded_sequence(masked_x, masked_length, batch_first = True)

Expected behavior:
An exception raised stating that the input tensor must not be empty.

Environments created on:
-PyTorch 1.0, Windows (installed via conda), CUDA (9.0)
-PyTorch 1.0, Linux (installed via pip), CUDA ('9.0.176')

Thanks,
Jamie

@ezyang
Copy link
Contributor

@ezyang ezyang commented Jun 4, 2019

Reproduced on 5fcd37b, this should be fixed.

@t-vi
Copy link
Collaborator

@t-vi t-vi commented Jun 6, 2019

I'll take a stab at fixing this.
@JamieCT thank you for reporting this and the reproduction script. This is very useful!

t-vi added a commit to t-vi/pytorch that referenced this issue Jun 6, 2019
Fixes: pytorch#20529

Thank you, @JamieCT for the bug report with reproducing script.
@LeviViana
Copy link
Contributor

@LeviViana LeviViana commented Jun 10, 2019

@t-vi I saw your great video where you fix this bug, thanks for that BTW. But, I noticed something that might improve the error report. Indeed, in the following line we assume that input has at least 2 dimensions:

https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/PackedSequence.cpp#L21

I was wandering if it could be useful to insert something like:

TORCH_CHECK(input.dim() > 1, "The input must have at least 2 dimensions.");

@t-vi
Copy link
Collaborator

@t-vi t-vi commented Jun 10, 2019

@LeviViana sounds like a good addition, the IndexError currently thrown certainly isn't optimal. More to your point, it might be worth going over all the functions in torch.nn.utils.rnn / PackedSequence.cpp and seeing how well they check their inputs. Do ping me If you want to put up a PR. (I don't think you need to file a separate issue report.)

@LeviViana
Copy link
Contributor

@LeviViana LeviViana commented Sep 24, 2019

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.

6 participants