RelationalGATEncoder

class graphstorm.model.RelationalGATEncoder(g, h_dim, out_dim, num_heads, num_hidden_layers=1, edge_feat_name=None, edge_feat_mp_op='concat', dropout=0, use_self_loop=True, last_layer_act=False, num_ffn_layers_in_gnn=0, norm=None)

Bases: GraphConvEncoder, GSgnnGNNEncoderInterface

Relational graph attention encoder.

The RelationalGATEncoder employs several RelationalAttLayer as its encoding mechanism. The RelationalGATEncoder should be designated as the model’s encoder within Graphstorm.

Changed in version 0.4.1: Add two new arguments edge_feat_name and edge_feat_mp_op in v0.4.1 to support edge features in RGAT encoder.

Parameters

g: DistGraph

The distributed graph.

h_dim: int

Hidden dimension.

out_dim: int

Output dimension.

num_heads: int

Number of attention heads.

num_hidden_layers: int

Number of hidden layers. Total GNN layers is equal to num_hidden_layers + 1. Default: 1.

edge_feat_name: dict of list of str

User provided edge feature names in the format of {etype1:[feat1, feat2, …], etype2:[…], …}, or None if not provided.

edge_feat_mp_op: str

The opration method to combine source node embeddings with edge embeddings in message passing. Options include concat, add, sub, mul, and div. concat operation will concatenate the source node features with edge features; add operation will add the source node features with edge features together; sub operation will subtract the source node features by edge features; mul operation will multiply the source node features with edge features; and div operation will divide the source node features by edge features.

dropout: float

Dropout rate. Default: 0.

use_self_loop: bool

Whether to add selfloop. Default: True.

last_layer_act: callable

Activation for the last layer. Default: None.

num_ffn_layers_in_gnn: int

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

norm: str

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

Examples:

# Build model and do full-graph inference on RelationalGATEncoder
from graphstorm import get_node_feat_size
from graphstorm.model import RelationalGATEncoder
from graphstorm.model import EntityClassifier
from graphstorm.model import GSgnnNodeModel, GSNodeEncoderInputLayer
from graphstorm.dataloading import GSgnnData
from graphstorm.model import do_full_graph_inference

np_data = GSgnnData(...)

model = GSgnnNodeModel(alpha_l2norm=0)
feat_size = get_node_feat_size(np_data.g, "feat")
encoder = GSNodeEncoderInputLayer(g, feat_size, 4,
                                  dropout=0,
                                  use_node_embeddings=True)
model.set_node_input_encoder(encoder)

gnn_encoder = RelationalGATEncoder(g, 4, 4,
                                   num_heads=2,
                                   num_hidden_layers=1,
                                   dropout=0,
                                   use_self_loop=True,
                                   norm="batch")
model.set_gnn_encoder(gnn_encoder)
model.set_decoder(EntityClassifier(model.gnn_encoder.out_dims, 3, False))

h = do_full_graph_inference(model, np_data)

Warning

To use edge feature in message passing computation, please ensure the node and edge features have the same dimension. Users can use GraphStorm’s GSNodeEncoderInputLayer, and GSEdgeEncoderInputLayer to transfer node and edge feature dimensions.

is_support_edge_feat()

Overwrite GraphConvEncoder class’ method, indicating RelationalGATEncoder supports edge feature.

forward(blocks, n_h, e_hs=None)

RGAT encoder forward computation.

Changed in version 0.4.1: Change inputs into blocks, n_h and e_hs in v0.4.1 to support edge feature in RGAT encoder.

Parameters

blocks: list of DGL MFGs

Sampled subgraph in the list of DGL message flow graphs (MFGs) format. More detailed information about DGL MFG can be found in DGL Neighbor Sampling Overview.

n_h: dict of Tensor

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

e_hs: list of dict of Tensor

Input edge features for each edge type in the format of [{etype: tensor}, …], or [{}, {}. …] for zero number of edges in input blocks. The length of e_hs should be equal to the number of gnn layers. Default is None.

Returns

h: dict of Tensor

Output node embeddings for each node type in the format of {ntype: tensor}.