Fast GPU graph components and partitioning algorithms for PyTorch
Project description
torch-graph-components
Official PyTorch implementation for the
graph components and graph partitioning algorithms
from
EZ-SP: Fast and Lightweight Superpoint-Based 3D Segmentation
If you ❤️ or simply use this project, don't forget to give the repository a ⭐,
it means a lot to us !
📌 Description
torch-graph-components holds algorithms for fast graph connected
components and graph partitioning, fully implemented in PyTorch with
GPU parallelization in mind.
In particular, this project contains two main algorithms:
wcc_by_max_propagationfor searching the Weakly Connected Components of a graph in pure PyTorch. We created this to avoid the reliance on SciPy's CPU-based computation found in many PyTorch projects.merge_components_by_contour_priorfor partitioning a graph based on an energy minimization problem which we solve approximatively with a greedy heuristic. Basically, this algorithm lets you find clusters in a graph based on two objectives:- compatibility between values carried by the nodes of a same component
- complexity of contour of the components
See our paper for more details.
🏗 Installation
1. Install dependencies
torch-graph-components relies on backend libraries
(torch, torch-geometric, torch-scatter).
These dependencies are not bundled and must be installed manually
by the user because they depend on:
- Python version
- PyTorch version
- CUDA version
- Operating system
# Specify your torch and and CUDA versions
export TORCH_VERSION=2.7.0
export CUDA_VERSION=cu126
# Install torch
# https://pytorch.org
pip install torch==${TORCH_VERSION} --index-url https://download.pytorch.org/whl/${CUDA_VERSION}
# Install PyTorch Geometric and PyTorch Scatter
# https://pytorch-geometric.readthedocs.io
pip install torch-scatter torch-geometric -f https://data.pyg.org/whl/torch-${TORCH_VERSION}+${CUDA_VERSION}.html
2. Install the project
pip install torch-graph-components
🚀 Usage
import torch
from torch_graph_components import wcc_by_max_propagation
from torch_graph_components import merge_components_by_contour_prior
device = 'cuda' # choose your device
N = 10 # number of nodes
E = torch.tensor([
[0, 2, 3, 2],
[1, 3, 4, 4],
], dtype=torch.long, device=device) # edges
X = torch.rand(N, 3, device=device) # node features
S = torch.ones(N, device=device) # node weights
W = torch.rand(E.shape[1], device=device) # edge weights
reg = 0.05 # regularization term
min_size = 1 # minimum component size
# Compute the weakly connected components. Returns the final component
# assignment as a tensor of node-wise indices.
# See code documentation for more details
I_wcc, _ = wcc_by_max_propagation(N, E, verbose=True)
print(I_wcc)
# Partition the graph. Returns the final component assignment as a
# tensor of node-wise indices, along with other merged attributes.
# See code documentation for more details
I_merged, _, _ = merge_components_by_contour_prior(
X,
S,
E,
W,
reg,
min_size,
verbose=True)
print(I_merged)
👩🔧 Troubleshooting
Here are some common issues and tips for tackling them.
⚠️ If you experience:
- segmentation faults
- crashes during import
- low-level runtime errors
These issues are almost always caused by incompatible backend dependencies installations. Please ensure that the dependencies were properly installed by running, in python:
import torch import torch_geometric import torch_scatter
💬 Citing our work
If your work uses all or part of the present code, please include the following a citation:
@article{geist2025ezsp,
title={EZ-SP: Fast and Lightweight Superpoint-Based 3D Segmentation},
author={Geist, Louis and Landrieu, Loic and Robert, Damien},
journal={arXiv},
year={2025},
}
Also, if you ❤️ or simply use this project, don't forget to give the repository a ⭐, it means a lot to us !
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torch_graph_components-0.1.0.tar.gz.
File metadata
- Download URL: torch_graph_components-0.1.0.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f1f3a3e3eb97e45e4fa9afa25d437565074144a0191b80a38bbdc8f5b76e58d
|
|
| MD5 |
f8833fedf970eb995760069ddf245622
|
|
| BLAKE2b-256 |
2a7b4edba6f9f9874639b1389db0f0829c12492518ced9c9a81675251c57d420
|
File details
Details for the file torch_graph_components-0.1.0-py3-none-any.whl.
File metadata
- Download URL: torch_graph_components-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49b0bc2b8f0fa70b063cc65644712384e73f7c972b671da854e15a5f252cec53
|
|
| MD5 |
b1ca69d6e3cb9f79b590952aabb50a84
|
|
| BLAKE2b-256 |
6ffa72a44893d7a8ab5086b2e7550a4633f1bddc937e26dc8b3a949c21eeab63
|