HOW ATTENTIVE ARE GRAPH ATTENTION NETWORKS?

Shaked Brody
Technion
shakedbr@cs.technion.ac.il

Uri Alon
Language Technologies Institute
Carnegie Mellon University
ualon@cs.cmu.edu

Eran Yahav
Technion
yahave@cs.technion.ac.il

ABSTRACT

Graph Attention Networks (GATs) are one of the most popular GNN architectures and are considered as the state-of-the-art architecture for representation learning with graphs. In GAT, every node attends to its neighbors given its own representation as the query. However, in this paper we show that GAT computes a very limited kind of attention: the ranking of the attention scores is unconditioned on the query node. We formally define this restricted kind of attention as static attention and distinguish it from a strictly more expressive dynamic attention. Because GATs use a static attention mechanism, there are simple graph problems that GAT cannot express: in a controlled problem, we show that static attention hinders GAT from even fitting the training data. To remove this limitation, we introduce a simple fix by modifying the order of operations and propose GATv2: a dynamic graph attention variant that is strictly more expressive than GAT. We perform an extensive evaluation and show that GATv2 outperforms GAT across 12 OGB and other benchmarks while we match their parametric costs. Our code is available at GitHub.1 GATv2 is available as part of the PyTorch Geometric library,2 the Deep Graph Library,3 and the TensorFlow GNN library.4

1 INTRODUCTION

Graph neural networks (GNNs; Gori et al., 2005; Scarselli et al., 2008)GNNs have seen increasing popularity over the past few years (Duvenaud et al., 2015; Atwood and Towsley, 2016; Bronstein et al., 2017; Monti et al., 2017). GNNs provide a general and efficient framework to learn from graph-structured data. Thus, GNNs are easily applicable in domains where the data can be represented as a set of nodes and the prediction depends on the relationships (edges) between the nodes. Such domains include molecules, social networks, product recommendation, computer programs and more.

In a GNN, each node iteratively updates its state by interacting with its neighbors. GNN variants (Wu et al., 2019; Xu et al., 2019; Li et al., 2016) mostly differ in how each node aggregates and combines the representations of its neighbors with its own. Veličković et al. (2018)Veličković and colleagues pioneered the use of attention-based neighborhood aggregation, in one of the most common GNN variants — Graph Attention Network (GAT). In GAT, every node updates its representation by attending to its neighbors using its own representation as the query. This generalizes the standard averaging or max-pooling of neighbors (Kipf and Welling, 2017; Hamilton et al., 2017), by allowing every node to compute a weighted average of its neighbors, and (softly) select its most relevant neighbors. The work of

Heatmaps and line plots comparing attention mechanisms in standard GAT and GATv2.Figure 1: In a complete bipartite graph of “query nodes” q zero through q nine and “key nodes” k zero through k nine: standard GAT (Figure 1a) computes static attention – the ranking of attention coefficients is global for all nodes in the graph, and is unconditioned on the query node. For example, all queries ( to q zero to q nine) attend mostly to the 8th key (k eight). In contrast, GATv2 (Figure 1b) can actually compute dynamic attention, where every query has a different ranking of attention coefficients of the keys.

Veličković et al. (2018)Veličković and colleagues also generalizes the Transformer’s (Vaswani et al., 2017) self-attention mechanism, from sequences to graphs (Joshi, 2020).

Nowadays, GAT is one of the most popular GNN architectures (Bronstein et al., 2021) and is considered as the state-of-the-art neural architecture for learning with graphs (Wang et al., 2019a). Nevertheless, in this paper we show that GAT does not actually compute the expressive, well known, type of attention (Bahdanau et al., 2014), which we call dynamic attention. Instead, we show that GAT computes only a restricted “static” form of attention: for any query node, the attention function is monotonic with respect to the neighbor (key) scores. That is, the ranking (the arg sort) of attention coefficients is shared across all nodes in the graph, and is unconditioned on the query node. This fact severely hurts the expressiveness of GAT, and is demonstrated in Figure 1a.

Supposedly, the conceptual idea of attention as the form of interaction between GNN nodes is orthogonal to the specific choice of attention function. However, Veličković et al.’s (2018)Veličković and colleagues’ original design of GAT has spread to a variety of domains (Wang et al., 2019a; Yang et al., 2020; Wang et al., 2019c; Huang and Carley, 2019; Ma et al., 2020; Kosaraju et al., 2019; Nathani et al., 2019; Wu et al., 2020; Zhang et al., 2020) and has become the default implementation of “graph attention network” in all popular GNN libraries such as PyTorch Geometric (Fey and Lenssen, 2019), DGL (Wang et al., 2019b), and others (Dwivedi et al., 2020; Gordić, 2020; Brockschmidt, 2020).

To overcome the limitation we identified in GAT, we introduce a simple fix to its attention function by only modifying the order of internal operations. The result is GATv2 – a graph attention variant

that has a universal approximator attention function, and is thus strictly more expressive than GAT. The effect of fixing the attention function in GATv2 is demonstrated in Figure 1b.

In summary, our main contribution is identifying that one of the most popular GNN types, the graph attention network, does not compute dynamic attention, the kind of attention that it seems to compute. We introduce formal definitions for analyzing the expressive power of graph attention mechanisms (Definitions 3.1 and 3.2), and derive our claims theoretically (Theorem 1) from the equations of Veličković et al. (2018)Veličković and colleagues. Empirically, we use a synthetic problem to show that standard GAT cannot express problems that require dynamic attention (Section 4.1). We introduce a simple fix by switching the order of internal operations in GAT, and propose GATv2, which does compute dynamic attention (Theorem 2). We further conduct a thorough empirical comparison of GAT and GATv2 and find that GATv2 outperforms GAT across 12 benchmarks of node-, link-, and graph-prediction. For example, GATv2 outperforms extensively tuned GNNs by over 1.4% in the difficult “UnseenProj Test” set of the VarMisuse task (Allamanis et al., 2018)Allamanis and colleagues, without any hyperparameter tuning; and GATv2 improves over an extensively-tuned GAT by 11.5% in 13 prediction objectives in QM9. In node-prediction benchmarks from OGB (Hu et al., 2020)Hu and colleagues, not only that GATv2 outperforms GAT with respect to accuracy — we find that dynamic attention provided a much better robustness to noise.

2 PRELIMINARIES

A directed graph G equals V, E contains nodes V and edges E, where the pair j, i in E denotes an edge from a node j to a node i. We assume that every node i in V has an initial representation h i zero of dimension d zero. An undirected graph can be represented with bidirectional edges.

2.1 GRAPH NEURAL NETWORKS

A graph neural network (GNN) layer updates every node representation by aggregating its neighbors’ representations. A layer’s input is a set of node representations h i of dimension d for all i in V and the set of edges E. A layer outputs a new set of node representations h prime i of dimension d prime, where the same parametric function is applied to every node given its neighbors N i, the set of neighbors j:

h prime i equals f theta of h i and the aggregation of its neighbors’ representations h j

The design of f and aggregate is what mostly distinguishes one type of GNN from the other. For example, a common variant of GraphSAGE (Hamilton et al., 2017)Hamilton and colleagues performs an element-wise mean as , followed by concatenation with h i, a linear layer and a ReLU as f.

2.2 GRAPH ATTENTION NETWORKS

GraphSAGE and many other popular GNN architectures (Xu et al., 2019; Duvenaud et al., 2015) weigh all neighbors j in N i with equal importance (e.g., mean or max-pooling as ). To address this limitation, GAT (Veličković et al., 2018) instantiates Equation (1) by computing a learned weighted average of the representations of N i. A scoring function e computes a score for every edge j, i, which indicates the importance of the features of the neighbor to the node :

the score e of h i and h j is the leaky ReLU of a transpose times the concatenation of W h i and W h j

where a, W are learned, and denotes vector concatenation. These attention scores are normalized across all neighbors j in N i using softmax, and the attention function is defined as:

the attention coefficient alpha i j is the softmax of the scores over the neighbors

Then, GAT computes a weighted average of the transformed features of the neighbor nodes (followed by a nonlinearity sigma) as the new representation of , using the normalized attention coefficients:

h prime i equals sigma of the sum over neighbors of alpha i j times W h j

From now on, we will refer to Equations (2) to (4) as the definition of GAT.

3 The Expressive Power of Graph Attention Mechanisms

In this section, we explain why attention is limited when it is not dynamic (Section 3.1). We then show that GAT is severely constrained, because it can only compute static attention (Section 3.2). Next, we show how GAT can be fixed (Section 3.3), by simply modifying the order of operations.

We refer to a neural architecture (e.g., the scoring or the attention function of GAT) as a family of functions, parameterized by the learned parameters. An element in the family is a concrete function with specific trained weights. In the following, we use to denote the set the set of integers from 1 to n.

3.1 The Importance of Dynamic Weighting

Attention is a mechanism for computing a distribution over a set of input key vectors, given an additional query vector. If the attention function always weighs one key at least as much as any other key, unconditioned on the query, we say that this attention function is static:

Definition 3.1 (Static attention). A (possibly infinite) family of scoring functions computes static scoring for a given set of key vectors and query vectors , if for every there exists a “highest scoring” key such that for every query and key it holds that . We say that a family of attention functions computes static attention given and , if its scoring function computes static scoring, possibly followed by monotonic normalization such as softmax.

Static attention is very limited because every function has a key that is always selected, regardless of the query. Such functions cannot model situations where different keys have different relevance to different queries. Static attention is demonstrated in Figure 1a.

The general and powerful form of attention is dynamic attention:

Definition 3.2 (Dynamic attention). A (possibly infinite) family of scoring functions computes dynamic scoring for a given set of key vectors and query vectors , if for any mapping there exists such that for any query and any key : . We say that a family of attention functions computes dynamic attention for and , if its scoring function computes dynamic scoring, possibly followed by monotonic normalization such as softmax.

That is, dynamic attention can select every key using the query , by making the maximal in . Note that dynamic and static attention are exclusive properties, but they are not complementary. Further, every dynamic attention family has strict subsets of static attention families with respect to the same and . Dynamic attention is demonstrated in Figure 1b.

Attending by decaying Another way to think about attention is the ability to “focus” on the most relevant inputs, given a query. Focusing is only possible by decaying other inputs, i.e., giving these decayed inputs lower scores than others. If one key is always given an equal or greater attention score than other keys (as in static attention), no query can ignore this key or decay this key’s score.

3.2 The Limited Expressivity of GAT

Although the scoring function can be defined in various ways, the original definition of Veličković et al. (2018)Veličković and colleagues (Equation (2)) has become the de facto practice: it has spread to a variety of domains and is now the standard implementation of “graph attention network” in all popular GNN libraries (Fey and Lenssen, 2019; Wang et al., 2019b; Dwivedi et al., 2020; Gordić, 2020; Brockschmidt, 2020).

The motivation of GAT is to compute a representation for every node as a weighted average of its neighbors. Statedly, GAT is inspired by the attention mechanism of Bahdanau et al. (2014)Bahdanau and colleagues and the self-attention mechanism of the Transformer (Vaswani et al., 2017). Nonetheless:

Theorem 1. A GAT layer computes only static attention, for any set of node representations . In particular, for , a GAT layer does not compute dynamic attention.

Proof. Let be a graph modeled by a GAT layer with some and values (Equations (2) and (3)), and having node representations . The learned parameter can be written as a

concatenation a, formed by concatenating a one and a two in two-d-prime space such that a one and a two are in d-prime space, and Equation (2) can be re-written as:

e of h i and h j equals Leaky ReLU of, a one transpose W h i plus a two transpose W h j

Since V is finite, there exists a node j max in V such that a two transpose W h sub j max is maximal among all nodes ( is the required by Definition 3.1). Due to the monotonicity of LeakyReLU and softmax, for every query node , the node also leads to the maximal value of its attention distribution . Thus, from Definition 3.1 directly, alpha computes only static attention. This also implies that alpha does not compute dynamic attention, because in GAT, Definition 3.2 holds only for constant mappings phi that map all inputs to the same output.

The consequence of Theorem 1 is that for any set of nodes V and a trained GAT layer, the attention function alpha defines a constant ranking (argsort) of the nodes, unconditioned on the query nodes . That is, we can denote s j equals a two transpose W h j and get that for any choice of h i, alpha is monotonic with respect to the per-node scores . This global ranking induces the local ranking of every neighborhood N i. The only effect of h i is in the “sharpness” of the produced attention distribution. This is demonstrated in Figure 1a (bottom), where different curves denote different queries .

Generalization to multi-head attention Veličković et al. (2018)Veličković and colleagues found it beneficial to employ H separate attention heads and concatenate their outputs, similarly to Transformers. In this case, Theorem 1 holds for each head separately: every head h in H has a (possibly different) node that maximizes , and the output is the concatenation of H static attention heads.

3.3 Building Dynamic Graph Attention Networks

To create a dynamic graph attention network, we modify the order of internal operations in GAT and introduce GATv2 – a simple fix of GAT that has a strictly more expressive attention mechanism.

GATv2 The main problem in the standard GAT scoring function (Equation (2)) is that the learned layers and are applied consecutively, and thus can be collapsed into a single linear layer. To fix this limitation, we simply apply the layer after the nonlinearity (LeakyReLU), and the layer after the concatenation,5 effectively applying an MLP to compute the score for each query-key pair:

For GAT, e equals Leaky ReLU of, a transpose times the concatenation of W h i and W h j. For GAT v 2, e equals a transpose times the Leaky ReLU of, W times the concatenation of h i and h j.

The simple modification makes a significant difference in the expressiveness of the attention function:

Theorem 2.

A GATv2 layer computes dynamic attention for any set of node representations .K, defined as the set of node representations h one through h n

We prove Theorem 2 in Appendix A. The main idea is that we can define an appropriate function that GATv2 will be a universal approximator (Cybenko, 1989; Hornik, 1991) of. In contrast, GAT (Equation (52)) cannot approximate any such desired function (Theorem 1).

Complexity GATv2 has the same time-complexity as GAT’s declared complexity: order of the number of nodes times d d prime, plus the number of edges times d prime. However, by merging its linear layers, GAT can be computed faster than stated by Veličković et al. (2018)Veličković and colleagues. For a detailed time- and parametric-complexity analysis, see Appendix G.

4 Evaluation

First, we demonstrate the weakness of GAT using a simple synthetic problem that GAT cannot even fit (cannot even achieve high training accuracy), but is easily solvable by GATv2 (Section 4.1). Second, we show that GATv2 is much more robust to edge noise, because its dynamic attention mechanisms allow it to decay noisy (false) edges, while GAT’s performance severely decreases as noise increases (Section 4.2). Finally, we compare GAT and GATv2 across 12 benchmarks overall. (Sections 4.3 to 4.6 and appendix D.3). We find that GAT is inferior to GATv2 across all examined benchmarks.

Bipartite graph illustrating the Dictionary Lookup problem with keys and queries.Figure 2: The DictionaryLookup problem of size k equals four: every node in the bottom row has an alphabetic attribute and a numeric value ; every node in the upper row has only an attribute; the goal is to predict the value for each node in the upper row, using its attribute.
Line graph comparing GAT and GATv2 accuracy as k increases.Figure 3: The DictionaryLookup problem: GATv2 easily achieves 100% train and test accuracies even for k equals one hundred and using only a single head.

Setup When previous results exist, we take hyperparameters that were tuned for GAT and use them in GATv2, without any additional tuning. Self-supervision (Kim and Oh, 2021; Rong et al., 2020a), graph regularization (Zhao and Akoglu, 2020; Rong et al., 2020b), and other tricks (Wang, 2021; Huang et al., 2021)Prior techniques like self-supervision and graph regularization are orthogonal to the contribution of the GNN layer itself, and may further improve all GNNs. In all experiments of GATv2, we constrain the learned matrix by setting W as the concatenation of W prime with itself, to rule out the increased number of parameters over GAT as the source of empirical difference (see Appendix G.2). Training details, statistics, and code are provided in Appendix B.

Our main goal is to compare dynamic and static graph attention mechanisms. However, for reference, we also include non-attentive baselines such as GCN (Kipf and Welling, 2017), GIN (Xu et al., 2019) and GraphSAGE (Hamilton et al., 2017)G C N, G I N, and Graph SAGE. These non-attentive GNNs can be thought of as a special case of attention, where every node gives all its neighbors the same attention score. Additional comparison to a Transformer-style scaled dot-product attention (“DPGAT”), which is strictly weaker than our proposed GATv2 (see a proof in Appendix E.1), is shown in Appendix E.

4.1 Synthetic Benchmark: DictionaryLookup

The DictionaryLookup problem is a contrived problem that we designed to test the ability of a GNN architecture to perform dynamic attention. Here, we demonstrate that GAT cannot learn this simple problem. Figure 2 shows a complete bipartite graph of two k nodes. Each “key node” in the bottom row has an attribute and a value . Each “query node” in the upper row has only an attribute . The goal is to predict the value of every query node (upper row), according to its attribute. Each graph in the dataset has a different mapping from attributes to values. We created a separate dataset for each k from one, two, three, and so on, for which we trained a different model, and measured per-node accuracy.

Although this is a contrived problem, it is relevant to any subgraph with keys that share more than one query, and each query needs to attend to the keys differently. Such subgraphs are very common in a variety of real-world domains. This problem tests the layer itself because it can be solved using a single GNN layer, without suffering from multi-layer side-effects such as over-smoothing (Li et al., 2018), over-squashing (Alon and Yahav, 2021), or vanishing gradients (Li et al., 2019)over-smoothing, over-squashing, or vanishing gradients. Our code will be made publicly available, to serve as a testbed for future graph attention mechanisms.

Results Figure 3 shows the following surprising results: GAT with a single head G A T one h failed to fit the training set for any value of k, no matter for how many iterations it was trained, and after trying various training methods. Thus, it expectedly fails to generalize (resulting in low test accuracy). Using 8 heads, G A T eight h successfully fits the training set, but generalizes poorly to the test set. In contrast, GATv2 easily achieves 100% training and 100% test accuracies for any value of k, and even for k equals one hundred (not shown) and using a single head, thanks to its ability to perform dynamic attention. These results clearly show the limitations of GAT, which are easily solved by GATv2. An additional comparison to GIN, which could not fit this dataset, is provided in Figure 6 in Appendix D.1.

Visualization Figure 1a (top) shows a heatmap of GAT’s attention scores in this DICTIONARY-LOOKUP problem. As shown, all query nodes to q zero to q nine attend mostly to the eighth key (k eight), and have the same ranking of attention coefficients (Figure 1a (bottom)). In contrast, Figure 1b shows how GATv2 can select a different key node for every query node, because it computes dynamic attention.

The role of multi-head attention Veličković et al. (2018)Veličković and colleagues found the role of multi-head attention to be stabilizing the learning process. Nevertheless, Figure 3 shows that increasing the number of heads strictly increases training accuracy, and thus, the expressivity. Thus, GAT depends on having multiple attention heads. In contrast, even a single GATv2 head generalizes better than a multi-head GAT.

4.2 ROBUSTNESS TO NOISE

We examine the robustness of dynamic and static attention to noise. In particular, we focus on structural noise: given an input graph G equals V comma E and a noise ratio p between zero and one, we randomly sample the number of edges times p non-existing edges E prime from the set of possible edges not in E. We then train the GNN on the noisy graph G prime equals V comma E union E prime.

Two line charts showing accuracy vs noise ratio for ogbn-arxiv and ogbn-mag datasets. GATv2 maintains higher accuracy than GAT as noise increases.Figure 4: Test accuracy compared to the noise ratio: GATv2 is more robust to structural noise compared to GAT. Each point is an average of 10 runs, error bars show standard deviation.

Results Figure 9 shows the accuracy on two node-prediction datasets from the Open Graph Benchmark (OGB; Hu et al., 2020)O G B as a function of the noise ratio p. As p increases, all models show a natural decline in test accuracy in both datasets. Yet, thanks to their ability to compute dynamic attention, GATv2 shows a milder degradation in accuracy compared to GAT, which shows a steeper descent. We hypothesize that the ability to perform dynamic attention helps the models distinguishing between given data edges (E) and noise edges (E prime); in contrast, GAT cannot distinguish between edges, because it scores the source and target nodes separately. These results clearly demonstrate the robustness of dynamic attention over static attention in noisy settings, which are common in reality.

4.3 PROGRAMS: VARMISUSE

Setup VARMISUSE (Allamanis et al., 2018) is an inductive node-pointing problem that depends on 11 types of syntactic and semantic interactions between elements in computer programs.

We used the framework of Brockschmidt (2020)Brockschmidt, who performed an extensive hyperparameter tuning by searching over 30 configurations for every GNN type. We took their best GAT hyperparameters and used them to train GATv2, without further tuning.

Results As shown in Figure 5, GATv2 is more accurate than GAT and other GNNs in the SeenProj test sets. Furthermore, GATv2 achieves an even higher improvement in the UnseenProj test set. Overall, these results demonstrate the power of GATv2 in modeling complex relational problems, especially since it outperforms extensively tuned models, without any further tuning by us.

Published as a conference paper at ICLR 2022

Figure 5: Accuracy (5 runs stdev)plus or minus standard deviation over five runs on VARMISUSE. GATv2 is more accurate than all GNNs in both test sets, using GAT’s hyperparameters. previously reported by Brockschmidt (2020)Brock-shmit, twenty twenty.

ModelSeenProjUnseenProj
No-AttentionGCN
GIN
AttentionGAT
GATv2

4.4 Node-Prediction

We further compare GATv2, GAT, and other GNNs on four node-prediction datasets from OGB.

Table 1: Average accuracy (Table 1a) and ROC-AUC (Table 1b) in node-prediction datasets (10 runs std)ten runs plus or minus standard deviation. In all datasets, GATv2 outperforms GAT. – previously reported by Hu et al. (2020)Hu and colleagues, twenty twenty.

(a)
ModelAttn. Headsogbn-arxivogbn-productsogbn-mag
GCN0
GraphSAGE0
GAT1
8
GATv2 (this work)1
8
(b)
ogbn-proteins

Results Results are shown in Table 1. In all settings and all datasets, GATv2 is more accurate than GAT and the non-attentive GNNs. Interestingly, in the datasets of Table 1a, even a single head of GATv2 outperforms GAT with 8 heads. In Table 1b (ogbn-proteins), increasing the number of heads results in a major improvement for GAT (from 70.77 to 78.63), while GATv2 already gets most of the benefit using a single attention head. These results demonstrate the superiority of GATv2 over GAT in node prediction (and even with a single head), thanks to GATv2’s dynamic attention.

4.5 Graph-Prediction: QM9

Setup In the QM9 dataset (Ramakrishnan et al., 2014; Gilmer et al., 2017)Ramakrishnan and colleagues, twenty fourteen; and Gilmer and colleagues, twenty seventeen, each graph is a molecule and the goal is to regress each graph to 13 real-valued quantum chemical properties. We used the implementation of Brockschmidt (2020)Brock-shmit, twenty twenty who performed an extensive hyperparameter search over 500 configurations; we took their best-found configuration of GAT to implement GATv2.

Table 2: Average error rates (lower is better), 5 runs for each property, on the QM9 dataset. The best result among GAT and GATv2 is marked in bold; the globally best result among all GNNs is marked in bold and underline. was previously tuned and reported by Brockschmidt (2020)Brock-shmit.

Predicted PropertyRel. to
Model12345678910111213GAT
GCN3.214.221.451.622.4216.3817.407.828.249.057.003.931.02-1.5%
GIN2.644.671.421.502.2715.6312.935.8818.715.625.383.531.05-2.3%
GAT2.684.651.481.532.3152.3914.877.616.867.646.544.111.48+0%
GATv22.654.281.411.472.2916.3714.036.076.286.605.973.571.59-11.5%

Results Table 2 shows the main results: GATv2 achieves a lower (better) average error than GAT, by 11.5% relatively. GAT achieves the overall highest average error. In some properties, the non-attentive

GNNs, GCN and GIN, perform best. We hypothesize that attention is not needed in modeling these properties. Generally, GATv2 achieves the lowest overall average relative error (rightmost column).

We compare GATv2, GAT, and other GNNs in link-prediction datasets from OGBthe Open Graph Benchmark.

Table 3: Average Hits@50 (Table 3a) and mean reciprocal rank (MRR) (Table 3b) in link-prediction benchmarks from OGB (10 runsplus or minusstd). The best result among GAT and GATv2 is marked in bold; the best result among all GNNs is marked in . dagger was reported by Hu et al. (2020)Hu and colleagues.

(a)ogbl-collab(b) ogbl-citation2
ModelAttn. Headsw/o val edgesw/ val edges
No-AttentionGCN
GraphSAGE
GATGAT
GAT
GATv2GATv2
GATv242.8549.7080.14

Results Table 3 shows that in all datasets, GATv2 achieves a higher MRR than GAT, which achieves the lowest MRR. However, the non-attentive GraphSAGE performs better than all attentive GNNs. We hypothesize that attention might not be needed in these datasets. Another possibility is that dynamic attention is especially useful in graphs that have high node degrees: in ogbn-products and ogbn-proteins (Table 1) the average node degrees are 50.5 and 597, respectively (see Table 5 in Appendix C). ogbl-collab and ogbl-citation2 (Table 3), however, have much lower average node degrees – of 8.2 and 20.7. We hypothesize that a dynamic attention mechanism is especially useful to select the most relevant neighbors when the total number of neighbors is high. We leave the study of the effect of the datasets’s average node degrees on the optimal GNN architecture for future work.

4.7 Discussion

In all examined benchmarks, we found that GATv2 is more accurate than GAT. Further, we found that GATv2 is significantly more robust to noise than GAT. In the synthetic DICTIONARYLOOKUP benchmark (Section 4.1), GAT fails to express the data, and thus achieves even poor training accuracy.

In few of the benchmarks (Table 3 and some of the properties in Table 2) – a non-attentive model such as GCN or GIN achieved a higher accuracy than all GNNs that do use attention.

Which graph attention mechanism should I use? It is usually impossible to determine in advance which architecture would perform best. A theoretically weaker model may perform better in practice, because a stronger model might overfit the training data if the task is “too simple” and does not require such expressiveness. Intuitively, we believe that the more complex the interactions between nodes are – the more benefit a GNN can take from theoretically stronger graph attention mechanisms such as GATv2. The main question is whether the problem has a global ranking of “influential” nodes (GAT is sufficient), or do different nodes have different rankings of neighbors (use GATv2).

Veličković, the author of GAT, has confirmed on Twitter6 that GAT was designed to work in the “easy-to-overfit” datasets of the time (2017), such as Cora, Citeseer and Pubmed (Sen et al., 2008)described by Sen and colleagues, where the data might had an underlying static ranking of “globally important” nodes. Veličković agreed that newer and more challenging benchmarks may demand stronger attention mechanisms such as GATv2. In this paper, we revisit the traditional assumptions and show that many modern graph benchmarks and datasets contain more complex interactions, and thus require dynamic attention.

Attention in GNNs Modeling pairwise interactions between elements in graph-structured data goes back to interaction networks (Battaglia et al., 2016; Hoshen, 2017)Battaglia and colleagues, and Hoshen, and relational networks (Santoro et al., 2017)Santoro and colleagues. The GAT formulation of Veličković et al. (2018)Veličković and colleagues rose as the most popular framework for attentional GNNs, thanks to its simplicity, generality, and applicability beyond reinforcement learning (Denil et al., 2017; Duan et al., 2017)Denil and colleagues, and Duan and colleagues. Nevertheless, in this work, we show that the popular and widespread definition of GAT is severely constrained to static attention only.

Other graph attention mechanisms Many works employed GNNs with attention mechanisms other than the standard GAT’s (Zhang et al., 2018; Thekumparampil et al., 2018; Gao and Ji, 2019; Lukovnikov and Fischer, 2021; Shi et al., 2020; Dwivedi and Bresson, 2020; Busbridge et al., 2019; Rong et al., 2020a; Veličković et al., 2020), and Lee et al. (2018)Lee and colleagues conducted an extensive survey of attention types in GNNs. However, none of these works identified the monotonicity of GAT’s attention mechanism, the theoretical differences between attention types, nor empirically compared their performance. Kim and Oh (2021)Kim and Oh compared two graph attention mechanisms empirically, but in a specific self-supervised scenario, without observing the theoretical difference in their expressiveness.

The static attention of GAT Qiu et al. (2018)Qiu and colleagues recognized the order-preserving property of GAT, but did not identify the severe theoretical constraint that this property implies: the inability to perform dynamic attention (Theorem 1). Furthermore, they presented GAT’s monotonicity as a desired trait (!) To the best of our knowledge, our work is the first work to recognize the inability of GAT to perform dynamic attention and its practical harmful consequences.

6 CONCLUSION

In this paper, we identify that the popular and widespread Graph Attention Network does not compute dynamic attention. Instead, the attention mechanism in the standard definition and implementations of GAT is only static: for any query, its neighbor-scoring is monotonic with respect to per-node scores. As a result, GAT cannot even express simple alignment problems. To address this limitation, we introduce a simple fix and propose GATv2: by modifying the order of operations in GAT, GATv2 achieves a universal approximator attention function and is thus strictly more powerful than GAT.

We demonstrate the empirical advantage of GATv2 over GAT in a synthetic problem that requires dynamic selection of nodes, and in 11 benchmarks from OGB and other public datasets. Our experiments show that GATv2 outperforms GAT in all benchmarks while having the same parametric cost.

We encourage the community to use GATv2 instead of GAT whenever comparing new GNN architectures to the common strong baselines. In complex tasks and domains and in challenging datasets, a model that uses GAT as an internal component can replace it with GATv2 to benefit from a strictly more powerful model. To this end, we make our code publicly available at GitHub, and GATv2 is available as part of the PyTorch Geometric library, the Deep Graph Library, and TensorFlow GNN. An annotated implementation is available at nn.labml.ai.

ACKNOWLEDGMENTS

We thank Gail Weiss for the helpful discussions, thorough feedback, and inspirational paper (Weiss et al., 2018)by Weiss and colleagues. We also thank Petar Veličković for the useful discussion about the complexity and implementation of GAT.

References

[references omitted]

[references omitted]

[references omitted]

[references omitted]

[references omitted]

A PROOF FOR THEOREM 2

For brevity, we repeat our definition of dynamic attention (Definition 3.2):

Definition 3.2 (Dynamic attention). A (possibly infinite) family of scoring functions computes dynamic scoring for a given set of key vectors and query vectors , if for any mapping there exists such that for any query and any key : . We say that a family of attention functions computes dynamic attention for and , if its scoring function computes dynamic scoring, possibly followed by monotonic normalization such as softmax.

Theorem 2. A GATv2 layer computes dynamic attention for any set of node representations .

Proof. Let be a graph modeled by a GATv2 layer, having node representations , and let be any node mapping . We define as follows:

Next, we define a continuous function that equals to in only specific inputs:

For all other inputs , realizes to any values that maintain the continuity of (this is possible because we fixed the values of for only a finite set of points).7

Thus, for every node and :

If we concatenate the two input vectors, and define the scoring function of GATv2 (Equation (7)) as a function of the concatenated vector , from the universal approximation theorem (Hornik et al., 1989; Cybenko, 1989; Funahashi, 1989; Hornik, 1991)according to the universal approximation theorem, can approximate for any compact subset of .

Thus, for any sufficiently small epsilon (any ) there exist parameters and such that for every node and every :

and due to the increasing monotonicity of softmax:

The choice of nonlinearity In general, these results hold if GATv2 had used any common non-polynomial activation function (such as ReLU, sigmoid, or the hyperbolic tangent function). The LeakyReLU activation function of GATv2 does not change its universal approximation ability (Leshno et al., 1993; Pinkus, 1999; Park et al., 2021), and it was chosen only for consistency with the original definition of GAT.

B TRAINING DETAILS

In this section we elaborate on the training details of all of our experiments. All models use residual connections as in Veličković et al. (2018)Velitch-ko-vitch and colleagues. All used code and data are publicly available under the MIT license.

We used the provided splits of OGB (Hu et al., 2020)O G B and the Adam optimizer. We tuned the following hyperparameters: number of layers , hidden size , learning rate number of layers, either two, three, or six; hidden size, either 64, 128, or 256; learning rate, ranging from five ten-thousandths to one hundredth and sampling method – full batch, GraphSAINT (Zeng et al., 2019)Graph SAINT and NeighborSampling (Hamilton et al., 2017)Neighbor Sampling. We tuned hyperparameters according to validation score and early stopping. The final hyperparameters are detailed in Table 4.

Dataset# layersHidden sizeLearning rateSampling method
ogbn-arxiv32560.01GraphSAINT
ogbn-products31280.001NeighborSampling
ogbn-mag22560.01NeighborSampling
ogbn-proteins6640.01NeighborSampling
ogbl-collab3640.001Full Batch
ogbl-citation232560.0005NeighborSampling

Table 4: Training details of node- and link-prediction datasets.

B.2 ROBUSTNESS TO NOISE

In these experiments, we used the same best-found hyperparameters in node-prediction, with 8 attention heads in ogbn-arxiv and 1 head in ogbn-mag. Each point is an average of 10 runs.

B.3 SYNTHETIC BENCHMARK: DICTIONARYLOOKUP

In all experiments, we used a learning rate decay of 0.5, a hidden size of d equals 128, a batch size of 1024, and the Adam optimizer.

We created a separate dataset for every graph size (k), and we split each such dataset to train and test with a ratio of 80:20. Since this is a contrived problem, we did not use a validation set, and the reported test results can be thought of as validation results. Every model was trained on a fixed value of k. Every key node (bottom row in Figure 2) was encoded as a sum of learned attribute embedding and a value embedding, followed by ReLU.

We experimented with layer normalization, batch normalization, dropout, various activation functions and various learning rates. None of these changed the general trend, so the experiments in Figure 3 were conducted without any normalization, without dropout and a learning rate of 0.001.

B.4 PROGRAMS: VARMISUSE

We used the code, splits, and the same best-found configurations as Brockschmidt (2020)Brock-shmit, who performed an extensive hyperparameter tuning by searching over 30 configurations for each GNN type. We trained each model five times.

We took the best-found hyperparameters of Brockschmidt (2020)Brock-shmit for GAT and used them to train GATv2, without any further tuning.

B.5 GRAPH-PREDICTION: QM9

We used the code and splits of Brockschmidt (2020)Brock-shmit who performed an extensive hyperparameter search over 500 configurations. We took the best-found hyperparameters of Brockschmidt (2020)Brock-shmit.

for GAT and used them to train GATv2. The only minor change from GAT is placing a residual connection after every layer, rather than after every other layer, which is within the experimented hyperparameter search that was reported by Brockschmidt (2020)Brock-shmit, twenty twenty.

B.6 COMPUTE AND RESOURCES

Our experiments consumed approximately 100 days of GPU in total. We used cloud GPUs of type V100, and we used RTX 3080 and 3090 in local GPU machines.

C DATA STATISTICS

Statistics of the OGB datasets we used for node- and link-prediction are shown in Table 5.

Dataset# nodes# edgesAvg. node degreeDiameter
ogbn-arxiv169,3431,166,24313.723
ogbn-mag1,939,74321,111,00721.76
ogbn-products2,449,02961,859,14050.527
ogbn-proteins132,53439,561,252597.09
ogbl-collab235,8681,285,4658.222
ogbl-citation22,927,96330,561,18720.721

Table 5: Statistics of the OGB datasets (Hu et al., 2020)by Hu and colleagues, twenty twenty.

C.2 QM9

Statistics of the QM9 dataset, as used in Brockschmidt (2020)Brock-shmit, twenty twenty are shown in Table 6.

TrainingValidationTest
# examples110,46210,00010,000
# nodes - average18.0318.0618.09
# edges - average18.6518.6718.72
Diameter - average6.356.356.35

Table 6: Statistics of the QM9 chemical dataset (Ramakrishnan et al., 2014)by Ram-ah-krish-nan and colleagues, twenty fourteen as used by Brockschmidt (2020)Brock-shmit, twenty twenty.

C.3 VARMISUSE

Statistics of the VARMISUSE dataset, as used in Allamanis et al. (2018)All-ah-man-iss and colleagues, twenty eighteen and Brockschmidt (2020)Brock-shmit, twenty twenty, are shown in Table 7.

TrainingValidationUnseenProject TestSeenProject Test
# graphs2543604265411703659974
# nodes - average2377174219593986
# edges - average72987851588212925
Diameter - average7.887.887.787.82

Table 7: Statistics of the VARMISUSE dataset (Allamanis et al., 2018)by All-ah-man-iss and colleagues, twenty eighteen as used by Brockschmidt (2020)Brock-shmit, twenty twenty.

A line graph showing accuracy versus the number of different keys k for GATv2 and GIN models on the DictionaryLookup task. GATv2 maintains 100 percent accuracy, while GIN accuracy drops significantly as k increases.Figure 6: Train and test accuracy across graph sizes in the DICTIONARYLOOKUP problem. GATv2 easily achieves 100% train and test accuracy even for k equals 100 and using only a single head. GIN (Xu et al., 2019)Xu and colleagues, although considered as more expressive than other GNNs, cannot perfectly fit the training data (with a model size of d equals 128) starting from k equals 20.

D ADDITIONAL RESULTS

D.1 DICTIONARYLOOKUP

Figure 6 shows additional comparison between GATv2 and GIN (Xu et al., 2019)Xu and colleagues in the DICTIONARYLOOKUP problem. GATv2 easily achieves 100% train and test accuracy even for k equals 100 and using only a single head. GIN, although considered as more expressive than other GNNs, cannot perfectly fit the training data (with a model size of d equals 128) starting from k equals 20.

D.2 QM9

Standard deviation for the QM9 results of Section 4.5 are presented in Table 8.

Model1234567
GCN4.22
GIN2.642.2715.6312.93
GAT
GAT$_{8h}$$
^\dagger$
GATv2
GATv22.654.281.411.472.2916.3714.03
Model8910111213Rel. to GAT
GCN1.02-1.5%
GIN5.885.625.383.53-2.3%
GAT+134.1%
GAT$_{8h}
$$^\dagger$1.48+0%
GATv2+91.6%
GATv26.076.286.605.973.57-11.5%

Table 8: Average error rates (lower is better), 5 runs standard deviation for each property, on the QM9 dataset. The best result among GAT and GATv2 is marked in bold; the globally best result among all GNNs is marked in bold and underline. was previously tuned and reported by Brockschmidt (2020)Brockschmidt in twenty twenty.

D.3 PUBMED CITATION NETWORK

We tuned the following parameters for both GAT and GATv2: number of layers $\in \{0, 1, 2\}$, hidden size $\in \{8, 16, 32\}$, number of heads $\in \{1, 4, 8\}$, dropout $\in \{0.4, 0.6, 0.8\}$, bias $\in \{\text{True}, \text{False}\}$, share weights $\in \{\text{True}, \text{False}\}$, use residual $\in \{\text{True}, \text{False}\}$. Table 9 shows the test accuracy (100 runs$\pm$stdev) using the best hyperparameters found for each model. We tuned the following parameters for both GAT and GAT v 2: number of layers, hidden size, number of heads, dropout, bias, weight sharing, and the use of residuals. Table 9 shows the test accuracy over 100 runs, plus or minus the standard deviation, using the best hyperparameters found for each model.

Table 9: Accuracy (100 runsstdev) on Pubmed. GATv2 is more accurate than GAT.

ModelAccuracy
GAT
GATv278.5

It is important to note that PubMed has only 60 training nodes, which hinders expressive models such as GATv2 from exploiting their approximation and generalization advantages. Still, GATv2 is more accurate than GAT even in this small dataset. In Table 14, we show that this difference is statistically significant (p-value p value less than zero point zero zero zero one).

E ADDITIONAL COMPARISON WITH TRANSFORMER-STYLE ATTENTION (DPGAT)

The main goal of our paper is to highlight a severe theoretical limitation of the highly popular GAT architecture, and propose a minimal fix.

We perform additional empirical comparison to DPGAT, which follows Luong et al. (2015)Luong and colleagues and the dot-product attention of the Transformer (Vaswani et al., 2017)by Vaswani and colleagues. We define DPGAT as:

e of h i, h j is defined as the dot product of h i transpose Q and the transpose of h j transpose K, all divided by the square root of d k

Variants of DPGAT were used in prior work (Gao and Ji, 2019; Dwivedi and Bresson, 2020; Rong et al., 2020a; Veličković et al., 2020; Kim and Oh, 2021), and we consider it here for the conceptual and empirical comparison with GAT.

Despite its popularity, DPGAT is strictly weaker than GATv2. DPGAT provably performs dynamic attention for any set of node representations only if they are linearly independent (see Theorem 3 and its proof in Appendix E.1). Otherwise, there are examples of node representations that are linearly dependent and mappings phi, for which dynamic attention does not hold (Appendix E.2). This constraint is not harmful when violated in practice, because every node has only a small set of neighbors, rather than all possible nodes in the graph; further, some nodes possibly never need to be “selected” in practice.

E.1 PROOF THAT DPGAT PERFORMS DYNAMIC ATTENTION FOR LINEARLY INDEPENDENT NODE REPRESENTATIONS

Theorem 3. A DPGAT layer computes dynamic attention for any set of node representations K equals Q equals the set of h one through h n that are linearly independent.

Proof. Let G equals V, E be a graph modeled by a DPGAT layer, having linearly independent node representations h one through h n. Let phi from n to n be any node mapping n to n.

We denote the row of a matrix as .

We define a matrix as:

Let X in R n by d be the matrix holding the graph’s node representations as its rows:

Published as a conference paper at ICLR 2022

Since the rows of X are linearly independent, it necessarily holds that d is greater than or equal to n.

Next, we find weight matrices Q and and K such that:

To satisfy Equation (16), we choose Q and K such that X Q equals U and X K equals P transpose U where U is an orthonormal matrix U times U transpose equals the identity matrix.

We can obtain U using the singular value decomposition (SVD) of X:

Since Sigma and X has a full rank, Sigma is invertible, and thus:

Now, we define Q as follows:

Note that X Q equals U, as desired.

To find K that satisfies X K equals P transpose U, we use Equation (17) and require:

and thus:

We define:

z of h i and h j is defined as e of h i and h j times the square root of d k

Where is the attention score function of DPGAT (Equation (13)).

Now, for a query i and a key j, and the corresponding representations h i and h j:

Since X i Q equals the i-th row of X Q and and X j K equals the j-th row of X K, we get

Therefore:

And thus:

To conclude, for every selected query i and any key j not equal to phi of i:

and due to the increasing monotonicity of softmax:

Hence, a DPGAT layer computes dynamic attention.

In the case that d is greater than n, we apply SVD to the full-rank matrix X X transpose in the set of real n by n matrices, and follow the same steps to construct and .

In the case that and and Q and K are d by d sub k, and d sub k is greater than d, we can use the same and (Equations (19) and (21)) padded with zeros. We define the and as follows:

E.2 DPGAT IS STRICTLY WEAKER THAN GATV2

There are examples of node representations that are linearly dependent and mappings phi, for which dynamic attention does not hold. First, we show a simple 2-dimensional example, and then we show the general case of such examples.

A 2D coordinate system showing three vectors starting from the origin: h0 (blue) along the x-axis, h1 (red), and h2 (green) with increasing slopes.Figure 7: An example for node representations that are linearly dependent, for which DPGAT cannot compute dynamic attention, because no query vector q in R two can “select” h one.

Consider the following linearly dependent set of vectors (Figure 7):

where and x hat and y hat are the cartesian unit vectors. We define beta in the set zero, one, two to express using the same expression:

h beta equals x hat plus beta times y hat

Let q in Q be any query vector. For brevity, we define the unscaled dot-product attention score as :

s of q and h beta is the attention score e times the square root of d k

Where is the attention score function of DPGAT (Equation (13)). The (unscaled) attention score between and is:

The first term q transpose Q times x hat transpose K transpose is unconditioned on , and thus shared for every . Let us focus on the second term . If that term is positive, then:

the attention score for h two is greater than for h one

Otherwise, if the product of q transpose Q and the transpose of y hat transpose K is less than or equal to zero:

Thus, for any query q, the key h one can never get the highest score, and thus cannot be “selected”. That is, the key h one cannot satisfy that e of q comma h one is strictly greater than any other key.

In the general case, let h zero and h one be non-zero vectors in R d be some non-zero vectors , and lambda is some scalar such that zero is less than lambda is less than one.

Consider the following linearly dependent set of vectors:

For any query q in Q and beta in the set zero, lambda, one we define:

Where is the attention score function of DPGAT (Equation (13)).

Therefore:

If the product of q transpose Q and the transpose of the difference h one transpose K minus h zero transpose K is greater than zero:

Otherwise, if the product is less than or equal to zero:

Thus, for any query q, the key h lambda cannot be selected. That is, the key h lambda cannot satisfy that e of q comma h lambda is strictly greater than any other key. Therefore, there are mappings phi, for which dynamic attention does not hold.

While we prove that GATv2 computes dynamic attention (Appendix A) for any set of node representations K equals Q, there are sets of node representations and mappings phi for which dynamic attention does not hold for DPGAT. Thus, DPGAT is strictly weaker than GATv2.

E.3 Empirical Evaluation

Here we repeat the experiments of Section 4 with DPGAT. We remind that DPGAT is strictly weaker than our proposed GATv2 (see a proof in Appendix E.1).

F Statistical Significance

Here we report the statistical significance of the strongest GATv2 and GAT models of the experiments reported in Section 4.

Two line graphs showing accuracy versus noise ratio for ogbn-arxiv and ogbn-mag datasets.Figure 8: Test accuracy compared to the noise ratio: GATv2 and DPGAT are more robust to structural noise compared to GAT. Each point is an average of 10 runs, error bars show standard deviation.

Table 10: Accuracy (5 runsplus or minusstdev) on VARMISUSE. GATv2 is more accurate than all GNNs in both test sets, using GAT’s hyperparameters. dagger – previously reported by Brockschmidt (2020).

ModelSeenProjUnseenProj
No-AttentionGCN
GIN
AttentionGAT
DPGAT
GATv2

Table 11: Average accuracy (Table 11a) and ROC-AUC (Table 11b) in node-prediction datasets (10 runsplus or minusstd). In all datasets, GATv2 outperforms GAT. dagger – previously reported by Hu et al. (2020).

(a)(b)
ModelAttn. Headsogbn-arxivogbn-productsogbn-magogbn-proteins
GCN0
GraphSAGE0
GAT1
8
DPGAT1
8
GATv2 (this work)1
8
Published as a conference paper at ICLR 2022

Table 12: Average error rates (lower is better), 5 runs plus or minus standard deviation for each property, on the QM9 dataset. The best result among GAT, GATv2 and DPGAT is marked in bold; the globally best result among all GNNs is marked in . dagger was previously tuned and reported by Brockschmidt (2020)Brockschmidt in twenty twenty.

Model1234567
GCN
GIN
GAT
GAT$_{8h}$$
^\dagger$
DPGAT
DPGAT
GATv2
GATv2
Model8910111213Rel. to GAT
GCN-1.5%
GIN-2.3%
GAT+134.1%
GAT$_{8h}
$$^\dagger$+0%
DPGAT+77.9%
DPGAT-9.7%
GATv2+91.6%
GATv2-11.5%

Line charts comparing the accuracy of GATv2 and GAT models across different noise ratios for ogbn-arxiv and ogbn-mag datasets. The plots show that GATv2 maintains higher accuracy and higher statistical significance as noise increases.Figure 9: Test accuracy and statistical significance compared to the noise ratio: GATv2 is more robust to structural noise compared to GAT. Each point is an average of 10 runs, error bars show standard deviation.

Table 13: Accuracy (5 runsstdev)plus or minus standard deviation on VARMISUSE. GATv2 is more accurate than all GNNs in both test sets, using GAT’s hyperparameters. dagger – previously reported by Brockschmidt (2020)Brockschmidt in twenty twenty.

ModelSeenProjUnseenProj
GAT
GATv2
p-value0.0480.049

Table 14: Accuracy (100 runs plus or minus stdev) on Pubmed. GATv2 is more accurate than GAT.

ModelAccuracy
GAT
GATv278.5
p-value< 0.0001

Table 15: Average accuracy (Table 15a) and ROC-AUC (Table 15b) in node-prediction datasets (30 runs plus or minus std). We report on the best GAT / GATv2 from Table 1.

(a)

Modelogbn-arxivogbn-productsogbn-mag
GAT
GATv271.93 80.63 33.01
p-value0.0022<0.00010.0018

(b)

ogbn-proteins
GAT
GATv278.96
p-value0.0349

Table 16: Average Hits@50 (Table 16a) and mean reciprocal rank (MRR) (Table 16b) in link-prediction benchmarks from OGB (30 runs plus or minus std). We report on the best GAT / GATv2 from Table 3.

(a)

ogbl-collab
Modelw/o val edgesw/ val edges
GAT
GATv243.82 49.06
p-value0.00430.0005

(b)

ogbl-citation2
GAT
GATv280.20
p-value0.0075

Table 17: Average error rates (lower is better), 20 runs plus or minus standard deviation for each property, on the QM9 dataset. We report on GAT and GATv2 with 8 attention heads.

Predicted Property
Model1234567
GAT
GATv22.67 4.28 1.43 1.51 2.21 16.64 13.61
p-value0.0043<0.00010.01380.16910.04870.00010.0516
Predicted Property
Model8910111213
GAT
GATv26.13 6.33 6.37 5.95 3.66 1.09
p-value<0.00010.04580.00060.0017<0.00010.0621

G Complexity Analysis

We repeat the definitions of GAT, GATv2 and DPGAT:

G.1 Time Complexity

GAT As noted by Veličković et al. (2018)Veličković and colleagues, the time complexity of a single GAT head may be expressed as big O of, the number of vertices times d d prime, plus the number of edges times d prime. Because of GAT’s static attention, this computation can be further optimized, by merging the linear layer with , merging with , and only then compute for every .

GATv2 require the same computational cost as GAT’s declared complexity: : we denote , where and contain the left half and right half of the columns of , respectively. We can first compute and for every . This takes .

Then, for every edge , we compute using the precomputed and , since . This takes .

Finally, computing the results of the linear layer takes additional time, and overall .

DPGAT also takes the same time. We can first compute and for every . This takes . Computing the dot-product for every edge takes additional time, and overall .

G.2 Parametric Complexity

GATGATv2DPGAT
Official
In our experiments

Table 18: Number of parameters for each GNN type, in a single layer and a single attention head.

All parametric costs are summarized in Table 18. All following calculations refer to a single layer having a single attention head, omitting bias vectors.

GAT has learned vector and a matrix: and , thus overall learned parameters.

GATv2 has a matrix that is twice larger: , because it is applied on the concatenation . Thus, the overall number of learned parameters is . However in our experiments, to rule out the increased number of parameters over GAT as the source of empirical difference, we constrained , and thus the number of parameters were .

DPGAT has and matrices of sizes each, and additional parameters in the value matrix , thus parameters overall. However in our experiments, we constrained and set , and thus the number of parameters is only .

Footnotes

  1. An annotated implementation of GATv2 is available at nn.labml.ai

  2. from torch_geometric.nn.conv.gatv2_conv import GATv2Conv

  3. from dgl.nn.pytorch import GATv2Conv

  4. from tensorflow_gnn.graph.keras.layers.gat_v2 import GATv2Convolution

  5. We also add a bias vector before applying the nonlinearity, we omit this in Equation (7) for brevity.

  6. Twitter

  7. The function is a function that we define for the ease of proof, because the universal approximation theorem is defined for continuous functions, and we only need the scoring function of GATv2 to approximate the mapping in a finite set of points. So, we need the attention function to approximate (from Equation 8) in some specific points. But, since is not continuous, we define and use the universal approximation theorem for . Since approximates , also approximates in our specific points, as a special case. We only require that will be identical to in specific points . For the rest of the input space, we don’t have any requirement on the value of , except for maintaining the continuity of . There exist infinitely many such possible for every given set of keys, queries and a mapping , but the concrete functions are not needed for the proof.