torch-geometric

PyTorch Geometric (PyG) for graph neural networks — node/link/graph classification, message passing (GCN, GAT, GraphSAGE, GIN), heterogeneous graphs, neighbor sampling, and custom datasets. Use when working with torch_geometric, not for general NetworkX analytics or non-graph PyTorch models.

Install

Hot:25

Download and extract to your skills directory

Copy command and send to AI Agent for auto-install:

Download and install this skill https://openskills.cc/api/download?slug=k-dense-ai-skills-torch-geometric&locale=en&source=copy

torch-geometric

Skill Overview


The torch-geometric skill provides a complete usage guide for the PyTorch Geometric (PyG) graph neural network library, covering the full workflow from installation and configuration, through understanding core concepts, to building GNN models, handling heterogeneous graphs, and training on large graphs.

Use Cases

  • Graph Neural Network Development and Training

  • - Use PyG to build and train various graph neural network models, including tasks such as node classification, graph classification, and link prediction. Supports popular GNN layers like GCN, GAT, GraphSAGE, and GIN.

  • Heterogeneous Graph Processing and Analysis

  • - Handle heterogeneous graph data containing multiple node types and edge types. Suitable for complex relationship scenarios such as social networks, knowledge graphs, and recommender systems. Provides specialized tools such as HeteroData and HGTConv.

  • Training on Large-Scale Graph Data

  • - Use sampling techniques such as NeighborLoader and ClusterLoader to handle large graphs that exceed GPU memory. Supports distributed training and PyTorch Lightning integration, making it suitable for industrial-grade graph data scenarios.

    Core Features

  • Complete GNN Building Toolkit

  • - Offers 60+ pre-implemented graph neural network layers (GCNConv, GATConv, SAGEConv, GINConv, etc.), supports custom MessagePassing layers, and includes high-level APIs for GraphSAGE, GCN, GAT, and GIN—meeting needs from research to production.

  • Robust Data Processing Capabilities

  • - Includes standard datasets such as Planetoid, TUDataset, and QM9. Supports Data and HeteroData graph structures, and provides a transforms-based data preprocessing pipeline. Can load custom graph data from formats like CSV, NetworkX, and scipy.

  • Extensible Training and Interpretability

  • - Supports large-graph training methods such as NeighborLoader, ClusterGCN, and GraphSAINT. Provides the torch_geometric.explain module to interpret GNN predictions (e.g., GNNExplainer, PGExplainer). Compatible with torch.compile and distributed training.

    Common Questions

    What environment does PyTorch Geometric require?


    You need Python 3.10+ and PyTorch 2.6+. It’s recommended to install the core library with uv pip install torch_geometric. The optional acceleration extensions (pyg-lib, torch-scatter, etc.) must be matched to your PyTorch and CUDA versions by installing the corresponding wheels from https://data.pyg.org/whl.

    How is torch_geometric different from NetworkX?


    torch_geometric focuses on training graph neural networks and provides GPU-accelerated GNN layers and large-scale graph training support. NetworkX is a general-purpose graph analysis library, better suited for graph algorithms, visualization, and small-scale graph computation. If your task is deep learning, use PyG; for classic graph algorithms, use NetworkX.

    How do I use PyG to handle large graphs that don’t fit in memory?


    Use NeighborLoader for neighbor sampling: set num_neighbors to control the number of samples per layer, and batch_size to control the number of seed nodes. PyG builds subgraphs containing the sampled neighbors for training, avoiding loading the full graph. For link prediction, use LinkNeighborLoader; in multi-GPU settings, you can combine it with torch.distributed DDP.