NeighborLoader is a PyTorch Geometric loader for training graph neural networks with mini-batches. Instead of aggregating every node and edge at once, it samples local neighborhoods around selected input nodes, reducing memory pressure for attention-heavy models such as GAT. section 4.4.1 section 7.7.2
A typical NeighborLoader workflow is:
- Set input_nodes to the training mask or training-node indices so batches begin from the intended supervision set. section 7.7.2
- Specify num_neighbors for each message-passing layer; num_neighbors=[1000]*2 samples up to 1,000 neighbors across two iterations. section 4.4.1
- Iterate over sampled batches, move features, labels, and adjacency information to the device, then run the forward pass, loss, backpropagation, and optimizer update. section 7.7.2
Mini-batching a fraud-detection GAT
A loader can be created with batch_size=128, num_neighbors=[1000]*2, and input_nodes=data.train_mask. Calling next(iter(loader)) returns sampled_data, whose batch_size and label distribution can be inspected before passing the batch to a GAT. This approach supports fake-review detection while avoiding full-graph attention memory requirements. section 4.4.1 section 4.0
