Closed aaronwtr closed 8 months ago
I think what you want to use here is LinkNeighborLoader
instead of DataLoader
.
@rusty1s trying to install pyg-lib according to docs to get LinkNeighborLoader to run with pip install pyg-lib -f https://data.pyg.org/whl/torch-2.0.0+cpu.html
results in:
Looking in links: https://data.pyg.org/whl/torch-2.0.0+cpu.html
ERROR: Could not find a version that satisfies the requirement pyg-lib (from versions: none)
ERROR: No matching distribution found for pyg-lib
Am I somehow not installing it correctly?
Why OS are you on?
@rusty1s MacOS 14.1.1
I am assuming you are on M1/M2 then? We don't provide custom wheels for that, so you would need to install pyg-lib
from source for this. Sorry :(
@rusty1s thank you for your help with this. Was able to install pyg-lib from the git main branch. However, I am running into other weird/unexpected behaviour. When I run the LinkNeighbourLoader as follows:
class HGSLNetDataModule(pl.LightningDataModule):
def __init__(self, graph, batch_size=32):
super().__init__()
self.graph = graph
self.batch_size = batch_size
def setup(self, stage=None):
self.train_graph, self.val_graph, _ = self.link_split_transform()
def train_dataloader(self):
return LinkNeighborLoader(
self.train_graph,
batch_size=self.batch_size,
num_neighbors=[10],
shuffle=True
)
def val_dataloader(self):
return LinkNeighborLoader(
self.val_graph,
batch_size=self.batch_size,
num_neighbors=[10],
shuffle=False
)
def link_split_transform(self):
transform = T.RandomLinkSplit(
num_val=0.15,
num_test=0,
is_undirected=True,
add_negative_train_samples=False
)
return transform(self.graph)
I get the following error:
Traceback (most recent call last):
File "/Users/aaronw/Desktop/PhD/Research/QMUL/Research/synthetic-lethality-prediction/synthetic-lethality-prediction/src/main.py", line 41, in <module>
main()
File "/Users/aaronw/Desktop/PhD/Research/QMUL/Research/synthetic-lethality-prediction/synthetic-lethality-prediction/src/main.py", line 36, in main
homotrain(graph)
File "/Users/aaronw/Desktop/PhD/Research/QMUL/Research/synthetic-lethality-prediction/synthetic-lethality-prediction/src/main.py", line 19, in homotrain
trainer.fit(model, datamodule)
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/lightning/pytorch/trainer/trainer.py", line 544, in fit
call._call_and_handle_interrupt(
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/lightning/pytorch/trainer/call.py", line 44, in _call_and_handle_interrupt
return trainer_fn(*args, **kwargs)
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/lightning/pytorch/trainer/trainer.py", line 580, in _fit_impl
self._run(model, ckpt_path=ckpt_path)
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/lightning/pytorch/trainer/trainer.py", line 989, in _run
results = self._run_stage()
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/lightning/pytorch/trainer/trainer.py", line 1033, in _run_stage
self._run_sanity_check()
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/lightning/pytorch/trainer/trainer.py", line 1062, in _run_sanity_check
val_loop.run()
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/lightning/pytorch/loops/utilities.py", line 182, in _decorator
return loop_run(self, *args, **kwargs)
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/lightning/pytorch/loops/evaluation_loop.py", line 127, in run
batch, batch_idx, dataloader_idx = next(data_fetcher)
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/lightning/pytorch/loops/fetchers.py", line 127, in __next__
batch = super().__next__()
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/lightning/pytorch/loops/fetchers.py", line 56, in __next__
batch = next(self.iterator)
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/lightning/pytorch/utilities/combined_loader.py", line 326, in __next__
out = next(self._iterator)
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/lightning/pytorch/utilities/combined_loader.py", line 132, in __next__
out = next(self.iterators[0])
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/torch_geometric/loader/base.py", line 36, in __next__
return self.transform_fn(next(self.iterator))
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 633, in __next__
data = self._next_data()
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 677, in _next_data
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 54, in fetch
return self.collate_fn(data)
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/torch_geometric/loader/link_loader.py", line 182, in collate_fn
out = self.link_sampler.sample_from_edges(
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/torch_geometric/sampler/neighbor_sampler.py", line 182, in sample_from_edges
return edge_sample(inputs, self._sample, self.num_nodes, self.disjoint,
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/torch_geometric/sampler/neighbor_sampler.py", line 550, in edge_sample
out = sample_fn(seed, seed_time)
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/torch_geometric/sampler/neighbor_sampler.py", line 282, in _sample
out = torch.ops.pyg.neighbor_sample(
File "/Users/aaronw/miniconda3/envs/sl-prediction/lib/python3.8/site-packages/torch/_ops.py", line 502, in __call__
return self._op(*args, **kwargs or {})
RuntimeError: pyg::neighbor_sample() Expected a value of type 'Optional[Tensor]' for argument 'seed_time' but instead found type 'bool'.
Position: 6
Value: True
Declaration: pyg::neighbor_sample(Tensor rowptr, Tensor col, Tensor seed, int[] num_neighbors, Tensor? node_time=None, Tensor? edge_time=None, Tensor? seed_time=None, Tensor? edge_weight=None, bool csc=False, bool replace=False, bool directed=True, bool disjoint=False, str temporal_strategy="uniform", bool return_edge_id=True) -> (Tensor, Tensor, Tensor, Tensor?, int[], int[])
Cast error details: Unable to cast True to Tensor
I have not set any seed_time argument anywhere so I can't quite follow where this arg gets assigned a boolean.
@aaronwtr The error is likely due to version mismatch between torch_geometric
and pyg_lib
. Which version of each have you installed?
@akihironitta I did
pip install ninja wheel
pip install git+https://github.com/pyg-team/pyg-lib.git
to install. This installed version 0.4.0 of pyg-lib
If you have pyg_lib 0.4.0, you need torch_geometric master afaik.
@rusty1s @akihironitta thank you for your help! Indeed had to use LinkNeighborLoader + pyg_lib 0.4.0 + torch_geometric from main.
🐛 Describe the bug
I am trying to build a GAT model with PyG and PyTorch Lightning. The problem I am trying to solve is a link prediction task and to that end, I need to split my edges into a train and val set. Since we have an independent held-out test graph, we don't need to get that with RandomLinkSplit. After my preprocessing, my graph object looks as follows:
Data(x=[507, 4], edge_index=[2, 39607], edge_label=[39607, 1])
Now, when I perform the train and val splitting, the two resulting graphs look as follows: train:
Data(x=[507, 4], edge_index=[2, 33668], edge_label=[16834, 1], edge_label_index=[2, 16834])
val:Data(x=[507, 4], edge_index=[2, 33668], edge_label=[5940, 1], edge_label_index=[2, 5940])
My model is as follows:
Then, I proceed to construct my datamodule as follows:
Running this leads to the following error:
It suggests that somehow PyG can not index over my graph, i.e. Data object from torch_geometric. I reached out to folks over at PyTorch Lightning, and Lightning developer Justin Goheen was so kind to step through my code with me. We traced back the problems to the torch_geometric.loader.DataLoader, which if we feed it any of our {train, val}_graphs after RandomLinkSplit, returns the exact error seen above. Note, that we get the same error if we use the standard torch DataLoader from torch.utils.DataLoader
Versions
Collecting environment information... PyTorch version: 2.0.1 Is debug build: False CUDA used to build PyTorch: None ROCM used to build PyTorch: N/A
OS: macOS 14.1.1 (arm64) GCC version: Could not collect Clang version: 15.0.0 (clang-1500.0.40.1) CMake version: Could not collect Libc version: N/A
Python version: 3.8.17 | packaged by conda-forge | (default, Jun 16 2023, 07:11:32) [Clang 14.0.6 ] (64-bit runtime) Python platform: macOS-14.1.1-arm64-arm-64bit Is CUDA available: False CUDA runtime version: No CUDA CUDA_MODULE_LOADING set to: N/A GPU models and configuration: No CUDA Nvidia driver version: No CUDA cuDNN version: No CUDA HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True
CPU: Apple M2
Versions of relevant libraries: [pip3] numpy==1.24.4 [pip3] torch==2.0.1 [pip3] torch-geometric==2.3.1 [pip3] torchmetrics==1.3.0.post0 [conda] numpy 1.24.4 pypi_0 pypi [conda] torch 2.0.1 pypi_0 pypi [conda] torch-geometric 2.3.1 pypi_0 pypi [conda] torchmetrics 1.3.0.post0 pypi_0 pypi