Throw error on tensor creation when sequence shape cannot be determined#7583
Merged
soumith merged 3 commits intopytorch:masterfrom May 18, 2018
Merged
Throw error on tensor creation when sequence shape cannot be determined#7583soumith merged 3 commits intopytorch:masterfrom
soumith merged 3 commits intopytorch:masterfrom
Conversation
ezyang
approved these changes
May 15, 2018
Contributor
|
@pytorchbot retest this please |
1 similar comment
Contributor
|
@pytorchbot retest this please |
Collaborator
|
thank you @sethah |
onnxbot
added a commit
to onnxbot/onnx-fb-universe
that referenced
this pull request
May 18, 2018
…n sequence shape cannot be determined (pytorch/pytorch#7583) pytorch/pytorch@32b23a4
weiyangfb
pushed a commit
to weiyangfb/pytorch
that referenced
this pull request
Jun 11, 2018
…ed (pytorch#7583) * first commit * unit test * minor style edits
|
This worked out for me. I was trying to convert a y_train and Y_val into a tensor. train_labels = torch.tensor(y_train.to_numpy()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7278
Currently, tensors can be created from Python sequences (determined by
PySequence_Check). The shape of the tensor to be created is determined by iterating over the first element in each of the (potentially nested) sequences. This is done here.There is an assumption that it is safe to index the
PyObectat element zero ifPySequence_Check(obj)is true andPySequence_Length(obj) > 0. Unfortunately, Python objects are still free to raise errors in their__getitem__methods under these conditions, which is often the case when creating tensors from Pandas objects. In this case,PySequence_GetItemwill return a null pointer, which in turn causes a segmentation fault when the nextPySequence_Checkcall is made.This patch adds a simple check for a null pointer and raises a
ValueErrorwhen this happens. The error trace from the call to__getitem__is not propagated since it is generally unhelpful and confusing. A unit test is added that verifies the appropriate error is raised in this situation.Examples
Notes
PySequence_GetItem(obj, 0)tries to do, but I could have missed it