Node2Vec - Segmentation Fault
See original GitHub issue🐛 Bug
When I run Node2Vec on a graph, I receive a Segmentation fault (core dumped)
message.
To Reproduce
Steps to reproduce the behavior:
1. Edge List
I will post this in the next comment (the file is long)
2. Script
import networkx as nx
import torch
from torch_geometric.nn import Node2Vec
import numpy as np
walk_length = 40
walks_per_node = 10
context_size = 5
p = 1
q = 1
def txt2nx(file):
graph = nx.read_edgelist(file)
return graph
if __name__ == "__main__":
def train():
model.train()
total_loss = 0
for pos_rw, neg_rw in loader:
optimizer.zero_grad()
loss = model.loss(pos_rw.to(device), neg_rw.to(device))
loss.backward()
optimizer.step()
total_loss += loss.item()
return total_loss / len(loader)
def train_epoch():
print()
for _ in range(5):
loss = train()
print(loss)
G = txt2nx('./test.edge_list')
G = nx.relabel.convert_node_labels_to_integers(G)
edge_index = torch.tensor(
np.array(G.edges()),
dtype=torch.long
).t().contiguous()
device = 'cuda' if torch.cuda.is_available() else 'cpu'
model = Node2Vec(
edge_index,
embedding_dim=8,
walk_length=walk_length,
context_size=context_size,
walks_per_node=walks_per_node,
num_negative_samples=1,
p=p,
q=q,
sparse=True,
).to(device)
loader = model.loader(batch_size=128, shuffle=True) # , num_workers=4)
optimizer = torch.optim.SparseAdam(model.parameters(), lr=0.01)
# Train until delta loss has been reached
train_epoch()
3. Output from running script
Segmentation fault (core dumped)
Expected behavior
I would have expected no errors training the embeddings with Node2Vec.
Environment
- OS: Ubuntu 20.04
- Python version: 3.8.2
- PyTorch version: 1.5.1
- CUDA/cuDNN version: (Ran this on CPU, but have 10.2)
- GCC version: gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0
- Any other relevant information:
Additional context
I tested it with networkx isolates (nx.algorithms.isolate.isolates(G)) and there were no isolated nodes.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Node2Vec - Segmentation Fault · Issue #1472 - GitHub
Bug When I run Node2Vec on a graph, I receive a Segmentation fault (core dumped) message. To Reproduce Steps to reproduce the behavior:...
Read more >Segmentation fault when accessing BST child nodes. Why?
As a result tree->remove_node(tree->root) attempt to delete the "left" node of an uninitialized pointer, which result in the segmentation fault ...
Read more >This article will take you GNN from entry to take-off, and be the ...
Abstract: This article introduces the development of graph neural networks in academia and industry, and gives the basic concepts and ...
Read more >A User Segmentation Method in Heterogeneous Open ... - MDPI
This study investigates the user segmentation problem in heterogeneous OICs and develops a hierarchical processing method to transform ...
Read more >Learning event representations for temporal ... - Digital CSIC
Our framework is the first attempt to learn simultaneously graph structure and data representations for temporal segmentation of image sequences. Our main ...
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
I had a similar error. I found that not using networkx resolved the problem. Maybe you can save your edge list in a text file and read it from there instead?
Thanks @davecerr. I solved it by saving edge list in a text file and then read it again, just like what @davecerr says.