# 2.4 Apply Edge Weight In Message Passing¶

(中文版)

A commonly seen practice in GNN modeling is to apply edge weight on the message before message aggregation, for examples, in GAT and some GCN variants. In DGL, the way to handle this is:

• Save the weight as edge feature.

• Multiply the edge feature by src node feature in message function.

For example:

import dgl.function as fn

graph.edata['a'] = affinity
graph.update_all(fn.u_mul_e('ft', 'a', 'm'),
fn.sum('m', 'ft'))


The example above uses affinity as the edge weight. The edge weight should usually be a scalar.