GNN explainer seed?

Continuing the discussion from GNNExplainer import:

Hi @mufeili 've been trying to explain some models using the advise from the discussion above and I see that every time I get slightly different results. I don’t know where this stochasticity is coming from but would it be possible to pass a seed or something in order to make it at least reproducible? I’ve tried running this before running the code but the issue persists :frowning: :

import os

import random

seed = 42

os.environ['PYTHONHASHSEED'] = str(seed)

# Torch RNG

torch.manual_seed(seed)

torch.cuda.manual_seed(seed)

torch.cuda.manual_seed_all(seed)

# Python RNG

np.random.seed(seed)

random.seed(seed)

I see from the source code here that torch.randn is used to initialise the masks. I believe that torch.manual_seed should solve the issue but it doesn’t. Any hint? Thanks!

See if adding these

torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
dgl.seed(seed)

helps. If there still exists randomness, then likely there are underlying operators that cannot be deterministic.

Hi @mufeili thanks!! I think it is working now and I’m able to reproduce the results :slight_smile: This line dgl.seed(seed) gave me this error though:


DGLError Traceback (most recent call last)

in () ----> 1 dgl.seed(seed)

/usr/local/lib/python3.7/dist-packages/dgl/random.py in seed(val) 16 The seed. 17 “”" —> 18 _CAPI_SetSeed(val) 19 20 def choice(a, size, replace=True, prob=None): # pylint: disable=invalid-name

dgl/_ffi/_cython/./function.pxi in dgl._ffi._cy3.core.FunctionBase.call()

dgl/_ffi/_cython/./function.pxi in dgl._ffi._cy3.core.FuncCall()

dgl/_ffi/_cython/./function.pxi in dgl._ffi._cy3.core.FuncCall3()

DGLError: [16:14:26] /opt/dgl/src/random/random.cc:34: Check failed: e == CURAND_STATUS_SUCCESS: CURAND Error: CURAND_STATUS_INITIALIZATION_FAILED at /opt/dgl/src/random/random.cc:34 Stack trace: [bt] (0) /usr/local/lib/python3.7/dist-packages/dgl/libdgl.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x4f) [0x7f2c1e3b8eaf] [bt] (1) /usr/local/lib/python3.7/dist-packages/dgl/libdgl.so(+0x6323b6) [0x7f2c1e6d93b6] [bt] (2) /usr/local/lib/python3.7/dist-packages/dgl/libdgl.so(DGLFuncCall+0x48) [0x7f2c1e6e1398] [bt] (3) /usr/local/lib/python3.7/dist-packages/dgl/_ffi/_cy3/core.cpython-37m-x86_64-linux-gnu.so(+0x16a04) [0x7f2bf3f5fa04] [bt] (4) /usr/local/lib/python3.7/dist-packages/dgl/_ffi/_cy3/core.cpython-37m-x86_64-linux-gnu.so(+0x16f3b) [0x7f2bf3f5ff3b] [bt] (5) /usr/bin/python3(_PyObject_FastCallKeywords+0x562) [0x594b72] [bt] (6) /usr/bin/python3(_PyEval_EvalFrameDefault+0x40b0) [0x515600] [bt] (7) /usr/bin/python3(_PyFunction_FastCallKeywords+0x187) [0x593dd7] [bt] (8) /usr/bin/python3() [0x548ae9]

What value did you pass for the seed?