question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rusty1scommented, Mar 10, 2022

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.

1reaction
rusty1scommented, Nov 5, 2021

Thanks for reporting. I fixed it in torch-cluster, see here.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found