I’m not familiar with PyTorch Geometric, but in case you can precompute the targets and each sample has one corresponding target class, you could take a look at this code snippet 17, which explains the usage of the WeightedRandomSampler.