pytorch_cluster icon indicating copy to clipboard operation
pytorch_cluster copied to clipboard

[BUG] Inconsistent behavior of 'neighbor_sampler' when setting a random seed for PyTorch

Open shun-zheng opened this issue 4 years ago • 1 comments

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()'?

shun-zheng avatar Apr 27 '20 11:04 shun-zheng

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?

github-actions[bot] avatar Sep 16 '21 06:09 github-actions[bot]