Implementation of the Paper: "Parameterized Hypercomplex Graph Neural Networks for Graph Classification" by Tuan Le, Marco Bertolini, Frank Noé and Djork-Arné Clevert

Overview

Parameterized Hypercomplex Graph Neural Networks (PHC-GNNs)

PHC-GNNs (Le et al., 2021): https://arxiv.org/abs/2103.16584

PHM Linear Layer Illustration PHC-GNN Layer Computation Diagram

Overview

Here we provide the implementation of Parameterized Hypercomplex Graph Neural Networks (PHC-GNNs) in PyTorch Geometric, along with 6 minimal execution examples in the benchmarks/ directory.

This repository is organised as follows:

  • phc/hypercomplex/ contains the implementation of the PHC-GNN with all its submodules. This directory resembles the quaternion/ in most cases, with the user-defined phm-dimension n. For more details, check the subdirectory README.md
  • phc/quaternion/ contains the implementation for quaternion GNN with all its submodules. For more details, check the subdirectory README.md
  • benchmarks/ contains the python training-scripts for 3 datasets from Open Graph Benchmark (OGB) and 3 datasets from Benchmarking-GNNs. Additionally, we provide 6 bash-scripts with default arguments to run our models.

Generally speaking, the phc/hypercomplex/ subdirectory also includes the quaternion-valued GNN, with the modification to only work on torch.Tensor objects. The phc/quaternion/ subdirectory was first implemented with the fixed rules of the quaternion-algebra, such as how to perform addition, and multiplication which can be summarized in the quaternion-valued affine transformation. The phc/hypercomplex/ directory generalizes such operations to work directly on torch.Tensor objects, making it applicable to many already existing projects.
For completeness and to share our initial motivation of this project, we also provide the implementations from the phc/quaternion/ subdirectory.

Installation

Requirements

To run our examples, the main requirements are listed in the environment_gpu.yml file. The main requirements used are the following:

python=3.8.5
pytest=6.2.1
cudatoolkit=10.1
cudnn=7.6.5
numpy=1.19.2
scipy=1.5.2
pytorch=1.7.1
torch-geometric=1.6.1
ogb=1.2.4

Conda

Create a new environment:

git clone https://github.com/bayer-science-for-a-better-life/phc-gnn.git
cd phc-gnn
conda env create -f environment_gpu.yml
conda activate phc-gnn

Install Pytorch Geometric and this module with pip by executing the bash-script install_pyg.sh

chmod +x install_pyg.sh
bash install_pyg.sh

#install this library
pip install -e .

Run the implemented pytests in the subdirectories, by executing:

pytest .

Getting started

Run our example scripts in the benchmarks/ directory. Make sure to have the phc-gnn environment activated. For more details, please have a look at benchmarks/README.md.

Reference

If you make use of the implementations of quaternion or parameterized hypercomplex GNN in your research, please cite our manuscript:

@misc{le2021parameterized,
      title={Parameterized Hypercomplex Graph Neural Networks for Graph Classification}, 
      author={Tuan Le and Marco Bertolini and Frank Noé and Djork-Arné Clevert},
      year={2021},
      eprint={2103.16584},
      archivePrefix={arXiv},
      primaryClass={cs.LG},
      url={https://arxiv.org/abs/2103.16584}
}

License

GPL-3

Comments
  • implementing linear layer with  PHM-layer

    implementing linear layer with PHM-layer

    Hi thanks for sharing your codes. I am a bit confused on finding the implementation of PHM-layer and how I can turn a linear layer to the more efficient one using the method in the paper to train the models, could you kindly guide me? I found this line https://github.com/bayer-science-for-a-better-life/phc-gnn/blob/e802868bea7b9d1cad15c8227b109a8b4ca2a8e7/phc/quaternion/layers.py#L60 not sure if this is the correct one I am looking for, but this seems that linear layer has 4 matrices of size of the original linear layer, then this is even more parameters, could you kindly comment on this? thanks

    opened by dorost1234 15
  • initialization of PHM layers

    initialization of PHM layers

    Hi

    I would like to initialize phm_rule and weights in a way that the final weight matrix of PHM layers is initialized with normal(mean=0, std=0.01), could you kindly provide me with some suggestions on how this can be achieved? So which initialization I can use for phm_rules and weight variables.

    thanks

    opened by dorooddorood606 4
  • kronecker product implementation and difference with torch.kron

    kronecker product implementation and difference with torch.kron

    Hi I tried to test your kronecker product implementation and compare it with torch implementation, for the matrices of the dimension on the example you provided in https://github.com/bayer-science-for-a-better-life/phc-gnn/issues/1 :

    def kronecker_product1(a, b):
        siz1 = torch.Size(torch.tensor(a.shape[-2:]) * torch.tensor(b.shape[-2:]))
        res = a.unsqueeze(-1).unsqueeze(-3) * b.unsqueeze(-2).unsqueeze(-4)
        siz0 = res.shape[:-4]
        out = res.reshape(siz0 + siz1)
        return out
    
    def kronecker_product2(a, b):
       return torch.kron(a, b)
    

    Now lets test the two versions:

    a = torch.rand((4, 4, 4))
    b = torch.rand((4, 64, 32))
    result1 = kronecker_product1(a, b)
    print("result 1 ", result1.shape)
    result2 = kronecker_product2(a, b)
    print("result 2 ", result2.shape)
    

    The results are not the same and even dimension-wise they differ:

    result 1  torch.Size([4, 256, 128])
    result 2  torch.Size([16, 256, 128])
    

    Could you kindly assist me how I can use the torch.kron implementation and which modifications are needed?

    thanks

    opened by dorost1234 4
  • assert x_j.size(-1) == edge_attr.size(-1)

    assert x_j.size(-1) == edge_attr.size(-1)

    Hi,

    when I run this code via bash run_script_pcba_phm4.sh

    I got the following error:

    Traceback (most recent call last): File "train_pcba.py", line 634, in main() File "train_pcba.py", line 610, in main ogb_bestEpoch_test_metrics, ogb_lastEpoch_test_metric, ogb_val_metrics = do_run(i, model, args, File "train_pcba.py", line 327, in do_run train_metrics = train(epoch=epoch, model=model, device=device, transform=transform, File "train_pcba.py", line 174, in train logits = model(data) File "/root/miniconda3/envs/phc-gnn/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "/ogb/phc-gnn-master/phc/hypercomplex/undirectional/models.py", line 243, in forward x = self.compute_hidden_layer_embedding(conv=self.convs[i], norm=self.norms[i], File "/ogb/phc-gnn-master/phc/hypercomplex/undirectional/models.py", line 208, in compute_hidden_layer_embedding x = conv(x=tmp[0], edge_index=edge_index, edge_attr=edge_attr, size=size) File "/root/miniconda3/envs/phc-gnn/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "/ogb/phc-gnn-master/phc/hypercomplex/undirectional/messagepassing.py", line 519, in forward return self.transform(x, edge_index, edge_attr, size) File "/root/miniconda3/envs/phc-gnn/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "/phc-gnn-master/phc/hypercomplex/undirectional/messagepassing.py", line 60, in forward x = self.propagate(edge_index=edge_index, x=x, edge_attr=edge_attr, size=size) File "/root/miniconda3/envs/phc-gnn/lib/python3.8/site-packages/torch_geometric/nn/conv/message_passing.py", line 236, in propagate out = self.message(**msg_kwargs) File "/ogb/phc-gnn-master/phc/hypercomplex/undirectional/messagepassing.py", line 74, in message assert x_j.size(-1) == edge_attr.size(-1) AssertionError

    Then, I print the shape of both x_j and edge_attr, x_j : [28302, 512] edge_attr : [28302, 2048]

    what caused this error?

    opened by wtzhao1631 3
  • AssertionError: Argument `in_features`=50 is not divisble be `phm_dim`4

    AssertionError: Argument `in_features`=50 is not divisble be `phm_dim`4

    Hi,

    When I run the code via bash run_script_hiv_phm4.sh

    I get the following error:

    Traceback (most recent call last): File "train_hiv.py", line 636, in main() File "train_hiv.py", line 569, in main model = UPH_SC_ADD(phm_dim=phm_dim, learn_phm=learn_phm, phm_rule=phm_rule, File "/ogb/phc-gnn-master/phc/hypercomplex/undirectional/models.py", line 134, in init self.convs[i] = PHMMessagePassing(in_features=in_dim, out_features=out_dim, bias=bias, File "/ogb/phc-gnn-master/phc/hypercomplex/undirectional/messagepassing.py", line 494, in init self.transform = PHMGINEConvSoftmax(in_features, out_features, phm_dim, phm_rule, learn_phm, File "/ogb/phc-gnn-master/phc/hypercomplex/undirectional/messagepassing.py", line 277, in init self.transform = PHMMLP(in_features=in_features, out_features=out_features, phm_dim=phm_dim, File "/phc-gnn-master/phc/hypercomplex/layers.py", line 324, in init self.linear1 = PHMLinear(in_features=in_features, out_features=int(factor*out_features), File "/ogb/phc-gnn-master/phc/hypercomplex/layers.py", line 231, in init assert in_features % phm_dim == 0, f"Argument in_features={in_features} is not divisble be phm_dim{phm_dim}" AssertionError: Argument in_features=50 is not divisble be phm_dim4

    The default embedding dimension is 200. Does this cause this error?

    opened by wtzhao1631 3
  • serious reproducibility issue with PHMLinear layers

    serious reproducibility issue with PHMLinear layers

    Hi there,

    I am using PHMLinear here [1], then I set all the seeds (torch/torch cuda/numpy/random) once before making a model, and then I use this layer inside the model, I am getting each time a different results, could you guide me please how I can fix this issue with this layer?

    thank you

    [1] https://github.com/bayer-science-for-a-better-life/phc-gnn/blob/f4f04d1a0350058599380b0d86426f4d7b7eb412/phc/hypercomplex/layers.py#L113-L191

    opened by dorooddorood606 2
  • making PHM layers faster

    making PHM layers faster

    Hi I observe speed difference between the PHM layers and linear layers, while in the original paper they clarim the running time should be the same, could you kindly let me know if you might know a way I could make the running time faster? greatly appreciated.

    opened by dorooddorood606 1
  • Use cached version of PHM-weight matrix after training.

    Use cached version of PHM-weight matrix after training.

    General idea: When training is finished, the PHM-weight matrix does not have to be constructed by a sum of Kronecker products in every forward pass. One could check for self.train and then use a cached version, e.g. saved in self._cached_weight of the final weight matrix for the linear transformation. Using torch.nn.functional.linear function with inserting the self._cached_weight parameter.

    Advantage: speedup gain in inference, as trainable parameters for PHM-layer are not updated, when running inference, we could just the final weight matrix, which is constructed by the optimized contribution and sub-weight matrices {C_i}_{i=1}^{n} and {W_i}_{i=1}^{n} , respectively.

    enhancement 
    opened by tuanle618 0
Owner
Bayer AG
Science for a better life
Bayer AG
PyTorch implementation of CVPR 2020 paper (Reference-Based Sketch Image Colorization using Augmented-Self Reference and Dense Semantic Correspondence) and pre-trained model on ImageNet dataset

Reference-Based-Sketch-Image-Colorization-ImageNet This is a PyTorch implementation of CVPR 2020 paper (Reference-Based Sketch Image Colorization usin

Yuzhi ZHAO 11 Jul 28, 2022
Inference code for "StylePeople: A Generative Model of Fullbody Human Avatars" paper. This code is for the part of the paper describing video-based avatars.

NeuralTextures This is repository with inference code for paper "StylePeople: A Generative Model of Fullbody Human Avatars" (CVPR21). This code is for

Visual Understanding Lab @ Samsung AI Center Moscow 18 Oct 6, 2022
Code for paper ECCV 2020 paper: Who Left the Dogs Out? 3D Animal Reconstruction with Expectation Maximization in the Loop.

Who Left the Dogs Out? Evaluation and demo code for our ECCV 2020 paper: Who Left the Dogs Out? 3D Animal Reconstruction with Expectation Maximization

Benjamin Biggs 29 Dec 28, 2022
Home repository for the Regularized Greedy Forest (RGF) library. It includes original implementation from the paper and multithreaded one written in C++, along with various language-specific wrappers.

Regularized Greedy Forest Regularized Greedy Forest (RGF) is a tree ensemble machine learning method described in this paper. RGF can deliver better r

RGF-team 364 Dec 28, 2022
Implementation of the paper "Language-agnostic representation learning of source code from structure and context".

Code Transformer This is an official PyTorch implementation of the CodeTransformer model proposed in: D. Zügner, T. Kirschstein, M. Catasta, J. Leskov

Daniel Zügner 131 Dec 13, 2022
Implementation of TransGanFormer, an all-attention GAN that combines the finding from the recent GanFormer and TransGan paper

TransGanFormer (wip) Implementation of TransGanFormer, an all-attention GAN that combines the finding from the recent GansFormer and TransGan paper. I

Phil Wang 146 Dec 6, 2022
The official implementation of our CVPR 2021 paper - Hybrid Rotation Averaging: A Fast and Robust Rotation Averaging Approach

Graph Optimizer This repo contains the official implementation of our CVPR 2021 paper - Hybrid Rotation Averaging: A Fast and Robust Rotation Averagin

Chenyu 109 Dec 23, 2022
Implementation of paper "DeepTag: A General Framework for Fiducial Marker Design and Detection"

Implementation of paper DeepTag: A General Framework for Fiducial Marker Design and Detection. Project page: https://herohuyongtao.github.io/research/

Yongtao Hu 46 Dec 12, 2022
The official PyTorch implementation of recent paper - SAINT: Improved Neural Networks for Tabular Data via Row Attention and Contrastive Pre-Training

This repository is the official PyTorch implementation of SAINT. Find the paper on arxiv SAINT: Improved Neural Networks for Tabular Data via Row Atte

Gowthami Somepalli 284 Dec 21, 2022
Official PyTorch implementation and pretrained models of the paper Self-Supervised Classification Network

Self-Classifier: Self-Supervised Classification Network Official PyTorch implementation and pretrained models of the paper Self-Supervised Classificat

Elad Amrani 24 Dec 21, 2022
The implementation of CVPR2021 paper Temporal Query Networks for Fine-grained Video Understanding, by Chuhan Zhang, Ankush Gupta and Andrew Zisserman.

Temporal Query Networks for Fine-grained Video Understanding ?? This repository contains the implementation of CVPR2021 paper Temporal_Query_Networks

null 55 Dec 21, 2022
The project is an official implementation of our paper "3D Human Pose Estimation with Spatial and Temporal Transformers".

3D Human Pose Estimation with Spatial and Temporal Transformers This repo is the official implementation for 3D Human Pose Estimation with Spatial and

Ce Zheng 363 Dec 28, 2022
Implementation for our AAAI2021 paper (Entity Structure Within and Throughout: Modeling Mention Dependencies for Document-Level Relation Extraction).

SSAN Introduction This is the pytorch implementation of the SSAN model (see our AAAI2021 paper: Entity Structure Within and Throughout: Modeling Menti

benfeng 69 Nov 15, 2022
Implementation of experiments in the paper Clockwork Variational Autoencoders (project website) using JAX and Flax

Clockwork VAEs in JAX/Flax Implementation of experiments in the paper Clockwork Variational Autoencoders (project website) using JAX and Flax, ported

Julius Kunze 26 Oct 5, 2022
Implementation of EMNLP 2017 Paper "Natural Language Does Not Emerge 'Naturally' in Multi-Agent Dialog" using PyTorch and ParlAI

Language Emergence in Multi Agent Dialog Code for the Paper Natural Language Does Not Emerge 'Naturally' in Multi-Agent Dialog Satwik Kottur, José M.

Karan Desai 105 Nov 25, 2022
This repository contains a re-implementation of the code for the CVPR 2021 paper "Omnimatte: Associating Objects and Their Effects in Video."

Omnimatte in PyTorch This repository contains a re-implementation of the code for the CVPR 2021 paper "Omnimatte: Associating Objects and Their Effect

Erika Lu 728 Dec 28, 2022
TF2 implementation of knowledge distillation using the "function matching" hypothesis from the paper Knowledge distillation: A good teacher is patient and consistent by Beyer et al.

FunMatch-Distillation TF2 implementation of knowledge distillation using the "function matching" hypothesis from the paper Knowledge distillation: A g

Sayak Paul 67 Dec 20, 2022
Implementation of the paper All Labels Are Not Created Equal: Enhancing Semi-supervision via Label Grouping and Co-training

SemCo The official pytorch implementation of the paper All Labels Are Not Created Equal: Enhancing Semi-supervision via Label Grouping and Co-training

null 42 Nov 14, 2022
An implementation of paper `Real-time Convolutional Neural Networks for Emotion and Gender Classification` with PaddlePaddle.

简介 通过PaddlePaddle框架复现了论文 Real-time Convolutional Neural Networks for Emotion and Gender Classification 中提出的两个模型,分别是SimpleCNN和MiniXception。利用 imdb_crop

null 8 Mar 11, 2022