torch-geometric

Build, train, and debug graph neural networks with PyTorch Geometric.

4|Updated Mar 2, 2026
One-click install
npx skills add https://github.com/shushuzn/Rairos --skill torch-geometric-shushuzn
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: torch-geometric
Source: https://github.com/shushuzn/Rairos/tree/main/skills/torch-geometric
Command: npx skills add https://github.com/shushuzn/Rairos --skill torch-geometric-shushuzn

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It removes the guesswork in implementing Graph Neural Networks by providing the right PyTorch Geometric (PyG) data structures, layer patterns, and training workflows for graph learning tasks.

Core Features & Use Cases

  • Graph modeling with PyG primitives: Covers Data and HeteroData so you can represent homogeneous and heterogeneous graphs correctly, including edge_index handling.
  • Implement and scale GNNs: Guides stacking common conv layers, writing custom layers via MessagePassing, and scaling training with NeighborLoader / LinkNeighborLoader.
  • Task-ready patterns: Provides ready-to-adapt training patterns for node classification, graph classification, and link prediction (including negative sampling).
  • Heterogeneous graph support: Shows how to build and train type-aware models with to_hetero, HeteroConv, and HGTConv.
  • Explainability workflows: Explains how to use torch_geometric.explain with algorithms like GNNExplainer and CaptumExplainer for model interpretation.

Quick Start

Use the skill when you need to implement or debug a PyTorch Geometric GNN for tasks like node classification or link prediction from your graph tensors (including correct edge_index construction).

Frequently Asked Questions about torch-geometric

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build a graph neural network for node classification using PyTorch Geometric?

To build a GNN for node classification, use PyTorch Geometric data structures like `Data` for graph tensors, stack common convolution layers, and apply training patterns designed for node-level tasks. Ensure correct `edge_index` construction to represent graph topology accurately.

How do I handle heterogeneous graphs in PyG?

Handle heterogeneous graphs in PyG using `HeteroData` structures and build type-aware models with `to_hetero`, `HeteroConv`, or `HGTConv`. This allows distinct node and edge types to be processed correctly within your graph neural network architecture.

What is the correct way to define edge_index for message passing layers?

The `edge_index` defines graph connectivity for message passing layers and must be a tensor of shape `[2, num_edges]` specifying source and target nodes. Correct `edge_index` semantics are crucial for proper information aggregation across graph edges.

How do I scale GNN training with neighbor sampling for large graphs?

Scale GNN training on large graphs using `NeighborLoader` for node-level tasks and `LinkNeighborLoader` for link prediction. These PyG loaders enable scalable mini-batch workflows by sampling localized subgraphs instead of loading the entire graph into memory.

Can I implement custom message passing logic in PyTorch Geometric?

Yes, you can implement custom message passing logic by subclassing the `MessagePassing` base class. This allows you to define custom aggregation and update functions for creating specialized graph convolution layers tailored to your specific graph learning task.

How do I explain GNN predictions using PyG?

Explain GNN predictions using the `torch_geometric.explain` module with algorithms like `GNNExplainer` and `CaptumExplainer`. These tools provide model interpretability by identifying important nodes and edges that influence your graph neural network's outputs.