Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GATv2Conv Bipartite Graph Assumption #9635

Open
freiberg-roman opened this issue Aug 31, 2024 · 0 comments
Open

GATv2Conv Bipartite Graph Assumption #9635

freiberg-roman opened this issue Aug 31, 2024 · 0 comments
Labels

Comments

@freiberg-roman
Copy link

freiberg-roman commented Aug 31, 2024

The following code demonstrates a problem when using the GATv2Conv layer in a bipartite graph scenario. Specifically, the issue arises when the source and destination nodes have unequal sizes, leading to a CUDA error during the forward pass.

import torch
from torch_geometric.nn import GATv2Conv

class MinimalGATModule(torch.nn.Module):
    def __init__(self, in_channels_src, in_channels_dst, out_channels, num_heads, edge_dim):
        super(MinimalGATModule, self).__init__()
        
        self.gat_conv = GATv2Conv(
            in_channels=(in_channels_src, in_channels_dst),
            out_channels=out_channels // num_heads,
            heads=num_heads,
            edge_dim=edge_dim,
            add_self_loops=True,
        )

    def forward(self, node_input_src, node_input_dst, edge_index, edge_attr):
        return self.gat_conv((node_input_src, node_input_dst), edge_index, edge_attr=edge_attr)

def main():
    # Bipartite graph with unequal source and destination nodes
    node_input_src = torch.randn((13, 240)).cuda()  # Source nodes (smaller set)
    node_input_dst = torch.randn((65, 240)).cuda()  # Destination nodes (larger set)

    edge_src = torch.tensor([0, 0, 1, 2, 2, 3, 4], device='cuda:0')
    edge_dst = torch.tensor([0, 10, 20, 30, 40, 50, 60], device='cuda:0')
    edge_index = torch.stack([edge_src, edge_dst], dim=0)

    edge_attr = torch.randn((7, 240)).cuda()  # Edge attributes

    module = MinimalGATModule(
        in_channels_src=240,
        in_channels_dst=240,
        out_channels=240,
        num_heads=4,
        edge_dim=240
    ).cuda()

    module(node_input_dst, node_input_src, torch.stack([edge_dst, edge_src], dim=0), edge_attr) # does work
    module(node_input_src, node_input_dst, edge_index, edge_attr) # does not work


if __name__ == "__main__":
    main()
usr/bin/env /path/to/python /path/to/debugpy/adapter/../../debugpy/launcher 49081 -- /path/to/second.py 
../aten/src/ATen/native/cuda/ScatterGatherKernel.cu:144: operator(): block: [0,0,0], thread: [1,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
../aten/src/ATen/native/cuda/ScatterGatherKernel.cu:144: operator(): block: [0,0,0], thread: [2,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
../aten/src/ATen/native/cuda/ScatterGatherKernel.cu:144: operator(): block: [0,0,0], thread: [3,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
../aten/src/ATen/native/cuda/ScatterGatherKernel.cu:144: operator(): block: [0,0,0], thread: [4,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
../aten/src/ATen/native/cuda/ScatterGatherKernel.cu:144: operator(): block: [0,0,0], thread: [5,0,0] Assertion `idx_dim >= 0 && idx_dim < index_size && "index out of bounds"` failed.
Traceback (most recent call last):
  File "/path/to/python3.11/runpy.py", line 198, in _run_module_as_main
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/python3.11/runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "/path/to/debugpy/__main__.py", line 39, in <module>
    cli.main()
  File "/path/to/debugpy/server/cli.py", line 430, in main
    run()
  File "/path/to/debugpy/server/cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "/path/to/debugpy/_pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/debugpy/_pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/path/to/debugpy/_pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "/path/to/second.py", line 43, in <module>
    main()
  File "/path/to/second.py", line 39, in main
    module(node_input_src, node_input_dst, edge_index, edge_attr) # does not work
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/torch/nn/modules/module.py", line 1541, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/second.py", line 17, in forward
    return self.gat_conv((node_input_src, node_input_dst), edge_index, edge_attr=edge_attr)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/torch/nn/modules/module.py", line 1541, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/torch_geometric/nn/conv/gatv2_conv.py", line 285, in forward
    edge_index, edge_attr = add_self_loops(
                            ^^^^^^^^^^^^^^^
  File "/path/to/torch_geometric/utils/loop.py", line 487, in add_self_loops
    loop_attr = compute_loop_attr(  #
                ^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/torch_geometric/utils/loop.py", line 766, in compute_loop_attr
    return scatter(edge_attr, col, 0, num_nodes, fill_value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/torch_geometric/utils/_scatter.py", line 79, in scatter
    count.scatter_add_(0, index, src.new_ones(src.size(dim)))
RuntimeError: CUDA error: device-side assert triggered
Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.

Versions

Collecting environment information...
PyTorch version: 2.3.1+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.2 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.11.9 (main, Apr 19 2024, 16:48:06) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-6.2.0-39-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA RTX A3000 Laptop GPU
Nvidia driver version: 550.40.07
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 39 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: GenuineIntel
Model name: 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz
CPU family: 6
Model: 141
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 1
Stepping: 1
CPU max MHz: 4800.0000
CPU min MHz: 800.0000
BogoMIPS: 4992.00
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l2 invpcid_single cdp_l2 ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves split_lock_detect dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq rdpid movdiri movdir64b fsrm avx512_vp2intersect md_clear ibt flush_l1d arch_capabilities
Virtualization: VT-x
L1d cache: 384 KiB (8 instances)
L1i cache: 256 KiB (8 instances)
L2 cache: 10 MiB (8 instances)
L3 cache: 24 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected

Versions of relevant libraries:
[pip3] msgpack-numpy==0.4.8
[pip3] numpy==1.26.4
[pip3] torch==2.3.1
[pip3] torch_cluster==1.6.3+pt23cu121
[pip3] torch_geometric==2.5.3
[pip3] torch_scatter==2.1.2+pt23cu121
[pip3] torch_sparse==0.6.18+pt23cu121
[pip3] torch_spline_conv==1.2.2+pt23cu121
[pip3] torchdata==0.7.1
[pip3] triton==2.3.1
[pip3] xitorch==0.5.1
[conda] msgpack-numpy 0.4.8 pypi_0 pypi
[conda] numpy 1.26.4 pypi_0 pypi
[conda] torch 2.3.1 pypi_0 pypi
[conda] torch-cluster 1.6.3+pt23cu121 pypi_0 pypi
[conda] torch-geometric 2.5.3 pypi_0 pypi
[conda] torch-scatter 2.1.2+pt23cu121 pypi_0 pypi
[conda] torch-sparse 0.6.18+pt23cu121 pypi_0 pypi
[conda] torch-spline-conv 1.2.2+pt23cu121 pypi_0 pypi
[conda] torchdata 0.7.1 pypi_0 pypi
[conda] triton 2.3.1 pypi_0 pypi
[conda] xitorch 0.5.1 pypi_0 pypi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant