Scalable Graph Neural Networks for Heterogeneous Graphs

Related tags

Deep Learning NARS
Overview

Neighbor Averaging over Relation Subgraphs (NARS)

NARS is an algorithm for node classification on heterogeneous graphs, based on scalable neighbor averaging techniques that have been previously used in e.g. SIGN to heterogeneous scenarios by generating neighbor-averaged features on sampled relation induced subgraphs.

For more details, please check out our paper:

Scalable Graph Neural Networks for Heterogeneous Graphs

Setup

Dependencies

  • torch==1.5.1+cu101
  • dgl-cu101==0.4.3.post2
  • ogb==1.2.1
  • dglke==0.1.0

Docker

We have prepared a dockerfile for building a container with clean environment and all required dependencies. Please checkout instructions in docker.

Data Preparation

Download and pre-process OAG dataset (optional)

If you plan to evaluate on OAG dataset, you need to follow instructions in oag_dataset to download and pre-process dataset.

Generate input for featureless node types

In academic graph datasets (ACM, MAG, OAG) in which only paper nodes are associated with input features. NARS featurizes other node types with TransE relational graph embedding pre-trained on the graph structure.

Please follow instructions in graph_embed to generate embeddings for each dataset.

Sample relation subsets

NARS samples Relation Subsets (see our paper for details). Please follow the instructions in sample_relation_subsets to generate these subsets.

Or you may skip this step and use the example subsets that have added to this repository.

Run NARS Experiments

NARS are evaluated on three academic graph datasets to predict publishing venues and fields of papers.

ACM

python3 train.py --dataset acm --use-emb TransE_acm --R 2 \
    --use-relation-subsets sample_relation_subsets/examples/acm \
    --num-hidden 64 --lr 0.003 --dropout 0.7 --eval-every 1 \
    --num-epochs 100 --input-dropout

OGBN-MAG

python3 train.py --dataset mag --use-emb TransE_mag --R 5 \
    --use-relation-subset sample_relation_subsets/examples/mag \
    --eval-batch-size 50000 --num-hidden 512 --lr 0.001 --batch-s 50000 \
    --dropout 0.5 --num-epochs 1000

OAG (venue prediction)

python3 train.py --dataset oag_venue --use-emb TransE_oag_venue --R 3 \
    --use-relation-subsets sample_relation_subsets/examples/oag_venue \
    --eval-batch-size 25000 --num-hidden 256 --lr 0.001 --batch-size 1000 \
    --data-dir oag_dataset --dropout 0.5 --num-epochs 200

OAG (L1-field prediction)

python3 train.py --dataset oag_L1 --use-emb TransE_oag_L1 --R 3 \
    --use-relation-subsets sample_relation_subsets/examples/oag_L1 \
    --eval-batch-size 25000 --num-hidden 256 --lr 0.001 --batch-size 1000 \
    --data-dir oag_dataset --dropout 0.5 --num-epochs 200

Results

Here is a summary of model performance using example relation subsets:

For ACM and OGBN-MAG dataset, the task is to predict paper publishing venue.

Dataset # Params Test Accuracy
ACM 0.40M 0.9305±0.0043
OGBN-MAG 4.13M 0.5240±0.0016

For OAG dataset, there are two different node predictions tasks: predicting venue (single-label) and L1-field (multi-label). And we follow Heterogeneous Graph Transformer to evaluate using NDCG and MRR metrics.

Task # Params NDCG MRR
Venue 2.24M 0.5214±0.0010 0.3434±0.0012
L1-field 1.41M 0.86420.0022 0.8542±0.0019

Run with limited GPU memory

The above commands were tested on Tesla V100 (32 GB) and Tesla T4 (15GB). If your GPU memory isn't enough for handling large graphs, try the following:

  • add --cpu-process to the command to move preprocessing logic to CPU
  • reduce evaluation batch size with --eval-batch-size. The evaluation result won't be affected since model is fixed.
  • reduce training batch with --batch-size

Run NARS with Reduced CPU Memory Footprint

As mentioned in our paper, using a lot of relation subsets may consume too much CPU memory. To reduce CPU memory footprint, we implemented an optimization in train_partial.py which trains part of our feature aggregation weights at a time.

Using OGBN-MAG dataset as an example, the following command randomly picks 3 subsets from all 8 sampled relation subsets and trains their aggregation weights every 10 epochs.

python3 train_partial.py --dataset mag --use-emb TransE_mag --R 5 \
    --use-relation-subsets sample_relation_subsets/examples/mag \
    --eval-batch-size 50000 --num-hidden 512 --lr 0.001 --batch-size 50000 \
    --dropout 0.5 --num-epochs 1000 --sample-size 3 --resample-every 10

Citation

Please cite our paper with:

@article{yu2020scalable,
    title={Scalable Graph Neural Networks for Heterogeneous Graphs},
    author={Yu, Lingfan and Shen, Jiajun and Li, Jinyang and Lerer, Adam},
    journal={arXiv preprint arXiv:2011.09679},
    year={2020}
}

License

NARS is CC-by-NC licensed, as found in the LICENSE file.

Comments
  • Can not reproduce the same result as you present in OGB-MAG dataset

    Can not reproduce the same result as you present in OGB-MAG dataset

    I used the same setting as you to train OGB-MAG and used the example relation subsets you gave, but the best accuracy I got us only 0.2788. I wonder if there is anything wrong.

    [INFO] Epoch 840, Times(s): 20.3544, Accuracy: Train 0.3018, Val 0.2757, Test 0.2839
    [INFO] Epoch 850, Times(s): 20.1501, Accuracy: Train 0.3021, Val 0.2749, Test 0.2838
    [INFO] Epoch 860, Times(s): 20.8749, Accuracy: Train 0.3023, Val 0.2756, Test 0.2851
    [INFO] Epoch 870, Times(s): 21.1500, Accuracy: Train 0.3022, Val 0.2754, Test 0.2834
    [INFO] Epoch 880, Times(s): 21.2005, Accuracy: Train 0.3023, Val 0.2768, Test 0.2853
    [INFO] Epoch 890, Times(s): 21.1369, Accuracy: Train 0.3022, Val 0.2758, Test 0.2842
    [INFO] Epoch 900, Times(s): 20.8746, Accuracy: Train 0.3029, Val 0.2763, Test 0.2852
    [INFO] Epoch 910, Times(s): 20.9197, Accuracy: Train 0.3028, Val 0.2765, Test 0.2849
    [INFO] Epoch 920, Times(s): 20.6873, Accuracy: Train 0.3026, Val 0.2761, Test 0.2839
    [INFO] Epoch 930, Times(s): 20.6163, Accuracy: Train 0.3028, Val 0.2771, Test 0.2845
    [INFO] Epoch 940, Times(s): 20.7486, Accuracy: Train 0.3033, Val 0.2773, Test 0.2851
    [INFO] Epoch 950, Times(s): 20.4859, Accuracy: Train 0.3031, Val 0.2774, Test 0.2853
    [INFO] Epoch 960, Times(s): 21.1654, Accuracy: Train 0.3028, Val 0.2788, Test 0.2868
    [INFO] Epoch 970, Times(s): 20.6524, Accuracy: Train 0.3030, Val 0.2759, Test 0.2850
    [INFO] Epoch 980, Times(s): 20.6713, Accuracy: Train 0.3028, Val 0.2756, Test 0.2843
    [INFO] Epoch 990, Times(s): 20.8252, Accuracy: Train 0.3028, Val 0.2783, Test 0.2865
    [INFO] Epoch 1000, Times(s): 20.6521, Accuracy: Train 0.3025, Val 0.2760, Test 0.2839
    [INFO] Best Epoch 960,Test 0.2788
    Namespace(R=5, batch_size=50000, cpu_preprocess=False, data_dir=None, dataset='mag', dropout=0.5, eval_batch_size=50000, eval_every=10, ff_layer=2, gpu=0, input_dropout=False, lr=0.001, num_epochs=100    0, num_hidden=512, seed=None, use_emb='TransE_mag', use_relation_subsets='sample_relation_subsets/examples/mag', weight_decay=0)
    
    
    opened by eddiegaoo 9
  • Out of gpu memory

    Out of gpu memory

    hi, I have a question about gpu memory. When I use MAG dataset, I found the number of hop of neighbors R is seated as 6. But I use Teslav100(32g), It is out of gpu memory. I calculate the size of one neighbor feature, and the size is 6 gb, according to your article, just use a tesla v100, I do not think this can be achieved. I am sorry if I ignore anything that can deal with the issue

    opened by BlackHorseQ 5
  • DGLKE cannot generate TransE embeddings for DGLHeteroGraph

    DGLKE cannot generate TransE embeddings for DGLHeteroGraph

    OS: Ubuntu 20.04 Python: 3.8 DGL version: 0.6.1 (pip install dgl-cu110) DGLKE version: 0.1.2 (pip install dglke)

    This issue seems to be related to recent changes in DGL.

    bash train_graph_emb.sh mag

    • dataset=mag
    • '[' mag == mag ']'
    • embed_size=128
    • DGLBACKEND=pytorch
    • dglke_train --model TransE_l2 --batch_size 1000 --neg_sample_size 200 --hidden_dim 128 --gamma 10 --lr 0.1 --max_step 400000 --log_interval 10000 -adv --gpu 0 --regularization_coef 1e-9 --data_path ./ --data_files train_triplets_mag --format raw_udd_hrt --dataset mag Using backend: pytorch Reading train triples.... Finished. Read 21111007 train triples. |Train|: 21111007 /home/jonny/.conda/envs/jonny_conda3/lib/python3.8/site-packages/dgl/base.py:45: DGLWarning: Recommend creating graphs by dgl.graph(data) instead of dgl.DGLGraph(data). return warnings.warn(message, category=category, stacklevel=1) /home/jonny/.conda/envs/jonny_conda3/lib/python3.8/site-packages/dgl/base.py:45: DGLWarning: Keyword arguments ['readonly', 'multigraph', 'sort_csr'] are deprecated in v0.5, and can be safely removed in all cases. return warnings.warn(message, category=category, stacklevel=1) Traceback (most recent call last): File "/home/jonny/.conda/envs/jonny_conda3/bin/dglke_train", line 8, in sys.exit(main()) File "/home/jonny/.conda/envs/jonny_conda3/lib/python3.8/site-packages/dglke/train.py", line 144, in main train_sampler_head = train_data.create_sampler(args.batch_size, File "/home/jonny/.conda/envs/jonny_conda3/lib/python3.8/site-packages/dglke/dataloader/sampler.py", line 379, in create_sampler return EdgeSampler(self.g, File "/home/jonny/.conda/envs/jonny_conda3/lib/python3.8/site-packages/dgl/contrib/sampling/sampler.py", line 683, in init self._sampler = _CAPI_CreateUniformEdgeSampler( File "dgl/_ffi/_cython/./function.pxi", line 287, in dgl._ffi._cy3.core.FunctionBase.call File "dgl/_ffi/_cython/./function.pxi", line 232, in dgl._ffi._cy3.core.FuncCall File "dgl/_ffi/_cython/./base.pxi", line 155, in dgl._ffi._cy3.core.CALL dgl._ffi.base.DGLError: [11:47:04] /opt/dgl/include/dgl/packed_func_ext.h:117: Check failed: ObjectTypeChecker::Check(sptr.get()): Expected type graph.Graph but get graph.HeteroGraph Stack trace: [bt] (0) /home/jonny/.conda/envs/jonny_conda3/lib/python3.8/site-packages/dgl/libdgl.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x4f) [0x7f7ea63d416f] [bt] (1) /home/jonny/.conda/envs/jonny_conda3/lib/python3.8/site-packages/dgl/libdgl.so(dgl::GraphRef dgl::runtime::DGLArgValue::AsObjectRefdgl::GraphRef() const+0x264) [0x7f7ea6b1f7f4] [bt] (2) /home/jonny/.conda/envs/jonny_conda3/lib/python3.8/site-packages/dgl/libdgl.so(+0xcf5020) [0x7f7ea6b7e020] [bt] (3) /home/jonny/.conda/envs/jonny_conda3/lib/python3.8/site-packages/dgl/libdgl.so(+0xcf5bf4) [0x7f7ea6b7ebf4] [bt] (4) /home/jonny/.conda/envs/jonny_conda3/lib/python3.8/site-packages/dgl/libdgl.so(DGLFuncCall+0x48) [0x7f7ea6ad8378] [bt] (5) /home/jonny/.conda/envs/jonny_conda3/lib/python3.8/site-packages/dgl/_ffi/_cy3/core.cpython-38-x86_64-linux-gnu.so(+0x15d3e) [0x7f7e7c675d3e] [bt] (6) /home/jonny/.conda/envs/jonny_conda3/lib/python3.8/site-packages/dgl/_ffi/_cy3/core.cpython-38-x86_64-linux-gnu.so(+0x1626b) [0x7f7e7c67626b] [bt] (7) /home/jonny/.conda/envs/jonny_conda3/bin/python(_PyObject_MakeTpCall+0x22f) [0x556c7e81385f] [bt] (8) /home/jonny/.conda/envs/jonny_conda3/bin/python(_PyEval_EvalFrameDefault+0x475) [0x556c7e896e35]
    opened by JonnyTran 4
  • The effect of RandomProject from 128 to 256 in OGB-MAG dataset

    The effect of RandomProject from 128 to 256 in OGB-MAG dataset

    Dear Authors,

    It is amazing to see such works that eliminate the necessity of GNN-like structure to achieve the state-of-the-art.

    I have a question on the featureless node embedding. On OGB-MAG dataset, you used TransE to embed the featureless into 256d vector while the original feature dimension is 128d. And then you use random projection to project 128d to 256d. I don't quite understand such an operation. Why not set embedding dimension as 128 in the first place?

    question 
    opened by Adam1679 3
  • The problem when implementing the model on MAG Dataset

    The problem when implementing the model on MAG Dataset

    When I try to run the model on the OGB-MAG dataset, I found that the cuda-related bug can not be fixed.

    Using backend: pytorch
    Namespace(R=5, batch_size=1, cpu_preprocess=False, data_dir=None, dataset='mag', dropout=0.5, eval_batch_size=50000, eval_every=10, ff_layer=2, gpu=0, input_dropout=False, lr=0.001, num_epochs=1000, num_hidden=512, seed=None, use_emb='TransE_mag', use_relation_subsets='sample_relation_subsets/examples/mag', weight_decay=0)
    Traceback (most recent call last):
      File "train.py", line 139, in <module>
        main(args)
      File "train.py", line 45, in main
        data = load_data(device, args)
      File "/data/sgaoar/NARS/data.py", line 107, in load_data
        return load_mag(device, args)
      File "/data/sgaoar/NARS/data.py", line 170, in load_mag
        g.nodes["paper"].data["feat"] = torch.matmul(paper_feat, rand_weight.to(device))
    RuntimeError: CUDA error: CUBLAS_STATUS_EXECUTION_FAILED when calling `cublasSgemm( handle, opa, opb, m, n, k, &alpha, a, lda, b, ldb, &beta, c, ldc)`
    

    My setup is exactly the same as yours. And I checked the shape of "paper_feat" and "rand_weight.to(device)", and they are like [3xxxxx, 128] and [128,256]. So there is no mismatch in the dimension. And I check the GPU memory also when the data is being loaded, the GPU did not run out of memory. I don't know what results in this. Look forward to your reply!

    opened by eddiegaoo 2
  • question about sampled relation subsets

    question about sampled relation subsets

    Hi, I have a question about sampled relation subsets. When using the mag dataset, affiliated_with, has_topic is one of the sampled relation subsets. Is the relation affiliated_with redundant to build the subgraph? Because author-affiliated_with-institution and institution-affiliated_with_r-author has no effect on the k-hop feature of paper, right? It may be that I have misunderstood something. Looking forward to your reply.

    opened by maqy1995 2
  • The problem of new_subgrah implementation

    The problem of new_subgrah implementation

    Hello dear author, I read your Nars paper and it helped a lot. I have a question in the code implementation part in data.py Line 48 new_edges[(dtype, etype + "_r", stype)] = (dst, src) it seems to do a bidirectional graph operation on the mag dataset. We all know that the mag dataset is a directed graph, what is the purpose of doing this?、 Best wishes!

    opened by GooLiang 1
  • dgl loading mag dataset device error

    dgl loading mag dataset device error

    dear author, when I cloned the code and running with dglcu113,pytorch+cu113,python3.9 for ogbn-mag dataset,I got some problem about loading embbeding.pt generated by transE, do you have any solution to running without change my conda env?

    Traceback (most recent call last):
      File "/home/yikh/mycode/NARS/train.py", line 139, in <module>
        main(args)
      File "/home/yikh/mycode/NARS/train.py", line 45, in main
        data = load_data(device, args)
      File "/home/yikh/mycode/NARS/data.py", line 107, in load_data
        return load_mag(device, args)
      File "/home/yikh/mycode/NARS/data.py", line 160, in load_mag
        g.nodes["author"].data["feat"] = author_emb.to(device)
      File "/home/yikh/.conda/envs/ykh/lib/python3.9/site-packages/dgl/view.py", line 90, in __setitem__
        self._graph._set_n_repr(self._ntid, self._nodes, {key: val})
      File "/home/yikh/.conda/envs/ykh/lib/python3.9/site-packages/dgl/heterograph.py", line 4122, in _set_n_repr
        raise DGLError('Cannot assign node feature "{}" on device {} to a graph on'
    dgl._ffi.base.DGLError: Cannot assign node feature "feat" on device cuda:0 to a graph on device cpu. Call DGLGraph.to() to copy the graph to the same device.
    

    if I add codes g = g.to(device) before loading it got another error with device, and I tried to fix the bug, but I made much more error😭,Thanks a lot.

    Traceback (most recent call last):
      File "/home/yikh/mycode/NARS/train.py", line 139, in <module>
        main(args)
      File "/home/yikh/mycode/NARS/train.py", line 52, in main
        feats = preprocess_features(g, rel_subsets, args, device)
      File "/home/yikh/mycode/NARS/train.py", line 26, in preprocess_features
        feats = gen_rel_subset_feature(g, subset, args, device)
      File "/home/yikh/mycode/NARS/data.py", line 45, in gen_rel_subset_feature
        src = src.numpy()
    TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
    
    opened by khan-yin 1
  • The code of RGCN

    The code of RGCN

    Dear authors, I have noticed that the RGCN has an accuracy of 50.0% on MAG in your paper, which is higher than RGCN's result reported in OGB leaderboard. Could you share your codes for the RGCN model you used in the paper? Thanks very much!

    opened by wzfhaha 1
Owner
Facebook Research
Facebook Research
Some tentative models that incorporate label propagation to graph neural networks for graph representation learning in nodes, links or graphs.

Some tentative models that incorporate label propagation to graph neural networks for graph representation learning in nodes, links or graphs.

zshicode 1 Nov 18, 2021
Revisiting, benchmarking, and refining Heterogeneous Graph Neural Networks.

Heterogeneous Graph Benchmark Revisiting, benchmarking, and refining Heterogeneous Graph Neural Networks. Roadmap We organize our repo by task, and on

THUDM 176 Dec 17, 2022
Code for our EMNLP 2021 paper “Heterogeneous Graph Neural Networks for Keyphrase Generation”

GATER This repository contains the code for our EMNLP 2021 paper “Heterogeneous Graph Neural Networks for Keyphrase Generation”. Our implementation is

Jiacheng Ye 12 Nov 24, 2022
The source code of the paper "SHGNN: Structure-Aware Heterogeneous Graph Neural Network"

SHGNN: Structure-Aware Heterogeneous Graph Neural Network The source code and dataset of the paper: SHGNN: Structure-Aware Heterogeneous Graph Neural

Wentao Xu 7 Nov 13, 2022
Implementation of "GNNAutoScale: Scalable and Expressive Graph Neural Networks via Historical Embeddings" in PyTorch

PyGAS: Auto-Scaling GNNs in PyG PyGAS is the practical realization of our G NN A uto S cale (GAS) framework, which scales arbitrary message-passing GN

Matthias Fey 139 Dec 25, 2022
DeepHyper: Scalable Asynchronous Neural Architecture and Hyperparameter Search for Deep Neural Networks

What is DeepHyper? DeepHyper is a software package that uses learning, optimization, and parallel computing to automate the design and development of

DeepHyper Team 214 Jan 8, 2023
Code for KDD'20 "An Efficient Neighborhood-based Interaction Model for Recommendation on Heterogeneous Graph"

Heterogeneous INteract and aggreGatE (GraphHINGE) This is a pytorch implementation of GraphHINGE model. This is the experiment code in the following w

Jinjiarui 69 Nov 24, 2022
A heterogeneous entity-augmented academic language model based on Open Academic Graph (OAG)

Library | Paper | Slack We released two versions of OAG-BERT in CogDL package. OAG-BERT is a heterogeneous entity-augmented academic language model wh

THUDM 58 Dec 17, 2022
Source code for CIKM 2021 paper for Relation-aware Heterogeneous Graph for User Profiling

RHGN Source code for CIKM 2021 paper for Relation-aware Heterogeneous Graph for User Profiling Dependencies torch==1.6.0 torchvision==0.7.0 dgl==0.7.1

Big Data and Multi-modal Computing Group, CRIPAC 6 Nov 29, 2022
Implementation of Heterogeneous Graph Attention Network

HetGAN Implementation of Heterogeneous Graph Attention Network This is the code repository of paper "Prediction of Metro Ridership During the COVID-19

null 5 Dec 28, 2021
A static analysis library for computing graph representations of Python programs suitable for use with graph neural networks.

python_graphs This package is for computing graph representations of Python programs for machine learning applications. It includes the following modu

Google Research 258 Dec 29, 2022
The source code of the paper "Understanding Graph Neural Networks from Graph Signal Denoising Perspectives"

GSDN-F and GSDN-EF This repository provides a reference implementation of GSDN-F and GSDN-EF as described in the paper "Understanding Graph Neural Net

Guoji Fu 18 Nov 14, 2022
On Size-Oriented Long-Tailed Graph Classification of Graph Neural Networks

On Size-Oriented Long-Tailed Graph Classification of Graph Neural Networks We provide the code (in PyTorch) and datasets for our paper "On Size-Orient

Zemin Liu 4 Jun 18, 2022
Convolutional Neural Networks on Graphs with Fast Localized Spectral Filtering

Graph ConvNets in PyTorch October 15, 2017 Xavier Bresson http://www.ntu.edu.sg/home/xbresson https://github.com/xbresson https://twitter.com/xbresson

Xavier Bresson 287 Jan 4, 2023
Complex-Valued Neural Networks (CVNN)Complex-Valued Neural Networks (CVNN)

Complex-Valued Neural Networks (CVNN) Done by @NEGU93 - J. Agustin Barrachina Using this library, the only difference with a Tensorflow code is that y

youceF 1 Nov 12, 2021
ZSL-KG is a general-purpose zero-shot learning framework with a novel transformer graph convolutional network (TrGCN) to learn class representation from common sense knowledge graphs.

ZSL-KG is a general-purpose zero-shot learning framework with a novel transformer graph convolutional network (TrGCN) to learn class representa

Bats Research 94 Nov 21, 2022
This is the repository for the AAAI 21 paper [Contrastive and Generative Graph Convolutional Networks for Graph-based Semi-Supervised Learning].

CG3 This is the repository for the AAAI 21 paper [Contrastive and Generative Graph Convolutional Networks for Graph-based Semi-Supervised Learning]. R

null 12 Oct 28, 2022
MACE is a deep learning inference framework optimized for mobile heterogeneous computing platforms.

Documentation | FAQ | Release Notes | Roadmap | MACE Model Zoo | Demo | Join Us | 中文 Mobile AI Compute Engine (or MACE for short) is a deep learning i

Xiaomi 4.7k Dec 29, 2022