Segmentation fault using torch_cluster.knn when skipping batch numbers
See original GitHub issue🐛 Bug
torch_geometric gives a segfault when performing knn on a graph on CPU where the batch
tensor skips a batch number.
To Reproduce
Example to reproduce the behavior:
import torch
from torch_cluster import knn_graph
points = torch.rand(2, 2)
batch = torch.tensor([0, 1])
eidx = knn_graph(points, 1, batch) # batch tensor with only consecutive numbers works fine
points = torch.rand(2, 2).cuda()
batch = torch.tensor([0, 2]).cuda()
eidx = knn_graph(points, 1, batch) # batch tensor skipping a number but on gpu runs fine
points = torch.rand(2, 2)
batch = torch.tensor([0, 2])
eidx = knn_graph(points, 1, batch) # batch tensor skipping a number but on cpu gives a segfault
Expected behavior
It should work 😃
Environment
- OS: Tested on Mac OS 11.4 and Ubuntu 20.04.2
- Python version: 3.9.6 and 3.9.5
- PyTorch version: 1.9.0
- CUDA/cuDNN version: knn_cuda works
- GCC version:
- Any other relevant information:
Additional context
This specifically comes up for me when working with heterogeneous graphs with e.g. node types A and B, where occasionally some graphs may not have any nodes of type B, in which case the batch
tensor for type B nodes will skip that graph number.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
torch_geometric.nn — pytorch_geometric documentation
lambda_max should be a torch.Tensor of size [num_graphs] in a mini-batch scenario and a scalar/zero-dimensional tensor when operating on single graphs.
Read more >Segmentation fault - PyTorch Forums
Hi,ptrblck, I solved this problem. look into this code, and it is a function of a sampler of Dataloader. def iter(self) returns iter(torch....
Read more >Implementation of a CNN based Image Classifier using PyTorch
We'll be using the torchvision utility for this purpose and downloading the CIFAR-10 dataset into training and testing sets in directories “./ ...
Read more >Image Clustering Implementation with PyTorch | by Anders Ohrn
The torch.matmul computes all the dot-products, taking the mini-batch dimension into account. Note also that the tensor codes contains a record ...
Read more >Rcpp: Seamless R and C++ Integration - Dirk Eddelbuettel
The GSE package implements robust estimation of multivariate location and scatter in the presence of missing data, it use Rcpp and RcppArmadillo. The ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, sorry for the delay. We postponed the release to combine it with the PyTorch 1.11 release (which should be released today). I will try to re-build all wheels at the weekend.
Thanks for reporting. I fixed it in
torch-cluster
, see here.