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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddMetaPaths may cause memory leak issue #9302

Open
panicpan2000 opened this issue May 7, 2024 · 1 comment
Open

AddMetaPaths may cause memory leak issue #9302

panicpan2000 opened this issue May 7, 2024 · 1 comment
Labels

Comments

@panicpan2000
Copy link

panicpan2000 commented May 7, 2024

馃悰 Describe the bug

Hi! I am studying the adversarial attack on heterogeneous graph neural networks (e.g. HAN).
Normally, we call the AddMetaPaths function once to train HAN.

import torch_geometric.transforms as T
from torch_geometric.datasets import DBLP
path = osp.join(osp.dirname(osp.realpath(__file__)), './data/DBLP')
# APA, APCPA, APTPA
metapaths = [[('author', 'paper'), ('paper', 'author')],
             [('author', 'paper'), ('paper', 'conference'), ('conference', 'paper'), ('paper', 'author')],
             [('author', 'paper'), ('paper', 'term'), ('term', 'paper'), ('paper', 'author')]]
transform = T.AddMetaPaths(metapaths=metapaths, drop_orig_edge_types=True, drop_unconnected_node_types=True)
dataset = DBLP(path, transform=transform)
data = dataset[0]

The training process and model are similar to the example in examples/hetero/han_imdb.py, and it is no problem.
Then, I want to change the graph and perform targeted attacks on HAN. Hence, we need to call AddMetaPaths many times.

for id in target_ids:
    mod_data = attack(ori_data)
    transform = T.AddMetaPaths(metapaths=metapaths, drop_orig_edge_types=True, drop_unconnected_node_types=True)
    new_metadata = transform(mod_data)
    gnn(new_metadata.x_dict, new_metadata.edge_index_dict)
    eval()

The procedure will be killed. I use top and memory_profiler and find that as the number of iterations increases, new_metadata = transform(mod_data) will consume a significant amount of memory space. I tried del mod_data or del new_metadata at the end of the iteration, but the problem still exists. The following code can be used to reproduce the issue without attack

import torch_geometric.transforms as T
from torch_geometric.datasets import DBLP
path = osp.join(osp.dirname(osp.realpath(__file__)), './data/DBLP')
# APA, APCPA, APTPA
metapaths = [[('author', 'paper'), ('paper', 'author')],
             [('author', 'paper'), ('paper', 'conference'), ('conference', 'paper'), ('paper', 'author')],
             [('author', 'paper'), ('paper', 'term'), ('term', 'paper'), ('paper', 'author')]]
transform = T.AddMetaPaths(metapaths=metapaths, drop_orig_edge_types=True, drop_unconnected_node_types=True)
dataset = DBLP(path, transform=None)
oridata = dataset[0]

for idx in range(2000):
    data = transform(oridata)

It seems that mod_data will not cause the problem. If I need to call AddMetaPaths in each iteration, What is the right way to avoid memory leak? The environment is torch_geometric-2.5.2, torch-2.1.2.

Versions

Collecting environment information...
PyTorch version: 2.1.2
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.1 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.31

Python version: 3.8.19 (default, Mar 20 2024, 19:58:24) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.4.0-42-generic-x86_64-with-glibc2.17
Is CUDA available: True
CUDA runtime version: 12.0.76
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration:
GPU 0: NVIDIA GeForce RTX 3090
GPU 1: NVIDIA GeForce RTX 3090
GPU 2: NVIDIA GeForce RTX 3090
GPU 3: NVIDIA GeForce RTX 3090

Nvidia driver version: 525.125.06
cuDNN version: Probably one of the following:
/usr/local/cuda-12.0/targets/x86_64-linux/lib/libcudnn.so.8
/usr/local/cuda-12.0/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8
/usr/local/cuda-12.0/targets/x86_64-linux/lib/libcudnn_adv_train.so.8
/usr/local/cuda-12.0/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8
/usr/local/cuda-12.0/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8
/usr/local/cuda-12.0/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8
/usr/local/cuda-12.0/targets/x86_64-linux/lib/libcudnn_ops_train.so.8
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
Byte Order: Little Endian
Address sizes: 46 bits physical, 57 bits virtual
CPU(s): 48
On-line CPU(s) list: 0-47
Thread(s) per core: 2
Core(s) per socket: 12
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 106
Model name: Intel(R) Xeon(R) Silver 4310 CPU @ 2.10GHz
Stepping: 6
Frequency boost: enabled
CPU MHz: 877.503
CPU max MHz: 3300.0000
CPU min MHz: 800.0000
BogoMIPS: 4200.00
Virtualization: VT-x
L1d cache: 1.1 MiB
L1i cache: 768 KiB
L2 cache: 30 MiB
L3 cache: 36 MiB
NUMA node0 CPU(s): 0-11,24-35
NUMA node1 CPU(s): 12-23,36-47
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected
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 pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 invpcid_single ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local wbnoinvd dtherm ida arat pln pts avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq rdpid md_clear pconfig flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] numpy==1.24.3
[pip3] torch==2.1.2
[pip3] torch-cluster==1.6.3+pt21cu118
[pip3] torch_geometric==2.5.2
[pip3] torch-scatter==2.1.2+pt21cu118
[pip3] torch-sparse==0.6.18+pt21cu118
[pip3] torch-spline-conv==1.2.2+pt21cu118
[pip3] torchaudio==2.1.2
[pip3] torchvision==0.16.2
[pip3] triton==2.1.0
[conda] blas 1.0 mkl
[conda] ffmpeg 4.3 hf484d3e_0 pytorch
[conda] libjpeg-turbo 2.0.0 h9bf148f_0 pytorch
[conda] mkl 2023.1.0 h213fc3f_46344
[conda] mkl-service 2.4.0 py38h5eee18b_1
[conda] mkl_fft 1.3.8 py38h5eee18b_0
[conda] mkl_random 1.2.4 py38hdb19cb5_0
[conda] numpy 1.24.3 py38hf6e8229_1
[conda] numpy-base 1.24.3 py38h060ed82_1
[conda] pyg 2.5.2 py38_torch_2.1.0_cu118 pyg
[conda] pytorch 2.1.2 py3.8_cuda11.8_cudnn8.7.0_0 pytorch
[conda] pytorch-cuda 11.8 h7e8668a_5 pytorch
[conda] pytorch-mutex 1.0 cuda pytorch
[conda] torch-cluster 1.6.3+pt21cu118 pypi_0 pypi
[conda] torch-scatter 2.1.2+pt21cu118 pypi_0 pypi
[conda] torch-sparse 0.6.18+pt21cu118 pypi_0 pypi
[conda] torch-spline-conv 1.2.2+pt21cu118 pypi_0 pypi
[conda] torchaudio 2.1.2 py38_cu118 pytorch
[conda] torchtriton 2.1.0 py38 pytorch
[conda] torchvision 0.16.2 py38_cu118 pytorch

@rusty1s
Copy link
Member

rusty1s commented May 13, 2024

I can reproduce this, but this is not an issue on the Python level and it looks like this is coming from PyTorch CSR@CSR matmul.

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

2 participants