-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Batch.get_example
fails when using sparse_coo_tensor
for the tensor values
#7022
Comments
Interesting. It looks like |
Yeah you are right. The code can be simplified to this:
|
It seems that pytorch supports Change this line:
to: if isinstance(value, Tensor) and not value.is_sparse: Add this other option to the same elif isinstance(value, Tensor) and value.is_sparse and (value.layout == sparse_coo):
key = str(key)
cat_dim = batch.__cat_dim__(key, value, store)
start, end = int(slices[idx]), int(slices[idx + 1])
indices = arange(start, end, dtype=long) # Converting the slice to indices to use `index_select`
value = value.index_select(cat_dim or 0, indices)
if decrement and (incs.dim() > 1 or int(incs[idx]) != 0):
value = value - incs[idx].to(value.device)
return value And of course change the imports
|
Cool. Are you interested in sending a PR in for this? :) |
Done in PR#7037 :) |
This PR allows to fix the issues with `Batch.from_data_list` or `Batch.get_example` or `Batch__getitem__` when using pytorch's sparse tensors, such as `sparse_coo_tensor`. See issue #7022 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Matthias Fey <matthias.fey@tu-dortmund.de>
🐛 Describe the bug
I cannot call
batch[0]
orbatch.get_example(0)
when usingtorch.sparse_coo_tensor
, despite the batching working as expected.On ubuntu, I get this error:
On windows, I get this error:
The text was updated successfully, but these errors were encountered: