SkillAgentSearch skills...

GammaGL

A multi-backend graph learning library.

Install / Use

/learn @BUPT-GAMMA/GammaGL
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Gamma Graph Library(GammaGL)

GitHub release (latest by date) Documentation Status GitHub visitors GitHub all releases Total lines

Documentation |启智社区

GammaGL is a multi-backend graph learning library based on TensorLayerX, which supports TensorFlow, PyTorch, PaddlePaddle, MindSpore as the backends.

We give a development tutorial in Chinese on wiki.

Highlighted Features

Multi-backend

GammaGL supports multiple deep learning backends, such as TensorFlow, PyTorch, Paddle and MindSpore. Different from DGL, the GammaGL's examples are implemented with the same code on different backend. It allows users to run the same code on different hardwares like Nvidia-GPU and Huawei-Ascend. Besides, users could use a particular framework API based on preferences for different frameworks.

PyG-Like

Following PyTorch Geometric(PyG), GammaGL utilizes a tensor-centric API. If you are familiar with PyG, it will be friendly and maybe a TensorFlow Geometric, Paddle Geometric, or MindSpore Geometric to you.

News

<details> <summary>2024-07-29 release v0.5 </summary> </br> We release the latest version v0.5
  • 70 GNN models
  • More fused operators
  • Support GPU sample
  • Support GraphStore and FeatureStore
</details> <details> <summary>2024-01-24 release v0.4 </summary> </br> We release the latest version v0.4.
  • 60 GNN models
  • More fused operators and users can truly use these operators
  • Support the latest version of PyTorch and MindSpore
  • Support for graph database like neo4j
</details> <details> <summary>2023-07-12 release v0.3 </summary> </br> We release the latest version v0.3.
  • 50 GNN models
  • Efficient message passing operators and fused operator
  • Rebuild sampling architecture.
</details> <details> <summary> 2023-04-01 paper accepted </summary> <br/>

Our paper <i>GammaGL: A Multi-Backend Library for Graph Neural Networks</i> is accpeted at SIGIR 2023 resource paper track.

</details> <details> <summary> 2023-02-24 启智社区优秀孵化项目奖 </summary> <br/>

GammaGL荣获启智社区优秀孵化项⽬奖!详细链接:https://mp.weixin.qq.com/s/PpbwEdP0-8wG9dsvRvRDaA

</details> <details> <summary> 2023-02-21 中国电子学会科技进步一等奖 </summary> <br/>

算法库支撑了北邮牵头,蚂蚁、中移动、海致科技等参与的“大规模复杂异质图数据智能分析技术与规模化应用”项目。该项目获得了2022年电子学会科技进步一等奖。

</details> <details> <summary>2023-01-17 release v0.2 </summary> </br> We release the latest version v0.2.
  • 40 GNN models
  • 20 datasets
  • Efficient message passing operators and fused operator
  • GPU sampling and heterogeneous graphs samplers.
</details> <details> <summary>2022-06-20 release v0.1 </summary> </br> We release the latest version v0.1.
  • Framework-agnostic design
  • PyG-like
  • Graph data structures, message passing module and sampling module
  • 20+ GNN models
</details>

Get Started

Currently, GammaGL requires Python Version >= 3.9 and is only supported on Linux operating systems.

  1. Python environment (Optional): We recommend using Conda package manager

    $ conda create -n ggl python=3.9
    $ source activate ggl
    
  2. Install Backend

    # For tensorflow
    $ pip install tensorflow-gpu # GPU version
    $ pip install tensorflow # CPU version
    
    # For torch, version 2.1+cuda 11.8
    # https://pytorch.org/get-started/locally/
    $ pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cu118
    
    # For paddle, any latest stable version
    # https://www.paddlepaddle.org.cn/
    $ python -m pip install paddlepaddle-gpu
    
    # For mindspore, GammaGL supports version 2.2.0, GPU-CUDA 11.6
    # https://www.mindspore.cn/install
    $ pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.2.0/MindSpore/unified/x86_64/mindspore-2.2.0-cp39-cp39-linux_x86_64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
    

    For other backend with specific version, please check whether TLX supports.

    Install TensorLayerX

    pip install git+https://github.com/dddg617/tensorlayerx.git@nightly 
    

    Note:

    • PyTorch is necessary when installing TensorLayerX.
    • This TensorLayerX is supported by BUPT GAMMA Lab Team.
  3. Download GammaGL

    You may download the nightly version through the following commands:

    $ git clone --recursive https://github.com/BUPT-GAMMA/GammaGL.git
    $ pip install pybind11 pyparsing
    $ python setup.py install
    

    大陆用户如果遇到网络问题,推荐从启智社区安装

    Try to git clone from OpenI

    git clone --recursive https://git.openi.org.cn/GAMMALab/GammaGL.git

    Note:

    "--recursive" is necessary, if you forgot, you can run command below in GammaGL root dir:

    git submodule update --init

    You may also download the stable version refer to our document.

Quick Tour for New Users

In this quick tour, we highlight the ease of creating and training a GNN model with only a few lines of code.

Train your own GNN model

In the first glimpse of GammaGL, we implement the training of a GNN for classifying papers in a citation graph. For this, we load the Cora dataset, and create a simple 2-layer GCN model using the pre-defined GCNConv:

import tensorlayerx as tlx
from gammagl.layers.conv import GCNConv
from gammagl.datasets import Planetoid

dataset = Planetoid(root='.', name='Cora')

class GCN(tlx.nn.Module):
    def __init__(self, in_channels, hidden_channels, out_channels):
        super().__init__()
        self.conv1 = GCNConv(in_channels, hidden_channels)
        self.conv2 = GCNConv(hidden_channels, out_channels)
        self.relu = tlx.ReLU()

    def forward(self, x, edge_index):
        # x: Node feature matrix of shape [num_nodes, in_channels]
        # edge_index: Graph connectivity matrix of shape [2, num_edges]
        x = self.conv1(x, edge_index)
        x = self.relu(x)
        x = self.conv2(x, edge_index)
        return x

model = GCN(dataset.num_features, 16, dataset.num_classes)
<details> <summary> We can now optimize the model in a training loop, similar to the <a href="https://tensorlayerx.readthedocs.io/en/latest/modules/model.html#trainonestep">standard TensorLayerX training procedure</a>.</summary>
import tensorlayerx as tlx
data = dataset[0]
loss_fn = tlx.losses.softmax_cross_entropy_with_logits
optimizer = tlx.optimizers.Adam(learning_rate=1e-3)
net_with_loss = tlx.model.WithLoss(model, loss_fn)
train_one_step = tlx.model.TrainOneStep(net_with_loss, optimizer, train_weights)

for epoch in range(200):
    loss = train_one_step(data.x, data.y)
</details> <details> <summary>We can now optimize the model in a training loop, similar to the <a href="https://pytorch.org/tutorials/beginner/basics/optimization_tutorial.html#full-implementation">standard PyTorch training procedure</a>.</summary>
import torch.nn.functional as F

data = dataset[0]
optimizer = torch.optim.Adam(model.parameters(), lr=0.01)

for epoch in range(200):
    pred = model(data.x, data.edge_index)
    loss = F.cross_entropy(pred[data.train_mask], data.y[data.train_mask])

    # Backpropagation
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()
</details> <details> <summary>We can now optimize the model in a training loop, similar to the <a href="https://tensorflow.google.cn/tutorials/quickstart/advanced">standard TensorFlow training procedure</a>.</summary>
import tensorflow as tf

optimizer = tf.keras.optimizers.Adam()
loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
for epoch in range(200):
    with tf.GradientTape() as tape:
        predictions = model(images, training=True)
        loss = loss_fn(labels, predictions)
    gradients = tape.gradient(loss, model.trainable_variables)
    optimizer.apply_gradients(zip(gradients, model.trainable_variables))
</details> <details> <summary>We can now optimize the model in a training loop, similar to the <a href="https://www.paddlepaddle.org.cn/documentation/docs/zh/guides/beginner/train_eval_predict_cn.html#api">standard PaddlePaddle training procedure</a>.</summary>
import paddle

data = dataset[0]
optim = paddle.optimizer.Adam(parameters=model.parameters())
loss_fn = paddle.nn.CrossEntropyLoss()

model.train()
for epoch in range(200):
    predicts = model(data.x, data.edge_index)
    loss = loss_fn(predicts, y_data)

    # Backpropagation
    loss.backward()
    optim.step()
    optim.clear_grad()
</details> <details> <summary>We can now optimize the model in a training loop, similar to the <a href="https://www.mindspore.cn/tutorials/zh-CN/r1.7/advanced/train/train_eval.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E8%AE%AD%E7%BB%83%E5%92%8C%E8%AF%84%E4%BC%B0">standard MindSpore training procedure</a>.</summary>
# 1. Generate training dataset
train_dataset = create_dataset(num_data=160, batch_size=16)

# 2.Buil
View on GitHub
GitHub Stars251
CategoryEducation
Updated3d ago
Forks94

Languages

Python

Security Score

100/100

Audited on Apr 3, 2026

No findings