pytorch_cluster
pytorch_cluster copied to clipboard
[BUG] Inconsistent behavior of 'neighbor_sampler' when setting a random seed for PyTorch
When testing with the following codes
torch.manual_seed(1234)
start = torch.tensor([0, 1])
cumdeg = torch.tensor([0, 3, 7])
neighbor_sampler(start, cumdeg, size=2)
we cannot get consistent bebaviors with multiple runs as expected in test_sampler.py.
The reason for such inconsistence is that the sampling code in cpu has two sampling branches:
if (size < 0.7 * float(num_neighbors)) {
......
int64_t sample = rand() % num_neighbors;
......
} else {
auto sample = torch::randperm(num_neighbors, start.options());
......
}
The upper branch utilizes the rand
function provided by C++
, which causes this inconsistence.
Maybe we should leverage similar functions provided by PyTorch
, which can be controlled by 'torch.manual_seed()'?
This issue had no activity for 6 months. It will be closed in 2 weeks unless there is some new activity. Is this issue already resolved?