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.

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():
        total_loss = 0
        for pos_rw, neg_rw in loader:
            loss = model.loss(,
            total_loss += loss.item()
        return total_loss / len(loader)

    def train_epoch():

        for _ in range(5):
            loss = train()

    G = txt2nx('./test.edge_list')

    G = nx.relabel.convert_node_labels_to_integers(G)

    edge_index = torch.tensor(

    device = 'cuda' if torch.cuda.is_available() else 'cpu'

    model = Node2Vec(

    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

3. Output from running script

Segmentation fault (core dumped)

Expected behavior

I would have expected no errors training the embeddings with Node2Vec.


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

github_iconTop GitHub Comments

davecerrcommented, Jan 29, 2021

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?

dansontongcommented, Aug 30, 2021

Thanks @davecerr. I solved it by saving edge list in a text file and then read it again, just like what @davecerr says.

Read more comments on GitHub >

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

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 Post

No results found

github_iconTop Related Hashnode Post

No results found