Library / SDK
pyg-team/pytorch_geometric avatar
pyg-team/pytorch_geometric

PyTorch Geometric: A Tensor-Centric GNN Library That Stays Close to PyTorch

Graph Neural Network Library for PyTorch. For this, we load the Cora dataset, and create a simple 2-layer GCN model using the pre-defined GCNConv: We can now optimize the model in a training loop, similar to the standard PyTorch training procedure .

24,082 stars4,052 forksPythonMIT

At a glance

What is it?
PyTorch Geometric (PyG) is a graph neural network library built on PyTorch, offering a unified API, message passing primitives, and scalable loaders. This review covers its core mechanism, setup, and where it fits or falls short.
Who is it for?
Adopt PyG if you are a PyTorch user who needs a mature, well-documented GNN library with a large model zoo and scalable mini-batching. Skip it if you are not using PyTorch or if you need a production-grade distributed training solution, since PyG's multi-GPU support is still experimental and its API is tightly coupled to PyTorch's tensor model.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 14 days ago.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

What PyG Solves and Who It Serves

PyG addresses the friction of building graph neural networks from scratch. Without it, you would need to implement message passing, graph convolutions, and mini-batching for irregular structures yourself, a task that is error-prone and time-consuming. The library is aimed at two groups: machine learning researchers who want to prototype GNN architectures quickly, and engineers who need to apply GNNs to real-world graphs with millions of nodes. The README emphasizes that it takes 10 to 20 lines of code to train a GNN model, which is a concrete promise. For a researcher experimenting with new architectures, the message passing API is the key draw. For a practitioner dealing with large graphs, the mini-batch loaders and support for heterogeneous graphs are more relevant. The documentation positions PyG as a PyTorch extension, not a separate framework, so it is not for someone who wants a self-contained tool.

The Core Mechanism: Message Passing and the Data Object

At the heart of PyG is the `MessagePassing` base class. The README shows an implementation of an edge convolutional layer that inherits from `MessagePassing` and overrides `forward`. The mechanism is explicit: you define how messages are computed from node features and edge connectivity, and how they are aggregated, for example with `aggr="max"`. The `forward` method receives `x` (a node feature matrix of shape `[num_nodes, in_channels]`) and `edge_index` (the graph connectivity matrix). This design is tensor-centric, meaning the entire graph is represented as tensors, which keeps it close to PyTorch's data model. The library also provides pre-defined convolution layers like `GCNConv`, which encapsulate the standard graph convolution formula. The training loop in the README is almost identical to a standard PyTorch loop: you create an optimizer, iterate over epochs, compute predictions, and call `loss.backward()`. The only difference is that you pass `data.x` and `data.edge_index` to the model. This is a deliberate design choice to lower the learning curve for PyTorch users.

Getting Started: Installation and a Minimal GCN Example

Installation is not shown in the README snippet, but the PyPI and download links imply it is available via `pip install torch-geometric`. The documentation is hosted on ReadTheDocs, and the project has a PyPI version badge, so the standard install path is through pip. To run the quick tour, you need PyTorch installed first, since PyG is built upon it. After that, you load the Cora dataset with `Planetoid(root='.', name='Cora')` from `torch_geometric.datasets`. The dataset object gives you a single `data` object that contains `x`, `edge_index`, `y`, and masks like `train_mask`. The example defines a two-layer GCN using `GCNConv`, and the training loop uses `torch.optim.Adam` with a learning rate of 0.01 and 200 epochs. A key detail is that the model's `forward` takes `edge_index` as a separate argument, which is a departure from some other GNN libraries that bundle the graph structure into the data object. This explicit separation makes the data flow clear but requires you to pass the connectivity matrix every time. For a new user, the quick tour is enough to get a model running, but you will need to consult the examples folder for evaluation code, as the README only shows training.

Scalability and Heterogeneity: The Loaders and Multi-GPU Story

PyG positions itself as supporting large-scale graphs, with mini-batch loaders for both many small graphs and single giant graphs. The README mentions these loaders as a core highlight, along with multi-GPU support and `torch.compile` support. However, the multi-GPU support is listed under an `examples/multi_gpu` directory, which suggests it is not a fully integrated feature but rather example code. This is a limitation: if you need to train on a cluster with multiple GPUs, you may have to write custom logic based on those examples. The library also supports heterogeneous graphs with multiple node and edge types, which is a differentiator from simpler GNN frameworks that assume a single graph type. The `DataPipe` support is another sign of focus on data loading pipelines. For a graph with millions of nodes, the mini-batch loaders are likely the right tool, but the documentation does not specify the exact scaling limits. You would need to test your own graph to see if the memory footprint and training time meet your needs.

A Genuine Limitation: PyTorch-Only and API Churn

The most obvious limitation is that PyG is exclusively for PyTorch. If your team uses TensorFlow or JAX, PyG is not an option. The README is explicit that PyG is built upon PyTorch, and the API is tensor-centric, so there is no interoperability layer. Another limitation is the API's evolution. The release history shows version 2.8.0 in June 2026, 2.7.0 in October 2025, and 2.6.1 in September 2024. That is roughly two major releases per year, which means the API can change. The 2.6.1 release was labeled as bugfixes, but major versions like 2.7.0 and 2.8.0 may introduce breaking changes. The README does not detail these changes, but the existence of a separate PyG 2.0 paper suggests a significant architectural shift. Users on older versions may find that example code from the README does not run on the latest release without adjustments. This is a real cost for long-lived projects. Additionally, the library's focus on research means that some production concerns, like model serving or distributed training, are not fully addressed in the core library.

The Alternative: Message Passing Libraries vs. High-Level Frameworks

The main alternative to PyG is Deep Graph Library (DGL), which also provides GNN primitives but supports multiple backends, including PyTorch, TensorFlow, and MXNet. DGL takes a different approach to graph representation: it uses a graph-centric abstraction where the graph is a first-class object, and you define message functions on edges and nodes. In contrast, PyG keeps the graph as tensors (`edge_index` and `x`) and uses a message passing class that is closer to PyTorch's module system. This difference matters in practice. With DGL, you often write `g.ndata['h']` to access node features, whereas in PyG you pass tensors directly to the forward method. For a PyTorch purist, PyG's approach is more familiar. For someone who wants to switch backends or work with a more graph-native API, DGL might be a better fit. The README does not mention DGL, but the choice is a real one for teams evaluating GNN libraries.

Maintenance and Upgrade Cost: License and Release Cadence

PyG is licensed under MIT, which is permissive and allows commercial use without copyleft obligations. The repository is actively maintained, with the last push on June 5, 2026, and a release on the same day. The release cadence of roughly two minor versions per year indicates a healthy project, but it also means you need to plan for upgrades. The README does not specify a deprecation policy, so you should read the release notes for each version before upgrading. The project has a large number of implemented GNN models, which is a maintenance advantage: you are not implementing everything from scratch. However, the breadth of models also means that some may be unmaintained or paper-specific, so you should verify that the model you need is still supported. The documentation and Colab notebooks are a plus for onboarding, but the actual upgrade cost depends on how deeply you integrate PyG into your codebase. If you use only the high-level `GCNConv` and datasets, upgrades are likely straightforward. If you write custom message passing layers, you need to test them against each new release.

Editorial conclusion

Adopt PyG if you are a PyTorch user who needs a mature, well-documented GNN library with a large model zoo and scalable mini-batching. Skip it if you are not using PyTorch or if you need a production-grade distributed training solution, since PyG's multi-GPU support is still experimental and its API is tightly coupled to PyTorch's tensor model. Before adopting, verify that your graph sizes and heterogeneity match PyG's loaders, and check the latest release notes for changes to the `torch_geometric.nn` API, as updates like 2.8.0 may alter behavior. Also confirm that your PyTorch version is compatible with the PyG wheel, and test your custom message passing layers against the provided examples.

Official sources

  1. Official documentation
  2. Official README
  3. Project repository
  4. Release notes
Community notes

Community notes