Cannot reproduce LinkNeighborSampling #9878
Replies: 2 comments
-
Hi, I am not an expert but I will try to help. The complete function is here:
There were more comments on this post, so I advice you go there to check. best, |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for replying and telling me a helpful post. I revised my code as: import os
import random
import numpy as np
import torch
import torch_geometric.transforms as T
from torch_geometric.datasets import OGB_MAG
from torch_geometric.loader import NeighborLoader
from torch_geometric import seed_everything
def set_random_seed(seed):
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
os.environ["PYTHONHASHSEED"] = str(seed)
torch.backends.cudnn.enabled = True
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":4096:8"
torch.use_deterministic_algorithms(True)
def build_batch(seed):
set_random_seed(seed)
transform = T.ToUndirected() # Add reverse edge types.
data = OGB_MAG(root="./data", preprocess="metapath2vec", transform=transform)[0]
train_loader = NeighborLoader(
data,
# Sample 15 neighbors for each node and each edge type for 2 iterations:
num_neighbors=[15] * 2,
# Use a batch size of 128 for sampling training nodes of type "paper":
batch_size=128,
input_nodes=("paper", data["paper"].train_mask),
)
batch = next(iter(train_loader))
return batch
batch1 = build_batch(42)
batch2 = build_batch(42)
print(batch1["field_of_study", "rev_has_topic", "paper"].edge_index.shape)
print(batch2["field_of_study", "rev_has_topic", "paper"].edge_index.shape) but output keeps non-reproducible.
Maybe I should check deeper, but your comment was so helpful. Thanks a lot. |
Beta Was this translation helpful? Give feedback.
-
🐛 Describe the bug
Hi, I am struggling to reproduce batch sampling with LinkNeighborLoader.
Following is what I tried:
I expected
batch1
andbatch2
are identical, but they are not.How do I fix this problem?
Environment
Beta Was this translation helpful? Give feedback.
All reactions