GithubHelp home page GithubHelp logo

pyg-team / pyg-lib Goto Github PK

View Code? Open in Web Editor NEW
159.0 159.0 38.0 526 KB

Low-Level Graph Neural Network Operators for PyG

Home Page: https://pyg-lib.readthedocs.io

License: Other

Python 20.46% C++ 71.01% CMake 1.80% Cuda 6.74%
deep-learning geometric-deep-learning graph-convolutional-networks graph-neural-networks pytorch

pyg-lib's People

Contributors

akihironitta avatar babymastodon avatar damianszwichtenberg avatar jokeren avatar kaixuanliu avatar kgajdamo avatar mananshah99 avatar mszarma avatar olhababicheva avatar pmpalang avatar pre-commit-ci[bot] avatar puririshi98 avatar rusty1s avatar sauravmaheshkar avatar vid-koci avatar yanbing-j avatar yaox12 avatar yaoyaowd avatar zechengz avatar zenotan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyg-lib's Issues

Cannot import pyg-lib on macOS

๐Ÿ› Describe the bug

I'm unable to get pyg-lib to import on my Mac. It seems to affect both Intel and M1 Macs (I'm on an Intel, but an M1 user reported the same issue: #211 (comment)). The original issue in the thread may not be relevant, thus I'm opening a new issue.

Minimal example is simply importing pyg_lib:

import pyg_lib

In my case, I was importing torch_geometric.graphgym.config, resulting in the following stack trace:

  File "/Users/semo/PycharmProjects/pretrained-pe/graphgym/act/example.py", line 3, in <module>
    from torch_geometric.graphgym.config import cfg
  File "/Users/semo/PycharmProjects/pretrained-pe/venv/lib/python3.10/site-packages/torch_geometric/__init__.py", line 4, in <module>
    import torch_geometric.data
  File "/Users/semo/PycharmProjects/pretrained-pe/venv/lib/python3.10/site-packages/torch_geometric/data/__init__.py", line 1, in <module>
    from .data import Data
  File "/Users/semo/PycharmProjects/pretrained-pe/venv/lib/python3.10/site-packages/torch_geometric/data/data.py", line 20, in <module>
    from torch_sparse import SparseTensor
  File "/Users/semo/PycharmProjects/pretrained-pe/venv/lib/python3.10/site-packages/torch_sparse/__init__.py", line 39, in <module>
    from .storage import SparseStorage  # noqa
  File "/Users/semo/PycharmProjects/pretrained-pe/venv/lib/python3.10/site-packages/torch_sparse/storage.py", line 7, in <module>
    from torch_sparse.utils import Final, index_sort
  File "/Users/semo/PycharmProjects/pretrained-pe/venv/lib/python3.10/site-packages/torch_sparse/utils.py", line 5, in <module>
    import torch_sparse.typing
  File "/Users/semo/PycharmProjects/pretrained-pe/venv/lib/python3.10/site-packages/torch_sparse/typing.py", line 2, in <module>
    import pyg_lib  # noqa
  File "/Users/semo/PycharmProjects/pretrained-pe/venv/lib/python3.10/site-packages/pyg_lib/__init__.py", line 38, in <module>
    load_library('libpyg')
  File "/Users/semo/PycharmProjects/pretrained-pe/venv/lib/python3.10/site-packages/pyg_lib/__init__.py", line 35, in load_library
    torch.ops.load_library(spec.origin)
  File "/Users/semo/PycharmProjects/pretrained-pe/venv/lib/python3.10/site-packages/torch/_ops.py", line 573, in load_library
    ctypes.CDLL(path)
  File "/Users/semo/.pyenv/versions/3.10.9/lib/python3.10/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Users/semo/PycharmProjects/pretrained-pe/venv/lib/python3.10/site-packages/libpyg.so, 0x0006): Library not loaded: /Users/runner/hostedtoolcache/Python/3.10.8/x64/lib/libpython3.10.dylib
  Referenced from: <16F9F1F8-8305-3FAA-9EB1-C519E67F7DAC> /Users/semo/PycharmProjects/pretrained-pe/venv/lib/python3.10/site-packages/libpyg.so
  Reason: tried: '/Users/runner/hostedtoolcache/Python/3.10.8/x64/lib/libpython3.10.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/hostedtoolcache/Python/3.10.8/x64/lib/libpython3.10.dylib' (no such file), '/Users/runner/hostedtoolcache/Python/3.10.8/x64/lib/libpython3.10.dylib' (no such file), '/usr/local/lib/libpython3.10.dylib' (no such file), '/usr/lib/libpython3.10.dylib' (no such file, not in dyld cache)

Environment

  • pyg-lib version: 0.1.0/latest from source(0.1.0+pt113)
  • PyTorch version: 1.13.1/2.0.0
  • OS: macOS 13.2.1
  • Python version: 3.10.8
  • CUDA/cuDNN version: None/CPU (Intel Core i9)
  • How you installed PyTorch and pyg-lib (conda, pip, source): Both, see below
  • Any other relevant information:

Things I've tried:

  • Install torch & torch_geometric packages via conda and pyg_lib via pip in a clean env
  • Install torch, torch_geometric packages and pyg_lib via pip only
  • Test with PyTorch 2.0.0 and 1.13.1 (I'm positive the same setup worked with 1.13.1 and latest torch_geometric/pyg_lib last week)

I hope to have pyg_lib on Windows available soon

๐Ÿš€ The feature, motivation and pitch

I'm working on Omicverse on Windows, but the installation is unsuccessful because this configuration is missing

Alternatives

No response

Additional context

No response

Dependencies wipe out existing ones

๐Ÿ› Describe the bug

We're installing on a nvidia rapids container (22.12), with carefully selected cuda version (in this case 11.3, where their max is 11.5). Installing pyg-lib via pip does not preserve existing installs. For example, cuda 11.7 gets installed, which would break rapids. I did not see a conda version that might have been more careful.

Environment

rapids 22.12 ubuntu 20.04 cuda 11.3 container with torch 1.12

pyg-lib missing from torch==2.0.0 wheels

๐Ÿ› Describe the bug

Running any of the following install commands on Linux fails

pip install pyg-lib  -f https://data.pyg.org/whl/torch-2.0.0+cpu.html
pip install pyg-lib  -f https://data.pyg.org/whl/torch-2.0.0+cu117.html
pip install pyg-lib  -f https://data.pyg.org/whl/torch-2.0.0+cu118.html

Upon inspection of data.pyg.org/whl/, I see that pyg-lib is missing from the torch-2.0.0 directories.

Environment

  • pyg-lib version: latest
  • PyTorch version:
  • OS: Ubuntu
  • Python version: 3.8
  • CUDA/cuDNN version: 1.18
  • How you installed PyTorch and pyg-lib (conda, pip, source): pip
  • Any other relevant information:

Apple silicon support

๐Ÿš€ The feature, motivation and pitch

I'm trying to use Hierarchical Neighborhood Sampling for my project. I found that this feature requires pyg-lib, which is not available on Apple Silicon. Is there any plan to add Apple Silicon support?

Alternatives

No response

Additional context

No response

Errors when sampling neighbors with disjoint setting

๐Ÿ› Describe the bug

from ogb.nodeproppred import PygNodePropPredDataset
from torch_geometric.loader import NeighborLoader



if __name__ == '__main__':
    dataset = PygNodePropPredDataset(name='ogbn-products', root='~/GNSL/on_products/dataset')
    split_idx= dataset.get_idx_split()
    data = dataset[0]
    # transform_sampler_output
    #print(data.x, data.x.shape, data.x.dtype)

    loader = NeighborLoader(data, num_neighbors=[10, 10], batch_size=2, disjoint=1, input_nodes=split_idx['train'])
    for mini_batch in loader:
        print(mini_batch)
        break

When I run python3 data.py, this program encounters exception:

Traceback (most recent call last):
File "/root/GG4RL/data.py", line 14, in
for mini_batch in loader:
File "/root/miniconda3/envs/digress/lib/python3.10/site-packages/torch_geometric/loader/base.py", line 36, in next
return self.transform_fn(next(self.iterator))
File "/root/miniconda3/envs/digress/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 633, in next
data = self._next_data()
File "/root/miniconda3/envs/digress/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 677, in _next_data
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File "/root/miniconda3/envs/digress/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 54, in fetch
return self.collate_fn(data)
File "/root/miniconda3/envs/digress/lib/python3.10/site-packages/torch_geometric/loader/node_loader.py", line 117, in collate_fn
out = self.node_sampler.sample_from_nodes(input_data)
File "/root/miniconda3/envs/digress/lib/python3.10/site-packages/torch_geometric/sampler/neighbor_sampler.py", line 174, in sample_from_nodes
return node_sample(inputs, self._sample)
File "/root/miniconda3/envs/digress/lib/python3.10/site-packages/torch_geometric/sampler/neighbor_sampler.py", line 358, in node_sample
out = sample_fn(seed, seed_time)
File "/root/miniconda3/envs/digress/lib/python3.10/site-packages/torch_geometric/sampler/neighbor_sampler.py", line 282, in _sample
out = torch.ops.pyg.neighbor_sample(
File "/root/miniconda3/envs/digress/lib/python3.10/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 'edge_weight' but instead found type 'bool'.
Position: 6
Value: True
Declaration: pyg::neighbor_sample(Tensor rowptr, Tensor col, Tensor seed, int[] num_neighbors, Tensor? 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

Environment

  • pyg-lib version: '0.3.1+pt20cu118'
  • PyTorch version: '2.0.1+cu118'
  • OS: Ubuntu 18.04
  • Python version: 3.10
  • CUDA/cuDNN version: 11.8
  • How you installed PyTorch and pyg-lib (conda, pip, source): pip
  • Any other relevant information: installed GLIBC-2.9 and pytorch_geometric: 2.3.1

An error occurs when I run "hetero_neighbor.py" in benchmark\sampler

๐Ÿ› Describe the bug

I ran the hetero_neighbor.py in command line without changing any code, but I got this error.

Traceback (most recent call last):
  File "/home/xxx/Documents/pyg-lib/benchmark/sampler/hetero_neighbor.py", line 146, in <module>
    test_hetero_neighbor()
  File "/home/xxx/anaconda3/envs/pyG-env/lib/python3.11/site-packages/pyg_lib/testing.py", line 17, in wrapper
    func(*args, **kwargs)
  File "/home/xxx/anaconda3/envs/pyG-env/lib/python3.11/site-packages/pyg_lib/testing.py", line 65, in wrapper
    func(*args, dataset=dataset, **kwargs)
  File "/home/xxx/Documents/pyg-lib/benchmark/sampler/hetero_neighbor.py", line 91, in test_hetero_neighbor
    pyg_lib.sampler.hetero_neighbor_sample(
TypeError: hetero_neighbor_sample() got an unexpected keyword argument 'edge_time_dict'

Environment

  • pyg-lib version: 0.3
  • PyTorch version: 2.1.0
  • OS: ubuntu
  • Python version: 3.11.5
  • CUDA/cuDNN version: cuda_11.8
  • How you installed PyTorch and pyg-lib (conda, pip, source): install pytorch by 'conda' but pyg-lib by 'pip'
  • Any other relevant information:

Cannot install into python 3.11 + torch 2.2.0 environment

๐Ÿ˜ต Describe the installation problem

can't find any available versions of pyg_lib if I use python 3.11 + torch2.2.0 (cpu):

I can create an empty conda (mamba) environment using this env.yaml:

name: empty311
channels:
  - conda-forge
dependencies:
  - python=3.11
  - pip

and then when I mamba activate empty311 and try to pip install with

(empty311) $ pip install --find-links=http://data.pyg.org/whl/torch-2.2.0+cpu.html  --trusted-host=data.pyg.org -r min_requirements.in

where min_requirements.in is merely:

torch==2.2.0
pyg_lib

Then I get this error:

% pip install --find-links=http://data.pyg.org/whl/torch-2.2.0+cpu.html  --trusted-host=data.pyg.org -r min_requirements.in
Looking in links: http://data.pyg.org/whl/torch-2.2.0+cpu.html
Collecting torch==2.2.0 (from -r min_requirements.in (line 1))
  Using cached torch-2.2.0-cp311-none-macosx_10_9_x86_64.whl.metadata (25 kB)
ERROR: Could not find a version that satisfies the requirement pyg_lib (from versions: none)
ERROR: No matching distribution found for pyg_lib

If I change to either use python 3.10 or torch 2.1.0, then it works fine.

I am on Mac OS 14.2.1 trying to install any version of pyg-lib of which 0.4.0 is the only option.

Environment

  • pyg-lib version: any, but specifically 0.4.0
  • PyTorch version: 2.2.0
  • OS: Mac OSX 14.2.1
  • Python version: 3.11
  • CUDA/cuDNN version: N/A
  • How you installed PyTorch and pyg-lib (conda, pip, source): pip
  • Any other relevant information:

Specify compatible PyTorch version in Requires-Dist

๐Ÿš€ The feature, motivation and pitch

Since each distribution wheel is built for a particular version of PyTorch, it would be helpful to specify that PyTorch version in Requires-Dist in the package metadata. E.g., in setup.py: setup(install_requires=['torch==1.13.1+cu116']).

This helps fail-fast if an incompatible version is being installed. For organizations storing these wheels in a private package repository, this also allows pip to automatically select the right version if a version range is specified.

Alternatives

Can otherwise specify a particular Torch version's subdirectory of the downloads site using pip --find-links ..., but that doesn't fail-fast if the version is incompatible

Additional context

No response

segment_matmul failing on CUDA

๐Ÿ› Describe the bug

I was trying to reproduce the minimal example listed in the documentation for segment_matmul. However, I've found that while it works on the CPU, it fails on the GPU with a RuntimeError. Here's the code I've used:

# segmat.py
from argparse import ArgumentParser

from torch_geometric.typing import pyg_lib
import torch

parser = ArgumentParser()
parser.add_argument('device', type=str)
args = parser.parse_args()

device = torch.device(args.device)
inputs = torch.randn(8, 16, device=device)
ptr = torch.tensor([0, 5, 8], device=device)
other = torch.randn(2, 16, 32, device=device)

out = pyg_lib.ops.segment_matmul(inputs, ptr, other)

Running

python segmat.py cpu

works, but

python segmat.py cuda

throws the following:

Traceback (most recent call last):
  File "/home/daniel/Drive/VU/projects/2023-06-09-exigraph/exigraph/segmat.py", line 15, in <module>
    out = pyg_lib.ops.segment_matmul(inputs, ptr, other)
  File "/home/daniel/miniconda3/envs/exigraph/lib/python3.10/site-packages/pyg_lib/ops/__init__.py", line 95, in segment_matmul
    out = torch.ops.pyg.segment_matmul(inputs, ptr, other)
  File "/home/daniel/miniconda3/envs/exigraph/lib/python3.10/site-packages/torch/_ops.py", line 502, in __call__
    return self._op(*args, **kwargs or {})
RuntimeError: GroupedGEMM run failed

Environment

  • pyg-lib version: 0.2.0+pt20cu117
  • PyTorch version: 2.0.1
  • OS: Ubuntu 22.04.2 LTS
  • Python version: 3.10.11
  • CUDA/cuDNN version: 11.7
  • How you installed PyTorch and pyg-lib (conda, pip, source): pip, using
pip install pyg-lib -f https://data.pyg.org/whl/torch-2.0.0+cu117.html

recent changes to pip installation gives weird error when uninstalling

๐Ÿ˜ต Describe the installation problem

so if I have an old installation of pyg-lib I can uninstall it:

root@8239e7e0e1e1:/opt/pyg/pyg-lib# pip uninstall -y pyg-lib
Found existing installation: pyg-lib 0.1.0
Uninstalling pyg-lib-0.1.0:
  Successfully uninstalled pyg-lib-0.1.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

Then I try to install from source:

root@8239e7e0e1e1:/opt/pyg/pyg-lib# pip install -e .
Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com
Obtaining file:///opt/pyg/pyg-lib
Installing collected packages: pyg-lib
  Running setup.py develop for pyg-lib

After this I cannot uninstall it:

root@8239e7e0e1e1:/opt/pyg/pyg-lib# pip uninstall -y pyg-lib
Found existing installation: pyg-lib 0.1.0
Can't uninstall 'pyg-lib'. No files were found to uninstall.
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
root@8239e7e0e1e1:/opt/pyg/pyg-lib# pip show pyg-lib
Name: pyg-lib
Version: 0.1.0
Summary: Low-Level Graph Neural Network Operators for PyG
Home-page: https://github.com/pyg-team/pyg-lib
Author: PyG Team
Author-email: [email protected]
License: UNKNOWN
Location: /opt/pyg/pyg-lib
Requires: 
Required-by:

Notice how instead of pyg-lib-0.1.0, it is not showing as pyg-lib 0.1.0 and then saying there is nothing to uninstall

Environment

  • pyg-lib version: pip install -e . from master
  • OS: linux

pyg_lib wheels missing from https://data.pyg.org/whl/torch-2.2.0%2Bcpu.html

๐Ÿ˜ต Describe the installation problem

pyg-lib is missing from https://data.pyg.org/whl/torch-2.2.0%2Bcpu.html, so pip installing pyg_lib following the instructions fails:

Run pip install pyg_lib torch_scatter torch_sparse torch_cluster torch_spline_conv torch_geometric -f https://data.pyg.org/whl/torch-2.2.0+cpu.html
Looking in links: https://data.pyg.org/whl/torch-2.2.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

Environment

  • PyTorch version: 2.2.0
  • OS: Linux
  • Python version: 3.10
  • CUDA/cuDNN version: CPU
  • How you installed PyTorch and pyg-lib (conda, pip, source): pip

[RFC] `cugraph`-based neighborhood sampling

๐Ÿš€ The feature, motivation and pitch

GPU-based neighborhood sampling can accelerate mini-batch creation for graphs that fit into GPU memory.

Currently, the (solely) CPU-based sampling interface inside PyG looks as follows:

template <bool replace, bool directed>
tuple<torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor>
sample(const torch::Tensor &colptr, const torch::Tensor &row,
       const torch::Tensor &input_node, const vector<int64_t> num_neighbors)

The PyG routine expects:

  • (colptr, row): CSC/CSR representation of the graph
  • input_node: The seed nodes for which to sample neighbors
  • num_neighbors: A list of neighbors to sample in each layer
  • replace: Sample without or with replacement
  • directed: Whether sampled edges are directed or not. If not, we extract the full subgraph of sampled nodes.

It returns (re-labeled) row and col vectors of the sampled subgraph/adjacency matrix, as well as output_node_id and output_edge_id of the sampled nodes/edges to perform feature fetching in a later stage.

On the other side, the sampling interface inside cugraph looks as follows:

template <typename graph_t>
std::tuple<rmm::device_uvector<typename graph_t::edge_type>,
           rmm::device_uvector<typename graph_t::vertex_type>>
sample_neighbors_adjacency_list(raft::handle_t const& handle,
                                raft::random::RngState& rng_state,
                                graph_t const& graph,
                                typename graph_t::vertex_type const* ptr_d_start,
                                size_t num_start_vertices,
                                size_t sampling_size,
                                ops::gnn::graph::SamplingAlgoT sampling_algo)

The major difference seems to be that cugraph performs sampling for 1-hop, while PyG supports multi-hop sampling (which can be fixed easily by just calling the cugraph routine multiple times) [to be confirmed by @pyg-team/nvidia-team].

Roadmap

For integrating GPU-based sampling inside PyG, we thus need to:

  • Integrate torch-sparse neighorhood sampling interface in pyg-lib
  • cugraph as a dependency inside pyg-lib
  • Call the cugraph-based sampling routine inside the GPU-based dispatcher
  • Integrate changes on PyG side

Issue iterating with `NeighborLoader` on pyg-lib 0.4.0

๐Ÿ› Describe the bug

Hey PyG team ๐Ÿ‘‹ I'm getting an error when trying to iterate with a NeighborLoader. I started getting this a couple of days ago, coinciding with the release of pyg-lib 0.4.0. I tested with pyg-lib 0.3.1, and the issue went away.

You should be able to reproduce the bug with the following code from the docs:

import os

!pip install torch==2.2.*
import torch
os.environ['CUDA'] = torch.version.cuda.replace(".", "")

!pip install --upgrade torch-geometric
!pip install --upgrade pyg-lib -f https://data.pyg.org/whl/torch-2.2.0+cu${CUDA}.html
!pip install --upgrade torch-sparse -f https://data.pyg.org/whl/torch-2.2.0+cu${CUDA}.html

from torch_geometric.datasets import Planetoid
from torch_geometric.loader import NeighborLoader

data = Planetoid(".", name='Cora')[0]

loader = NeighborLoader(
    data,
    # Sample 30 neighbors for each node for 2 iterations
    num_neighbors=[30] * 2,
    # Use a batch size of 128 for sampling training nodes
    batch_size=128,
    input_nodes=data.train_mask,
)

sampled_data = next(iter(loader))
print(sampled_data.batch_size)

Environment

  • pyg-lib version: 0.4.0
  • PyTorch version: 2.2.0
  • OS: Linux
  • Python version: 3.9
  • CUDA/cuDNN version: 12.1
  • How you installed PyTorch and pyg-lib (conda, pip, source): Reference code sample
  • Any other relevant information:

`test_fused_scatter_reduce` fails w/ latest triton (compilation error)

๐Ÿ› Describe the bug

the error is most likely caused by an update to triton to commit d54c04abe2c3e67b2139c68cdbda87b59e8dd01b

Screen Shot 2023-03-07 at 12 45 08 PM

root@4fda8fcd9b9f:/workspace# py.test -s /opt/pyg/pyg-lib/test/ops/test_scatter_reduce.py::test_fused_scatter_reduce -v
/usr/local/lib/python3.8/dist-packages/triton/compiler.py:942: CompilationError

full log:
triton_compile_err.txt

Environment

No response

[Roadmap] 0.1.0 Release ๐Ÿš€

The first pyg-lib release will focus on unifying the implementations from torch-sparse and torch-cluster into a single package in order to reduce the number of external low-level library dependencies of PyG.
In addition, implementations will be improved, e.g., by out-sourcing common routines into re-usable building blocks, unifiying the interfaces, supporting various data types, biased sampling, etc.
New functionality will be integrated for temporal-based learning and GNN acceleration.

Samplers

Priority 0

  • Unify common routines behind re-usable functions (e.g., sampling with/without replacement)
  • Deterministic sampling routines
  • Full support for different data types, e.g., int32, int64, etc
  • Integration of cugraph dependency
  • Neighbor Sampling neighbor_sample(rowptr, col, seed, num_neighbors):
    • Support for homogeneous graphs (CPU+GPU)
    • Support for heterogeneous graphs (CPU-only)
    • replace: sampling with or without replacement
    • directed: sub-tree vs sub-graph sampling (CPU-only)
    • disjoint: disjoint subtrees for every seed node (CPU-only)
    • temporal: temporal sampling (CPU-only)
    • weighted: Support for biased sampling (CPU-only)
    • temporal_weighted: Support for biased temporal sampling (CPU-only)
    • return_edge_id: Support for returning edge IDs (CPU-only)
  • Subgraph Sampling subgraph_sample(rowptr, col, nodes):
    • Support for homogeneous graphs (CPU+GPU)
    • Support for heterogeneous graphs (CPU-only)
    • return_edge_id: Support for returning edge IDs (CPU-only)

Priority 1

  • Random Walk Sampling random_walk(rowptr, col, nodes):
    • Support for homogeneous graphs (CPU+GPU)
    • Support for heterogeneous graphs (CPU-only)
    • weighted: Support for biased sampling (CPU-only)
    • node2vec-based sampling (CPU-only)
    • return_edge_id: Support for returning edge IDs (CPU-only)
  • Heterogeneous Graph Transformer Sampling hgt_sample(rowptr, dict, seed):
    • weighted: Support for biased sampling (CPU-only)

Operators

Priority 0

Priority 1

  • sparse_softmax(src, index):
    • forward (CPU+GPU) (#135)
    • backward (CPU+GPU)

Others

Priority 0 (refactor only)

  • METIS graph partitioning
  • Farthest point sampling fps
  • k-NN graph generation
  • radius graph generation/ball query

Priority 1

  • Full support for different data types, e.g., int32, int64, etc

pyg_lib and torch_sparse cannot be loaded

๐Ÿ› Describe the bug

I have installed the torch and torch_sparse and pyg_lib packages successfully, but when I import torch_sparse just report error as folling:
OSError: dlopen(/Users/wakala/venvs/versions/3.12.2/torch/lib/python3.12/site-packages/libpyg.so, 0x0006): Library not loaded: /Library/Frameworks/Python.framework/Versions/3.12/Python
Referenced from: <7BF3ABB0-5875-3736-8AB2-1784D3EFB687> /Users/wakala/venvs/versions/3.12.2/torch/lib/python3.12/site-packages/libpyg.so
Reason: tried: '/Library/Frameworks/Python.framework/Versions/3.12/Python' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/Python.framework/Versions/3.12/Python' (no such file), '/Library/Frameworks/Python.framework/Versions/3.12/Python' (no such file)

Environment

  • pyg-lib version: 0.4.0+pt23
  • PyTorch version: 2.3.0
  • OS: MacOS 14.4.1 (23E224)
  • Python version: 3.12.2
  • CUDA/cuDNN version:
  • How you installed PyTorch and pyg-lib (conda, pip, source): pip
  • Any other relevant information:

Conda forge package

๐Ÿ˜ต Describe the installation problem

I am building a conda package for pyg-lib at conda-forge/staged-recipes#21566

For now, it's only for Linux cpu and cuda but I guess OSX should build as well.

Are you willing to be added as a maintainer of the package as well?

Currently the conda recipe relies on git submodule for parallel-hashmap and cutlass. But those two deps are available on conda-forge and so it's preferred for the conda package to rely on those. But it requires modifying the CMake file for this to work.

Environment

  • pyg-lib version:
  • PyTorch version:
  • OS:
  • Python version:
  • CUDA/cuDNN version:
  • How you installed PyTorch and pyg-lib (conda, pip, source):
  • Any other relevant information:

Add plus notation to wheel filenames at data.pyg.org/whl

๐Ÿ› Describe the bug

it would be cool to introduce the plus notation in the wheel filenames, to avoid having to pass --force-reinstall

currently, the filenames are identical (just a different URL path), which confuses pip into thinking there is no need for a re-install:

https://data.pyg.org/whl/torch-1.9.0+cu111/torch_sparse-0.6.12-cp36-cp36m-linux_x86_64.whl
https://data.pyg.org/whl/torch-1.9.0+cpu/torch_sparse-0.6.12-cp36-cp36m-linux_x86_64.whl
# vs
https://download.pytorch.org/whl/cu111/torch-1.9.0+cu111-cp36-cp36m-linux_x86_64.whl
https://download.pytorch.org/whl/cpu/torch-1.9.0+cpu-cp36-cp36m-linux_x86_64.whl

use-case: docker image (and other CI pipelines) building on top of env that already contains the cpu versions

ref ray-project/ray#26072 (comment)

current behaviour (whereas torch would be overwritten at the second command due to plus notation in the wheel filenames):

$ pip install --no-deps torch-sparse==0.6.12 --find-links https://data.pyg.org/whl/torch-1.9.0+cpu.html
Looking in links: https://data.pyg.org/whl/torch-1.9.0+cpu.html
Collecting torch-sparse==0.6.12
  Using cached https://data.pyg.org/whl/torch-1.9.0%2Bcpu/torch_sparse-0.6.12-cp38-cp38-linux_x86_64.whl (640 kB)
Installing collected packages: torch-sparse
Successfully installed torch-sparse-0.6.12
$ pip install --no-deps torch-sparse==0.6.12 --find-links https://data.pyg.org/whl/torch-1.9.0+cu111.html
Looking in links: https://data.pyg.org/whl/torch-1.9.0+cu111.html
Requirement already satisfied: torch-sparse==0.6.12 in /usr/local/lib/python3.8/dist-packages (0.6.12)
$ pip install --no-deps --force-reinstall torch-sparse==0.6.12 --find-links https://data.pyg.org/whl/torch-1.9.0+cu111.html
Looking in links: https://data.pyg.org/whl/torch-1.9.0+cu111.html
Collecting torch-sparse==0.6.12
  Downloading https://data.pyg.org/whl/torch-1.9.0%2Bcu111/torch_sparse-0.6.12-cp38-cp38-linux_x86_64.whl (3.7 MB)
     โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 3.7/3.7 MB 4.0 MB/s eta 0:00:00
Installing collected packages: torch-sparse
  Attempting uninstall: torch-sparse
    Found existing installation: torch-sparse 0.6.12
    Uninstalling torch-sparse-0.6.12:
      Successfully uninstalled torch-sparse-0.6.12
Successfully installed torch-sparse-0.6.12

--no-deps only added for demo purposes (shorter logs)

plus notation is a non-breaking change from pip's side (current install commands will still work identically), it will just allow pip to differentiate the use-case above.

Environment

N/A

An error occurred while installing from the source on aarch64.

๐Ÿ˜ต Describe the installation problem

An error occurred while installing from the source on aarch64.
Actually, I want to install torch-geometric on aarch64. I executed the following command.

pip install ninja wheel
pip install git+https://github.com/pyg-team/pyg-lib.git

However, the following error occurred.

  Running command git clone --filter=blob:none --quiet https://github.com/pyg-team/pyg-lib.git /tmp/pip-req-build-i0glx2l_
  Running command git submodule update --init --recursive -q
  error: subprocess-exited-with-error
  
  ร— python setup.py bdist_wheel did not run successfully.
  โ”‚ exit code: 1
  โ•ฐโ”€
      creating build/lib.linux-aarch64-cpython-38/pyg_lib/ops
      copying pyg_lib/ops/scatter_reduce.py -> build/lib.linux-aarch64-cpython-38/pyg_lib/ops
      copying pyg_lib/ops/__init__.py -> build/lib.linux-aarch64-cpython-38/pyg_lib/ops
      running build_ext
      -- The C compiler identification is unknown
      -- The CXX compiler identification is unknown
      -- Check for working C compiler: /usr/bin/cc
      -- Check for working C compiler: /usr/bin/cc -- broken
      CMake Error at /usr/share/cmake/Modules/CMakeTestCCompiler.cmake:60 (message):
        The C compiler
      
          "/usr/bin/cc"
      
        is not able to compile a simple test program.
      
        It fails with the following output:
      
          Change Dir: /tmp/pip-req-build-i0glx2l_/build/temp.linux-aarch64-cpython-38/CMakeFiles/CMakeTmp
      
          Run Build Command(s):/xxx/anaconda3/envs/env_name/bin/ninja cmTC_3cc80 && [1/2] Building C object CMakeFiles/cmTC_3cc80.dir/testCCompiler.c.o
          FAILED: CMakeFiles/cmTC_3cc80.dir/testCCompiler.c.o
          /usr/bin/cc    -o CMakeFiles/cmTC_3cc80.dir/testCCompiler.c.o   -c testCCompiler.c
          cc1: error: /xxxxx/anaconda3/bin: Permission denied
          cc1: error: /xxxxx/anaconda3/bin: Permission denied
          cc1: error: /xxxxx/anaconda3/bin: Permission denied
          cc1: error: /xxxxx/anaconda3/bin: Permission denied
          cc1: error: /xxxxx/anaconda3/bin: Permission denied
          cc1: error: /root/bin: Permission denied
          ninja: build stopped: subcommand failed.
      
      
      
      

        File "/xxx/anaconda3/envs/env_name/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
          self.run_command(cmd)
        File "/xxx/anaconda3/envs/env_name/lib/python3.8/site-packages/setuptools/dist.py", line 1234, in run_command
          super().run_command(command)
        File "/xxx/anaconda3/envs/env_name/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/xxx/anaconda3/envs/env_name/lib/python3.8/site-packages/wheel/bdist_wheel.py", line 364, in run
          self.run_command("build")
        File "/xxx/anaconda3/envs/env_name/lib/python3.8/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
          self.distribution.run_command(command)
        File "/xxx/anaconda3/envs/env_name/lib/python3.8/site-packages/setuptools/dist.py", line 1234, in run_command
          super().run_command(command)
        File "/xxx/anaconda3/envs/env_name/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/xxx/anaconda3/envs/env_name/lib/python3.8/site-packages/setuptools/_distutils/command/build.py", line 131, in run
          self.run_command(cmd_name)
        File "/xxx/anaconda3/envs/env_name/lib/python3.8/site-packages/setuptools/_distutils/cmd.py", line 318,
 in run_command
          self.distribution.run_command(command)
        File "/xxx/anaconda3/envs/env_name/lib/python3.8/site-packages/setuptools/dist.py", line 1234, in run_c
ommand
          super().run_command(command)
        File "/xxx/anaconda3/envs/env_name/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 988
, in run_command
          cmd_obj.run()
        File "/xxx/anaconda3/envs/env_name/lib/python3.8/site-packages/setuptools/command/build_ext.py", line 8
4, in run
          _build_ext.run(self)
        File "/xxx/anaconda3/envs/env_name/lib/python3.8/site-packages/setuptools/_distutils/command/build_ext.
py", line 345, in run
          self.build_extensions()
        File "/xxx/anaconda3/envs/env_name/lib/python3.8/site-packages/setuptools/_distutils/command/build_ext.
py", line 467, in build_extensions
          self._build_extensions_serial()
        File "/xxx/anaconda3/envs/env_name/lib/python3.8/site-packages/setuptools/_distutils/command/build_ext.
py", line 493, in _build_extensions_serial
          self.build_extension(ext)
        File "/tmp/pip-req-build-i0glx2l_/setup.py", line 82, in build_extension
          subprocess.check_call(['cmake', ext.sourcedir] + cmake_args,
        File "/xxx/anaconda3/envs/env_name/lib/python3.8/subprocess.py", line 364, in check_call
          raise CalledProcessError(retcode, cmd)
      subprocess.CalledProcessError: Command '['cmake', '/tmp/pip-req-build-i0glx2l_', '-DBUILD_TEST=OFF', '-DBUILD_BENCHMARK=OFF', '-DUSE_PYTHON=ON', '-
DWITH_CUDA=OFF', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-req-build-i0glx2l_/build/lib.linux-aarch64-cpython-38', '-DCMAKE_BUILD_TYPE=RELEASE', '-DCMAK
E_PREFIX_PATH=/xxx/anaconda3/envs/env_name/lib/python3.8/site-packages/torch/share/cmake', '-GNinja']' returned
 non-zero exit status 1.
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pyg-lib
ERROR: Could not build wheels for pyg-lib, which is required to install pyproject.toml-based projects

I don't know what problems I have encountered and what good solutions are there. Or how to install torch-geometric on aarch64? The document only mentions that it can be installed from the source. At present, I am just an ordinary user of the server, and I don't have root permission.

Environment

  • pyg-lib version:
  • PyTorch version: 1.11.0+cu113
  • OS: Linux dlhpcshare-ccs-cli-1 4.19.90-24.4.v2101.ky10.aarch64
  • Python version: 3.8.18
  • CUDA/cuDNN version: 11.3 ๏ผˆBuild cuda_11.3.r11.3/compiler.29745058_0๏ผ‰
  • How you installed PyTorch and pyg-lib (conda, pip, source): source
  • Any other relevant information: aarch64

Error while using LinkLoaderNeighbor function which is indirectly due to installations issues. (Please consider it urgently as my project is stuck due this)

๐Ÿ› Describe the bug

I am attaching the Image of the bug:
Screenshot (513)

Environment

  • pyg-lib version:
  • PyTorch version: 2.2.1+cu121
  • OS: Windows
  • Python version:3.10.12
  • CUDA/cuDNN version: CPU
  • How you installed PyTorch and pyg-lib (conda, pip, source): pip (Note: there was also issue which is currently already opened by someone regarding the setup.py file)
  • Any other relevant information:

Plus notation for .whl filenames overlap between pytorch patch versions.

๐Ÿ› Describe the bug

As mentioned in #66 (comment) there seems to be a regression of sorts to the + notation for .whl generation.

Copied from other issue

I believe to have found an edge case which resurfaces the original comment of "currently, the filenames are identical (just a different URL path), which confuses pip into thinking there is no need for a re-install"

The torch version in the + metadata is specified up to the minor version and therefore filenames can be identical between torch versions.

In https://data.pyg.org/whl/torch-1.13.1%2Bcu116.html (for 1.13.1)
pyg_lib-0.1.0+pt113cu116-cp310-cp310-linux_x86_64.whl
In https://data.pyg.org/whl/torch-1.13.0%2Bcu116.html (for 1.13.0)
pyg_lib-0.1.0+pt113cu116-cp310-cp310-linux_x86_64.whl

This then resurfaces all the mentioned 'problems' with pip not reinstalling when it clearly should when the torch version (or cuda) version is updated. Could we fix that by setting the torch version to the patch version?

Thank you for looking into this!

Environment

N/A

Couldn't able to run LinkNeighborloader due to the backend issue, please explain its urgent

๐Ÿ› Describe the bug

`
Screenshot (625)

edge_label_index = train_data["user", "rates", "movie"].edge_label_index
edge_label = train_data["user", "rates", "movie"].edge_label

train_loader = LinkNeighborLoader(
data=train_data,
num_neighbors=[20, 10],
neg_sampling_ratio=2.0,
edge_label_index=(("user", "rates", "movie"), edge_label_index),
edge_label=edge_label,
batch_size=128,
shuffle=True,
)

Inspect a sample:

sampled_data = next(iter(train_loader))

print("Sampled mini-batch:")
print("===================")
print(sampled_data)

assert sampled_data["user", "rates", "movie"].edge_label_index.size(1) == 3 * 128
assert sampled_data["user", "rates", "movie"].edge_label.min() == 0
assert sampled_data["user", "rates", "movie"].edge_label.max() == 1`

Environment

  • pyg-lib version:
  • PyTorch version:
  • OS:
  • Python version:
  • CUDA/cuDNN version:
  • How you installed PyTorch and pyg-lib (conda, pip, source):
  • Any other relevant information:

failed to install pyg-lib on aarch64 ubuntu 20.04

๐Ÿ› Describe the bug

Run the installation:

$ pip3 install pyg-lib -f https://data.pyg.org/whl/torch-2.0.0+cu118.html Looking in links: https://data.pyg.org/whl/torch-2.0.0+cu118.html ERROR: Could not find a version that satisfies the requirement pyg-lib (from versions: none) ERROR: No matching distribution found for pyg-lib

This is on Arm64. The PyTorch 2.0.0 installed with Cuda 11.8 works fine. If it's not supported, please add it as a feature request. Thanks.

Environment

  • pyg-lib version:
  • PyTorch version:
  • OS: ubuntu 20.04 arm64
  • Python version: 3.8
  • CUDA/cuDNN version: 11.8
  • How you installed PyTorch and pyg-lib (conda, pip, source): pip3 install torch-2.0.0+nv23.05-cp38-cp38-linux_aarch64.whl
  • Any other relevant information:

cant seem to install on my m1 pro mac

๐Ÿ˜ต cant install pyg

Everytime i use the command:
pip install pyg-lib -f https://data.pyg.org/whl/torch-1.13.1+cpu.html
I get the error message
ERROR: Could not find a version that satisfies the requirement pyg-lib (from versions: none) ERROR: No matching distribution found for pyg-lib

Environment

  • pyg-lib version: n/a
  • PyTorch version: 1.13.1
  • OS: Mac OS Version 13.2.1
  • Python version: 3.10.5
  • CUDA/cuDNN version: n/a
  • How you installed PyTorch and pyg-lib (conda, pip, source): pip
  • Any other relevant information:

[RFC]ย `segment` Matrix-Multiplication

๐Ÿš€ The feature, motivation and pitch

In heterogeneous graph, we often want to apply a Linear transformation across node types using different weight matrices, i.e.:

x = ...  # a node feature matrix of shape [num_nodes, in_channels]
weight = ...  # a weight tensor of shape [num_node_types, in_channels, out_channels]
ptr = torch.tensor([0, ..., x.size(0)])  # boundaries of node types in x, len(ptr) == num_node_types + 1

out = segment_mm(x, ptr, weight, bias=None)

The computation is performed as follows (at best fully parallelized):

out[0:10] = x[0:10] @ weight[0]
out[10:15] = x[10:15] @ weight[1]
out[15:30] = x[15:30] @ weight[2]

The underlying implementation should ideally be way faster than manually iterating over each node type and applying matrix multiplications sequentially:

for i, (start, end) in enumerate(zip(ptr[:-1], ptr[1:])):
    x[start:end] @ weight[i]

and should be (hopefully) similar in performance when assuming equally-sized "segments":

x = x.view(num_node_types, num_nodes_per_node_type, in_channels)
x @ weight

cc @pyg-team/nvidia-team

LinkNeighborLoader Fails W/ MultiProcessing

๐Ÿ› Describe the bug

Mysterious error output:

E         File "/opt/conda/lib/python3.8/multiprocessing/util.py", line 452, in spawnv_passfds
E           return _posixsubprocess.fork_exec(
E       ValueError: bad value(s) in fds_to_keep

bad_fds_to_keep.txt

Environment

NVIDIA Container (in slack msg due to NDA)
test_tabformer_pyg.zip
The dataset can be downloaded here and the transactions.tgz can be unzipped for the desired dataset. It should be placed at /workspace/data/tabformer/card_transaction.v1.csv

Then the test can be run w/:
py.test -s test_tabformer_pyg.py -v

It should work out of the box since our container is on an older PyG version still using the original torch-sparse implementation of hetero neighbor sampling, but if you update to the latest master branch source build of pyg-lib and PyG then it will start using pyg-lib for hetero neighbor sampling and then you get the bad value(s) in fds_to_keep error. Not sure what's going on

PyG CI Failures

๐Ÿ› Describe the bug

The latest pytorch_geometric w/ latest pyg_lib gets a segfault when running the CI in an environment where cuda and pyg_lib are available (therefore the RGCNConv uses the cpu pyg_lib backend which seems to be broken).

/workspace/pytorch_geometric# pytest --cov --cov-report=xml
======================================================= FAILURES =======================================================
_________________________________________ test_to_hetero_and_rgcn_equal_output _________________________________________

    def test_to_hetero_and_rgcn_equal_output():
        torch.manual_seed(1234)

        # Run `RGCN`:
        x = torch.randn(10, 16)  # 6 paper nodes, 4 author nodes
        adj = (torch.rand(10, 10) > 0.5)
        adj[6:, 6:] = False
        edge_index = adj.nonzero(as_tuple=False).t().contiguous()
        row, col = edge_index

        # # 0 = paper<->paper, 1 = paper->author, 2 = author->paper
        edge_type = torch.full((edge_index.size(1), ), -1, dtype=torch.long)
        edge_type[(row < 6) & (col < 6)] = 0
        edge_type[(row < 6) & (col >= 6)] = 1
        edge_type[(row >= 6) & (col < 6)] = 2
        assert edge_type.min() == 0

        conv = RGCNConv(16, 32, num_relations=3)
        out1 = conv(x, edge_index, edge_type)

        # Run `to_hetero`:
        x_dict = {
            'paper': x[:6],
            'author': x[6:],
        }
        edge_index_dict = {
            ('paper', '_', 'paper'):
            edge_index[:, edge_type == 0],
            ('paper', '_', 'author'):
            edge_index[:, edge_type == 1] - torch.tensor([[0], [6]]),
            ('author', '_', 'paper'):
            edge_index[:, edge_type == 2] - torch.tensor([[6], [0]]),
        }

        node_types, edge_types = list(x_dict.keys()), list(edge_index_dict.keys())

        adj_t_dict = {
            key: SparseTensor.from_edge_index(edge_index).t()
            for key, edge_index in edge_index_dict.items()
        }

        model = to_hetero(RGCN(16, 32), (node_types, edge_types))

        # Set model weights:
        for i, edge_type in enumerate(edge_types):
            weight = model.conv['__'.join(edge_type)].lin.weight
            weight.data = conv.weight[i].data.t()
        for i, node_type in enumerate(node_types):
            model.lin[node_type].weight.data = conv.root.data.t()
            model.lin[node_type].bias.data = conv.bias.data

        out2 = model(x_dict, edge_index_dict)
        out2 = torch.cat([out2['paper'], out2['author']], dim=0)
>       assert torch.allclose(out1, out2, atol=1e-6)
E       assert False
E        +  where False = <built-in method allclose of type object at 0x7f45065379a0>(tensor([[-0.4873, -0.0432, -0.0032, -0.7257,  0.4246, -0.5593,  0.2248,  0.0758,\n         -0.3861, -0.4978,  0.6873,  ...5599,\n          0.2734,  0.8062,  0.3442,  1.8065, -1.0037, -0.5862,  0.3200, -1.7757]],\n       grad_fn=<AddBackward0>), tensor([[-0.4568,  0.1837,  0.0086, -0.9106,  0.4647, -1.2277,  1.0352, -0.0584,\n         -0.6260, -0.6004,  1.9123,  ...5599,\n          0.2734,  0.8062,  0.3442,  1.8065, -1.0037, -0.5862,  0.3200, -1.7757]],\n       grad_fn=<CatBackward0>), atol=1e-06)
E        +    where <built-in method allclose of type object at 0x7f45065379a0> = torch.allclose

test/nn/test_to_hetero_transformer.py:390: AssertionError
____________________________________________ test_rgcn_conv_equality[conf0] ____________________________________________

conf = (None, None)

    @pytest.mark.parametrize('conf', confs)
    def test_rgcn_conv_equality(conf):
        num_bases, num_blocks = conf

        x1 = torch.randn(4, 4)
        edge_index = torch.tensor([[0, 1, 1, 2, 2, 3], [0, 0, 1, 0, 1, 1]])
        edge_type = torch.tensor([0, 1, 1, 0, 0, 1])

        edge_index = torch.tensor([
            [0, 1, 1, 2, 2, 3, 0, 1, 1, 2, 2, 3],
            [0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1],
        ])
        edge_type = torch.tensor([0, 1, 1, 0, 0, 1, 2, 3, 3, 2, 2, 3])

        torch.manual_seed(12345)
        conv1 = RGCNConv(4, 32, 4, num_bases, num_blocks)

        torch.manual_seed(12345)
        conv2 = FastRGCNConv(4, 32, 4, num_bases, num_blocks)

        out1 = conv1(x1, edge_index, edge_type)
        out2 = conv2(x1, edge_index, edge_type)
>       assert torch.allclose(out1, out2, atol=1e-6)
E       assert False
E        +  where False = <built-in method allclose of type object at 0x7f45065379a0>(tensor([[ 0.1372, -0.0832,  0.7295,  0.1608,  0.6120, -0.7268, -0.1438,  0.8274,\n          0.0621, -0.2741, -0.0108,  ...0206,\n          0.4476, -0.5212, -0.1653,  0.6561,  0.5276,  0.7402,  0.4341, -0.1560]],\n       grad_fn=<AddBackward0>), tensor([[ 3.2177e-01,  2.9880e-01,  7.2184e-01,  3.9274e-01,  1.0374e+00,\n         -7.6988e-01, -4.9286e-01,  1.2883e+...7e-01, -1.6527e-01,  6.5613e-01,  5.2758e-01,  7.4016e-01,\n          4.3408e-01, -1.5605e-01]], grad_fn=<AddBackward0>), atol=1e-06)
E        +    where <built-in method allclose of type object at 0x7f45065379a0> = torch.allclose

test/nn/conv/test_rgcn_conv.py:36: AssertionError
____________________________________________ test_rgcn_conv[RGCNConv-conf0] ____________________________________________

cls = <class 'torch_geometric.nn.conv.rgcn_conv.RGCNConv'>, conf = (None, None)

    @pytest.mark.parametrize('cls,conf', product(classes, confs))
    def test_rgcn_conv(cls, conf):
        num_bases, num_blocks = conf

        x1 = torch.randn(4, 4)
        x2 = torch.randn(2, 16)
        idx1 = torch.arange(4)
        idx2 = torch.arange(2)
        edge_index = torch.tensor([[0, 1, 1, 2, 2, 3], [0, 0, 1, 0, 1, 1]])
        edge_type = torch.tensor([0, 1, 1, 0, 0, 1])
        row, col = edge_index
        adj = SparseTensor(row=row, col=col, value=edge_type, sparse_sizes=(4, 4))

        conv = cls(4, 32, 2, num_bases, num_blocks)
        assert conv.__repr__() == f'{cls.__name__}(4, 32, num_relations=2)'
        out1 = conv(x1, edge_index, edge_type)
        assert out1.size() == (4, 32)
>       assert conv(x1, adj.t()).tolist() == out1.tolist()
E       AssertionError: assert [[0.094849109...5622253, ...]] == [[-0.37521255...5622253, ...]]
E         At index 0 diff: [0.0948491096496582, -0.0819135308265686, 1.3105871677398682, 0.40821221470832825, 0.9653813242912292, -0.9601163268089294, 0.8856582641601562, 0.0513533353805542, -0.2117443084716797, -1.0377789735794067, -0.5760844945907593, -1.245593786239624, 0.12341594696044922, 0.41952651739120483, -0.541046142578125, -0.8374639749526978, 0.4925721287727356, -0.4119006097316742, -0.25780433416366577, 0.9387804269790649, 1.1101524829864502, -0.3150181472301483, 0.8848719000816345, 0.20270687341690063, -0.051341116428375244, -0.3655675947666168, 0.4692113399505615, ...
E
E         ...Full output truncated (2 lines hidden), use '-vv' to show

test/nn/conv/test_rgcn_conv.py:61: AssertionError
__________________________________________________ test_mask_feature ___________________________________________________

    def test_mask_feature():
        x = torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]],
                         dtype=torch.float)

        out = mask_feature(x, training=False)
        assert out[0].tolist() == x.tolist()
        assert torch.all(out[1])

        torch.manual_seed(4)
        out = mask_feature(x)
        assert out[0].tolist() == [[1.0, 2.0, 0.0, 0.0], [5.0, 6.0, 0.0, 0.0],
                                   [9.0, 10.0, 0.0, 0.0]]
        assert out[1].tolist() == [[True, True, False, False]]

        torch.manual_seed(5)
        out = mask_feature(x, mode='row')
        assert out[0].tolist() == [[1.0, 2.0, 3.0, 4.0], [0.0, 0.0, 0.0, 0.0],
                                   [9.0, 10.0, 11.0, 12.0]]
        assert out[1].tolist() == [[True], [False], [True]]

        torch.manual_seed(7)
        out = mask_feature(x, mode='all')
>       assert out[0].tolist() == [[1.0, 0.0, 0.0, 4.0], [5.0, 6.0, 7.0, 0.0],
                                   [9.0, 10.0, 0.0, 12.0]]
E       assert [[1.0, 2.0, 0..., 11.0, 12.0]] == [[1.0, 0.0, 0...0, 0.0, 12.0]]
E         At index 0 diff: [1.0, 2.0, 0.0, 0.0] != [1.0, 0.0, 0.0, 4.0]
E         Use -v to get the full diff
FAILED test/nn/test_to_hetero_transformer.py::test_to_hetero_and_rgcn_equal_output - assert False
FAILED test/nn/conv/test_rgcn_conv.py::test_rgcn_conv_equality[conf0] - assert False
FAILED test/nn/conv/test_rgcn_conv.py::test_rgcn_conv[RGCNConv-conf0] - AssertionError: assert [[0.094849109...562225...
FAILED test/utils/test_augmentation.py::test_mask_feature - assert [[1.0, 2.0, 0..., 11.0, 12.0]] == [[1.0, 0.0, 0......

Environment

latest pyg and pyg-lib main branch

[Roadmap] Self contained pyg-lib for full reliability for future development

๐Ÿš€ The feature, motivation and pitch

In an attempt to fully rely on pyg-lib for future development, the following two features planned to be supported-

  • METIS partitioning move from torch-sparse to pyg-lib
    • Move metis functionality (see here) from torch-sparse to pyg-lib
    • Integrate pyg-lib METIS functionality into PyG
  • HGT sampling move from torch-sparse to pyg-lib

Alternatives

No response

Additional context

No response

Success install but import error

๐Ÿ› Describe the bug

import torch 
import pyg_lib

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/X/anaconda3/envs/py3.10/lib/python3.10/site-packages/pyg_lib/__init__.py", line 39, in <module>
    load_library('libpyg')
  File "/home/X/anaconda3/envs/py3.10/lib/python3.10/site-packages/pyg_lib/__init__.py", line 36, in load_library
    torch.ops.load_library(spec.origin)
  File "/home/X/anaconda3/envs/py3.10/lib/python3.10/site-packages/torch/_ops.py", line 852, in load_library
    ctypes.CDLL(path)
  File "/home/X/anaconda3/envs/py3.10/lib/python3.10/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by /home/X/anaconda3/envs/py3.10/lib/python3.10/site-packages/libpyg.so)

Environment

  • pyg-lib version: 0.3.0
  • PyTorch version: 2.1.0
  • OS: Ubuntu 18.04
  • Python version: 3.10
  • CUDA/cuDNN version:CUDA 11.80, cuDNN
  • How you installed PyTorch and pyg-lib (conda, pip, source):
    Pytorch: conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
    pyg-lib: pip install pyg-lib -f https://data.pyg.org/whl/torch-2.1.0+cu118.html
  • Any other relevant information:
    The error information are:

My GLIBC version is

(Ubuntu GLIBC 2.27-3ubuntu1) 2.27

I'm quite sure that I can't upgrade my GLIBC version, how can I fix this issue? Is this a bug or a Compatibility issues? I'm not sure.

Thank you very much for help.

`bfloat16` and FP16 support for custom kernels

๐Ÿš€ The feature, motivation and pitch

As the kernels seem to be limited to the FP32 data type at the moment, it would be immensely helpful to have the implementations support mixed precision computations (FP16 and BF16) as well. This would be helpful for broader ranging applications in NLP, not just in graph neural nets.

How involved would enabling mixed-precision computations be? Any pointers to potentially start a PR?

Alternatives

No response

Additional context

No response

PyPi requirements failed on MacOS

๐Ÿ˜ต Describe the installation problem

Hello there,

I was trying to create a requirements.txt file for environment configurations on my 2023 Mac Mini, but I got the following error when I ran pip install -e .:

Looking in links: https://data.pyg.org/whl/torch-1.12.0+cpu
ERROR: Could not find a version that satisfies the requirement pyg_lib (from versions: none)
ERROR: No matching distribution found for pyg_lib

However, the same scripts work well with an Intel chip on my 2015 Macbook Pro. I attached part of the requirements file related to this issue below for your reference:

# =========== pytorch-geometric ===========
# For Linux
--find-links https://data.pyg.org/whl/torch-1.12.0+cu116.html
torch_geometric==2.3.0;    platform_system == "Linux"
pyg_lib==0.2.0;            platform_system == "Linux"
torch_cluster==1.6.0;      platform_system == "Linux"
torch_scatter==2.1.0;      platform_system == "Linux"
torch_sparse==0.6.16;      platform_system == "Linux"
torch_spline_conv==1.2.1;  platform_system == "Linux"

# For Mac
--find-links https://data.pyg.org/whl/torch-1.12.0+cpu.html
torch_geometric==2.3.0;    platform_system == "Darwin"
pyg_lib==0.2.0;            platform_system == "Darwin"
torch_cluster==1.6.0;      platform_system == "Darwin"
torch_scatter==2.1.0;      platform_system == "Darwin"
torch_sparse==0.6.16;      platform_system == "Darwin"
torch_spline_conv==1.2.1;  platform_system == "Darwin"

Environment

  • pyg-lib version: 0.2.0
  • PyTorch version: 1.12.0
  • OS: Mac OS Ventura 13.2.1
  • Python version: Python 3.9
  • CUDA/cuDNN version: cpu
  • How you installed PyTorch and pyg-lib (conda, pip, source): pip
  • Any other relevant information: see above.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.