Non-deterministic behaviour with the function sample_neighbors

Hi,

Thank you for sharing, building, and maintaining this wonderful library.

I’m encountering a problem with the function sample_neighbors. My problem is that even though I’ve set the random seed for all related library as the folloing. I’m still not able to get deterministic behaviour from the function. Could anyone kindly help me how to tackle the issue? Thank you very much.

random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
torch.backends.cudnn.enabled = False

Hi, welcome to DGL.

DGL uses its own random engine and seed. It’s independent of torch. So fixing seed via torch will not take effect in sample_neighbors. refer to dgl/random.h at 8341244a2dac850bd0c1153c7641c3b8a2bbfc30 · dmlc/dgl · GitHub for more details.

If you wanna generate deterministic sampled graph, DGL have no direct way for the moment. one WAR that may be deterministic could be specify the probability via prob arg in sample_neighbors with zero or one values.

I’m not sure whether it really meets your needs. you could have a try and pls share more details if not work. We’ll see then. feel free to get back here.

1 Like

You could also try fixing DGL’s random seed with dgl.seed. Although you will also need to disable OpenMP (set environment variable OMP_NUM_THREADS=1) and data loader parallelism.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.