RelGraphConvLayer

class graphstorm.model.RelGraphConvLayer(in_feat, out_feat, rel_names, num_bases, *, weight=True, bias=True, activation=None, self_loop=True, dropout=0.0, num_ffn_layers_in_gnn=0, ffn_activation=<function relu>, norm=None)

Bases: Module

Relational graph convolution layer from Modeling Relational Data with Graph Convolutional Networks.

A generic module for computing convolution on heterogeneous graphs.

The relational graph convolution layer applies GraphConv on the heterogeneous graphs, which reads the features from source nodes and writes the updated ones to destination nodes. If multiple relations have the same destination node types, their results are aggregated by the specified method. If the heterogeneous graph has no edge, the corresponding module will not be called.

Mathematically for the GraphConv it is defined as follows:

\[h_i^{(l+1)} = \sigma(b^{(l)} + \sum_{j\in\mathcal{N}(i)}\frac{1}{c_{ji}}h_j^{(l)}W^{(l)})\]

where \(\mathcal{N}(i)\) is the set of neighbors of node \(i\), \(c_{ji}\) is the product of the square root of node degrees (i.e., \(c_{ji} = \sqrt{|\mathcal{N}(j)|}\sqrt{|\mathcal{N}(i)|}\)), and \(\sigma\) is an activation function.

Note:

  • The implementation of RelGraphConvLayer selects right as the norm, which divides the aggregated messages by each node’s in-degrees, equivalent to averaging the received messages.

Examples:

# suppose graph and input_feature are ready
from graphstorm.model import RelGraphConvLayer

layer = RelGraphConvLayer(
        in_feat=h_dim, out_feat=h_dim, rel_names=g.canonical_etypes,
        num_bases=num_bases, self_loop,
        dropout, num_ffn_layers_in_gnn,
        ffn_activation, norm)
h = layer(g, input_feature)

Parameters

in_feat: int

Input feature size.

out_feat: int

Output feature size.

rel_names: list of tuple

Relation type list in the format of [(‘src_ntyp1’, ‘etype1’, ‘dst_ntype1`), …].

num_bases: int

Number of bases. If is None, use number of relation types. Default: None.

weight: bool

Whether to apply a linear layer after message passing. Default: True.

bias: bool

Whether to add bias. Default: True.

activation: callable

Activation function. Default: None.

self_loop: bool

Whether to include self loop message. Default: True.

dropout: float

Dropout rate. Default: 0.

num_ffn_layers_in_gnn: int

Number of fnn layers between gnn layers. Default: 0.

ffn_actication: torch.nn.functional

Activation for ffn. Default: relu.

norm: str

Normalization methods. Options:batch, layer, and None. Default: None, meaning no normalization.

forward(g, inputs)

RGCN layer forward computation.

Parameters

g: DGLHeteroGraph

Input DGL heterogenous graph.

inputs: dict of Tensor

Node features for each node type in the format of {ntype: tensor}.

Returns

dict of Tensor: New node embeddings for each node type in the format of {ntype: tensor}.