{"id":4284,"library":"torch-geometric","title":"PyTorch Geometric (PyG)","description":"PyTorch Geometric (PyG) is a library built upon PyTorch to easily write and train Graph Neural Networks (GNNs) for a wide range of applications related to structured data. It consists of various methods for deep learning on graphs and other irregular structures, providing easy-to-use mini-batch loaders, multi-GPU support, `torch.compile` support, a large number of common benchmark datasets, and helpful transforms. It is actively maintained with frequent minor releases delivering new features and bug fixes.","status":"active","version":"2.7.0","language":"en","source_language":"en","source_url":"https://github.com/pyg-team/pytorch_geometric","tags":["graph neural networks","pytorch","deep learning","geometric deep learning","GNN"],"install":[{"cmd":"pip install torch_geometric","lang":"bash","label":"Minimal Installation"},{"cmd":"# Ensure PyTorch is installed with appropriate CUDA support, e.g., for CUDA 12.1:\npip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121\n# Then install PyG's optional C++/CUDA extensions (replace TORCH and CUDA with your versions):\npip install pyg_lib torch_scatter torch_sparse torch_cluster torch_spline_conv -f https://data.pyg.org/whl/torch-${TORCH}+${CUDA}.html","lang":"bash","label":"With Optional C++/CUDA Extensions"}],"dependencies":[{"reason":"Core deep learning framework. PyG 2.7.0 requires PyTorch >=2.6 and is compatible up to PyTorch 2.8. Specific PyTorch versions require matching CUDA versions for GPU usage.","package":"torch","optional":false},{"reason":"Provides heterogeneous GNN operators and advanced graph sampling routines. Recommended for full feature set and performance.","package":"pyg-lib","optional":true},{"reason":"Accelerated and efficient sparse reductions, critical for many GNN operations. Recommended for performance.","package":"torch-scatter","optional":true},{"reason":"SparseTensor support, crucial for memory-efficient graph computations. Recommended for performance.","package":"torch-sparse","optional":true},{"reason":"Graph clustering routines, used in certain pooling layers and graph processing tasks. Recommended for specific features.","package":"torch-cluster","optional":true},{"reason":"Provides SplineConv support for specialized graph convolutions. Recommended for specific GNN architectures.","package":"torch-spline-conv","optional":true}],"imports":[{"note":"The primary object for representing a single graph.","symbol":"Data","correct":"from torch_geometric.data import Data"},{"note":"Base class for implementing custom Graph Neural Network layers.","symbol":"MessagePassing","correct":"from torch_geometric.nn import MessagePassing"},{"note":"A common Graph Convolutional Network layer.","symbol":"GCNConv","correct":"from torch_geometric.nn import GCNConv"},{"note":"For loading benchmark graph datasets like Cora, CiteSeer, PubMed.","symbol":"Planetoid","correct":"from torch_geometric.datasets import Planetoid"},{"note":"For graph transformations and augmentations.","symbol":"T","correct":"import torch_geometric.transforms as T"}],"quickstart":{"code":"import torch\nfrom torch_geometric.data import Data\n\n# Define an edge list (COO format: [source_nodes, target_nodes])\nedge_index = torch.tensor([[0, 1, 1, 2],\n                           [1, 0, 2, 1]], dtype=torch.long)\n\n# Define node features (3 nodes, 1 feature per node)\nx = torch.tensor([[-1],\n                  [0],\n                  [1]], dtype=torch.float)\n\n# Create a Data object to represent the graph\ndata = Data(x=x, edge_index=edge_index)\n\nprint(data)\nprint(f\"Number of nodes: {data.num_nodes}\")\nprint(f\"Number of edges: {data.num_edges}\")\nprint(f\"Is undirected: {data.is_undirected()}\")","lang":"python","description":"This example demonstrates how to create a basic graph using PyTorch Geometric's `Data` object, which is the fundamental building block for representing graphs. It defines node features and graph connectivity (edges) and then prints basic properties of the created graph."},"warnings":[{"fix":"Upgrade Python to 3.10 or newer, and PyTorch to 2.6 or newer. Check the official PyG installation guide for specific PyTorch/CUDA compatibility tables.","message":"PyG 2.7.0 dropped support for Python 3.9 and PyTorch versions 1.11 through 2.5. Ensure your environment uses Python >=3.10 and PyTorch >=2.6 for compatibility.","severity":"breaking","affected_versions":">=2.7.0"},{"fix":"Always refer to the official PyTorch Geometric installation instructions. Use the provided `-f https://data.pyg.org/whl/torch-${TORCH}+${CUDA}.html` link, replacing `${TORCH}` and `${CUDA}` placeholders with your exact PyTorch and CUDA versions.","message":"Installation of optional C++/CUDA extensions (e.g., `torch-scatter`, `torch-sparse`) is complex and requires careful matching of PyTorch and CUDA versions, often necessitating specific pre-built wheels. Mismatched versions can lead to compilation errors or runtime issues.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Replace usages of `torch_geometric.compile(model)` with `torch.compile(model)`. Remove `jittable=True` from `MessagePassing` layer initializations if present.","message":"The `torch_geometric.compile` utility and `MessagePassing.jittable` attribute have been deprecated. Users should migrate to `torch.compile` for model optimization.","severity":"deprecated","affected_versions":">=2.6.0"},{"fix":"Review the updated documentation for `GraphMultisetTransformer` and adjust your model's implementation accordingly.","message":"The interface and implementation of `GraphMultisetTransformer` changed in PyG 2.7.0, potentially affecting existing models that use this layer.","severity":"breaking","affected_versions":">=2.7.0"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}