This repository contains small, readable implementations of Graph Neural Network building blocks and training experiments using PyTorch, PyTorch Geometric, and PyTorch Lightning.
The project currently focuses on:
- A from-scratch Graph Convolutional Network layer example.
- A from-scratch graph multi-head attention layer example.
- Node classification on the Cora citation network.
- Early graph classification work on the MUTAG dataset.
| File | Description |
|---|---|
gcn.py |
Minimal GCN layer implemented with dense adjacency matrices. |
gma.py |
Graph multi-head attention layer implemented from scratch. |
train.py |
Node-level classification on the Cora dataset using MLP and GNN models. |
gcn_classification.py |
Graph-level classification experiment for the MUTAG dataset. |
checkpoint.py |
Seed setup, data/checkpoint paths, and pretrained checkpoint download helper. |
module.py |
Common imports and plotting/deep-learning setup utilities. |
setup.py |
Package metadata and dependency list. |
- Python 3.11 or newer
- PyTorch
- PyTorch Geometric
- PyTorch Lightning
- torchvision
- NumPy
- matplotlib
- seaborn
- tqdm
Install the package and dependencies in editable mode:
pip install -e .If PyTorch Geometric installation fails, install the correct PyTorch Geometric wheels for your PyTorch and CUDA version from the official installation guide:
pip install torch_geometricDatasets are downloaded automatically by PyTorch Geometric into:
./data_path
Model checkpoints are stored in:
./checkpoint_path
To download the pretrained checkpoint files referenced by the project, run:
python checkpoint.pyRun the dense-adjacency GCN example:
python gcn.pyThis script creates a small toy graph, applies a graph convolution layer, and prints the input features, adjacency matrix, and output features.
Run the graph attention example:
python gma.pyThis script builds a small graph, applies the custom multi-head attention layer, and prints the resulting node embeddings.
Run the Cora node-classification training script:
python train.pyThe script trains and evaluates:
- An MLP baseline that ignores graph edges.
- A GNN model using PyTorch Geometric message-passing layers.
It reports train, validation, and test accuracy.
Defined in train.py, this class builds a configurable stack of PyTorch
Geometric graph layers. Supported layer names include:
GCNGATGraphGraphConv
Defined in train.py, this baseline uses linear layers, ReLU activations, and
dropout. It is useful for comparing graph-aware learning against a model that
only uses node features.
The Lightning module in train.py wraps either the GNN or MLP model and
handles training, validation, testing, optimizer setup, and metric logging.
gcn_classification.py contains an in-progress graph-level classification
experiment for MUTAG. It shows the intended architecture for graph pooling and
classification, but it may need cleanup before being used as a stable training
entry point.