Pure Transformers are Powerful Graph Learners

Jinwoo Kim, Tien Dat Nguyen, Seonwoo Min, Sungjun Cho, Moontae Lee, Honglak Lee, Seunghoon Hong

Introduction

In recent years, Transformer has served as a versatile architecture in a broad class of machine learning problems, such as natural language processing , computer vision , and reinforcement learning , to name a few. It is because the fully-attentional structure of Transformer is general and powerful enough to take, process, and relate inputs and outputs of arbitrary structures, eliminating a need for data- and task-specific inductive bias to be baked into the network architecture. Combined with large-scale training, it opens up a new chapter for building a versatile model that can solve a wide range of problems involving diverse data modalities and even a mixture of modalities .

In graph learning domain, inspired by the breakthroughs, multiple works tried combining self-attention into graph neural network (GNN) architecture where message passing was previously dominant . As global self-attention across nodes cannot reflect the graph structure, however, these methods introduce graph-specific architectural modifications. This includes restricting self-attention to local neighborhoods , using global self-attention in conjunction with message-passing GNN , and injecting edge information into global self-attention via attention bias . Despite decent performance, such modifications can be a limiting constraint in terms of versatility, especially considering future integration to multi-task and multi-modal general-purpose attentional architectures . In addition, deviating from pure self-attention, these methods may inherit the issues of message-passing such as oversmoothing , and become incompatible with useful engineering techniques e.g., linear attention developed for standard self-attention.

Instead, we explore the opposite direction of applying a standard Transformer directly for graphs. For this, we treat all nodes and edges as independent tokens, augment them with appropriate token-wise embeddings, and feed the tokens as input to the standard Transformer. The model operates identically to Transformers used in language and vision; each node or edge is treated as a token, identical to the words in a sentence or patches of an image . Perhaps surprisingly, we show that this simple approach yields a powerful graph learner both in theory and practice.

As a key theoretical result, we prove that with appropriate token-wise embeddings, self-attention over the node and edge tokens can approximate any permutation equivariant linear operator on a graph . Remarkably, we show that a very simple choice of embedding composed of node identifiers and type identifiers is sufficient for accurate approximation. This provides a solid theoretical guarantee that, with the embeddings and enough attention heads, a Transformer is at least as expressive as a second-order invariant graph network (2-IGN) , which is already more expressive than all message-passing GNNs . This also immediately grants the model with the expressive power at least as good as the 2-dimensional Weisfeiler-Lehman (WL) graph isomorphism test , which is often sufficient for real-world graph data . We further extend our theoretical result to hypergraphs with order-kk hyperedges, showing that a Transformer with order-kk generalized token embeddings is at least as expressive as kk-IGN and, consequently kk-WL test.

We test our model, named Tokenized Graph Transformer (TokenGT), mainly on the PCQM4Mv2 large-scale quantum chemical property prediction dataset containing 3.7M molecular graphs . Even though TokenGT involves minimal graph-specific architectural modifications, it performs significantly better than all GNN baselines, showing that the advantages of Transformer architecture combined with large-scale training surpass the benefit of hard inductive bias of GNNs. Furthermore, TokenGT achieves competitive performance compared to Transformer variants with strong graph-specific modifications . Finally, we demonstrate that TokenGT can naturally utilize efficient approximations in Transformers in contrast to these variants, using kernel attention that enables linear computation cost without much degradation in performance.

Tokenized Graph Transformer (TokenGT)

In this section, we present the Tokenized Graph Transformer (TokenGT), a pure Transformer architecture for graphs with token-wise embeddings composed of node identifiers and type identifiers (Figure 1). Our goal in this section is to provide a practical overview – for theoretical analysis of the architecture, we guide the readers to Section 3.

The first component of token-wise embedding is the orthonormal node identifier that we use to represent the connectivity structure given in the input graph.

For each node v∈Vv\in\mathcal{V}, we augment the token Xv\mathbf{X}_{v} as [Xv,Pv,Pv][\mathbf{X}_{v},\mathbf{P}_{v},\mathbf{P}_{v}].

For each edge (u,v)∈E(u,v)\in\mathcal{E}, we augment the token X(u,v)\mathbf{X}_{(u,v)} as [X(u,v),Pu,Pv][\mathbf{X}_{(u,v)},\mathbf{P}_{u},\mathbf{P}_{v}].

Intuitively, a Transformer operating on the augmented tokens can fully recognize the connectivity structure of the graph since comparing the node identifiers between a pair of tokens reveals their incidence information. For instance, we can tell if an edge e=(u,v)e=(u,v) is connected with a node kk through dot-product (attention) since [Pu,Pv][Pk,Pk]⊤=1[\mathbf{P}_{u},\mathbf{P}_{v}][\mathbf{P}_{k},\mathbf{P}_{k}]^{\top}=1 if and only if k∈(u,v)k\in(u,v) and 0 otherwise. This allows the Transformer to identify and exploit the connectivity structure of a graph, for instance by putting more weights on incident pairs when the local operation is important.

Notably, as the node identifiers P\mathbf{P} are only required to be orthonormal, we have a large degree of freedom in implementation choices. We outline two practical methods below as examples. Their implementation details can be found in Appendix A.3.1.

Among the two methods, node identifiers generated as ORFs do not encode any information about the graph structure as they are entirely random. This means the Transformer that operates on the ORF-based node identifiers needs to compile and recognize graph structure only from the incidence information provided by the node identifiers. Although this is challenging, perhaps surprisingly, we empirically show in Section 5 that Transformers are strong enough to learn meaningful structural representations out of ORF-based node identifiers and outperform GNNs on large-scale task.

In contrast to ORFs, Laplacian eigenvectors provide a kind of graph positional embeddings (graph PEs) that describes the distance between nodes on a graph. Due to the positional information, it yields better performance compared to ORFs in our experiments in Section 5. One interesting aspect of Laplacian eigenvectors is that they can be viewed as a generalization of sinusoidal positional embeddings of NLP Transformers to graphs, as the eigenvectors of 1D chain graphs are sine and cosine functions . Thus, by choosing Laplacian eigenvectors as node identifiers, our approach can be interpreted as a direct extension of the NLP Transformer for inputs involving relational structures.

For each node v∈Vv\in\mathcal{V}, we augment the token [Xv,Pv,Pv][\mathbf{X}_{v},\mathbf{P}_{v},\mathbf{P}_{v}] as [Xv,Pv,Pv,EV][\mathbf{X}_{v},\mathbf{P}_{v},\mathbf{P}_{v},\mathbf{E}^{\mathcal{V}}].

For each edge (u,v)∈E(u,v)\in\mathcal{E}, we augment the token [X(u,v),Pu,Pv][\mathbf{X}_{(u,v)},\mathbf{P}_{u},\mathbf{P}_{v}] as [X(u,v),Pu,Pv,EE][\mathbf{X}_{(u,v)},\mathbf{P}_{u},\mathbf{P}_{v},\mathbf{E}^{\mathcal{E}}].

These embeddings provide information on whether a given token is a node or an edge, which is critical, e.g., when an attention head tries to attend specifically to node tokens and ignore edge tokens.

Similar to Transformers in language and vision , Tokenized Graph Transformer treats input nodes and edges as independent tokens and applies self-attention to them. This approach leads to much less inductive bias than current GNNs, where the sparse graph structure, or more fundamentally, permutation symmetry of graphs is deliberately baked into each layer . For TokenGT, such information is provided entirely as a part of input using token-wise embeddings, and the model has to learn how to interpret and utilize the information from data. Although such weak inductive bias might raise questions on the expressiveness of the model, our theoretical analysis in Section 3 shows that TokenGT is a powerful graph learner thanks to the token-wise embeddings and expressive power of self-attention. For example, we show that TokenGT is more expressive than all message-passing GNNs under the framework of Gilmer et al. (2017) .

Theoretical Analysis

We now present our theory. Our key result is that TokenGT, a standard Transformer with node and type identifiers presented in Section 2, is provably at least as expressive as the second-order Invariant Graph Network (2-IGN ), which is built upon all possible permutation equivariant linear layers on a graph. This provides solid theoretical guarantees for TokenGT, such as being at least as powerful as the 2-WL graph isomorphism test and more expressive than all message-passing GNNs. Our theory is based on a general framework on hypergraphs represented as higher-order tensors, which leads to the formulation of order-kk TokenGT that is at least as expressive as order-kk IGN (kk-IGN ).

We mainly develop our theoretical analysis upon Invariant Graph Networks (IGNs) , a family of expressive graph networks derived from the permutation symmetry of tensor representation of graphs. Here we provide a summary. In general, we define:

A body of previous work have shown appealing theoretical properties of kk-IGN, including universal approximation and alignment to kk-Weisfeiler-Lehman (kk-WL) graph isomorphism test . In particular, it is known that kk-IGNs are theoretically at least as powerful as the kk-WL test . It is also known that 2-IGNs are already more expressive than all message-passing GNNs under the framework of Gilmer et al. (2017) .

The core building block of IGN is invariant and equivariant linear layers with maximal expressiveness while respecting node permutation symmetry. The layers are defined as follows:

We provide the definition of the equivalence classes and basis tensors in Appendix A.1.1. For now, it is sufficient to know that the basis tensors are binary tensors that form the orthogonal basis of the full space of linear equivariant layers. In general, in Eq. (2) it is known that there exists bell(k+l)\textnormal{bell}(k+l) number of basis tensors Bμ\mathbf{B}^{\mu} for the weight and bell(l)\textnormal{bell}(l) number of basis tensors Cλ\mathbf{C}^{\lambda} for the bias.

2 Can Self-Attention Approximate Equivariant Basis?

Now, we present an intuition that connects Transformer (Section 2) and equivariant linear layer (Definition 2). For that, we write out the multihead self-attention layer as follows:

Now consider approximating basis tensor Bμ1=I\mathbf{B}^{\mu_{1}}=\mathbf{I} with an attention matrix α1\boldsymbol{\alpha}^{1}. The approximation is accurate when ii-th query always only attends to ii-th key and ignores the rest. To achieve the attention structure consistently, i.e., agnostic to input X\mathbf{X}, we need to provide auxiliary input that self-attention can "latch onto" to faithfully approximate α1≈I\boldsymbol{\alpha}^{1}\approx\mathbf{I}. Without this, attention must entirely rely on the inputs X\mathbf{X}, which is unreliable and can lead to approximation failure, e.g., when X\mathbf{X} has repeated rows.

Thus, self-attention can utilize the auxiliary information P\mathbf{P} to achieve an input-agnostic approximation of α1\boldsymbol{\alpha}^{1} to I\mathbf{I}. Notably, we can achieve a similar approximation for Bμ2=11⊤−I\mathbf{B}^{\mu_{2}}=\mathbf{11}^{\top}-\mathbf{I} using the same P\mathbf{P} by flipping the sign of keys, which gives α2=softmax(−aI)\boldsymbol{\alpha}^{2}=\textnormal{softmax}(-a\mathbf{I}) due to orthonormality. By sending a→∞a\to\infty, now attention from the ii-th query to the ii-th key is suppressed, and we obtain the following:

Note that this approximation is accurate only up to row normalization as rows of α2\boldsymbol{\alpha}^{2} always sum to one due to softmax, while Bμ2=11⊤−I\mathbf{B}^{\mu_{2}}=\mathbf{11}^{\top}-\mathbf{I} is binary. In our proofs of the theoretical results, we perform appropriate denormalization with MLP after MSA to achieve an accurate approximation.

Overall, we see that simple auxiliary input P\mathbf{P} suffices for two attention heads to approximate the equivariant basis of L1→1L_{1\to 1} accurately. We now question the following. Given appropriate auxiliary information as input, can a Transformer layer with bell(2k)\textnormal{bell}(2k) attention heads accurately approximate Lk→kL_{k\to k} by having each head approximate each equivariant basis Bμ\mathbf{B}^{\mu}? What would be the sufficient auxiliary input? We answer the question by showing that, with (order-kk generalized) node and type identifiers presented in Section 2, Transformer layers can accurately approximate equivariant layers Lk→kL_{k\to k} via input-agnostic head-wise approximation of each equivariant basis.

3 Pure Transformers are Powerful Graph Learners

We now present our main theoretical results that extend the discussions in Section 3.2 to any order kk. Note that k=2k=2 corresponds to TokenGT for graphs presented in Section 2. With k>2k>2, we naturally extend TokenGT to hypergraphs. All proofs can be found in Appendix A.1.

Let us exemplify. For k=1k=1 (sets), each ii-th entry is augmented as [Xi,Pi,Eγ1][\mathbf{X}_{i},\mathbf{P}_{i},\mathbf{E}^{\gamma_{1}}], consistent with our discussion in Section 3.2. For k=2k=2 (graphs), each (i,i)(i,i)-th entry is augmented as [Xii,Pi,Pi,Eγ1][\mathbf{X}_{ii},\mathbf{P}_{i},\mathbf{P}_{i},\mathbf{E}^{\gamma_{1}}] and each (i,j)(i,j)-th entry (i≠ji\neq j) is augmented as [Xij,Pi,Pj,Eγ2][\mathbf{X}_{ij},\mathbf{P}_{i},\mathbf{P}_{j},\mathbf{E}^{\gamma_{2}}]. This is consistent with TokenGT in Section 2, which augments nodes with EV=Eγ1\mathbf{E}^{\mathcal{V}}=\mathbf{E}^{\gamma_{1}} and edges with EE=Eγ2\mathbf{E}^{\mathcal{E}}=\mathbf{E}^{\gamma_{2}}.

Consequently, with the node and type identifiers, a collection of bell(2k)\textnormal{bell}(2k) attention heads can approximate the collection of all basis tensors of order-kk equivariant layer. This leads to the following:

While the approximation in Lemma 1 is only accurate up to normalization over inputs (keys) due to softmax normalization, for the approximation in Theorem 1 we perform appropriate denormalization using MLP after multihead self-attention and can obtain an accurate approximation.

By extending the result to multiple layers, we arrive at the following:

This directly leads to the following corollary:

A Transformer on node and type identifiers in Theorem 2 is at least as expressive as kk-IGN composed of order-kk equivariant linear layers.

Corollary 1 allows us to draw previous theoretical results on the expressiveness of kk-IGN and use them to lower-bound the provable expressiveness of a standard Transformer:

A Transformer on node and type identifiers in Theorem 2 is at least as powerful as kk-WL graph isomorphism test and is more expressive than all message-passing GNNs within the framework of Gilmer et al. (2017) .

Related Work

We outline relevant work including equivariant neural networks, theory on expressive power of Transformers and their connection to modeling equivariance, and Transformers for graphs.

A machine learning task is often invariant or equivariant to specific symmetry of input data, e.g., image classification is invariant to the translation of an input image. A large body of literature advocated baking the invariance or equivariance into a neural network as a type of inductive bias (e.g., translation equivariance of image convolution), showing that it reduces the number of parameters and improves generalization for a wide range of learning tasks involving various geometric structures . Ravanbakhsh et al. (2017) showed that any equivariant layer for discrete group actions is equivalent to a specific parameter sharing structure. Zaheer et al. (2017) and Maron et al. (2019) derived the parameter sharing for node permutation-symmetric data (sets and (hyper)graphs), which gives the maximally expressive equivariant linear layers and kk-IGN in Section 3.1. The work on equivariant neural networks underlie our theory of how a standard Transformer can be a powerful learner for sets and (hyper)graphs.

Recent work involving Transformers often focus on minimizing the domain- and task-specific inductive bias and scaling the model and data so that any useful computation structure can be learned . The success of this approach is, to some degree, attributed to the high expressive power of Transformers that allows learning diverse functions suited for the data at hand . Recent theory has shown that Transformers are expressive enough to even model certain equivariant functions . Andreoli et al. (2019) cast self-attention and convolution into a unified framework using basis tensors similar to ones in Section 3.1. Cordonnier et al. (2020) advanced the idea and showed that Transformers with relative positional encodings can approximate any image convolution layers. Lee et al. (2019) and Kim et al. (2021) showed that Transformers can model equivariant linear layers for sets , which can be viewed as the first-order case of our theory (see Section 3.2). To our knowledge, our work is the first to show that standard Transformers are expressive enough to provably model maximally expressive equivariant layers and kk-IGN for (hyper)graphs with k≥2k\geq 2.

Unlike in language and vision, developing Transformers for graphs is challenging due to (1) the presence of edge connectivity and (2) the absence of canonical node ordering that prevents adopting simple positional encodings . To incorporate the connectivity of edges, early methods restricted self-attention to local neighborhoods (thus reducing to message-passing) or used global self-attention with auxiliary message-passing modules . As message-passing suffers from limited expressive power and oversmoothing , recent works often discard them and use global self-attention on nodes with heuristic modifications to process edges . Ying et al. (2021) proposed to inject edge encoding based on shortest paths through self-attention bias. Kreuzer et al. (2021) proposed to incorporate edges into self-attention matrix via elementwise multiplication. On the contrary, we leave the self-attention unmodified and provide both nodes and edges with certain token-wise embeddings (Section 2) as its input. To incorporate graph structure into nodes, on the other hand, some approaches focus on developing graph positional encoding, e.g., based on Laplacian eigenvectors . While these can be directly incorporated into our work via auxiliary node identifiers for better performance, we leave this as future work. We further note that current graph Transformers that utilize Laplacian positional encoding rely heavily on heuristic edge encoding while ours does not. Another closely related approach is the Higher-order Transformer which generalizes kk-IGN with masked self-attention. While it is highly complex to implement due to hard-coded head-wise equivariant masks, our method can be implemented effortlessly using any available implementation of standard Transformer. Furthermore, our method is more flexible as the model can choose to use different attention heads to focus on a specific equivariant operator (e.g., local propagation) if needed. We further discuss the difficulty in applying linear attention to graph Transformers in Appendix A.2.

Experiments

We first conduct a synthetic experiment that directly confirms our key claims in Lemma 1 (Section 3). Then, we empirically explore the capability of Tokenized Graph Transformer (TokenGT) (Section 2) using the PCQM4Mv2 large-scale quantum chemistry regression dataset . We further present experiments on transductive node classification datasets involving large graphs in Appendix A.4.3.

As in Theorem 1 and 2 (Section 3), our argument on the expressive power of TokenGT relies on its capability to approximate order-kk permutation equivariant linear layers Lk→kL_{k\to k} (Definition 2). Specifically, Lemma 1 states that such capability depends on the ability of each self-attention head α1,...,αH\boldsymbol{\alpha}^{1},...,\boldsymbol{\alpha}^{H} (Eq. (3)) to accurately approximate each equivariant basis Bμ1,...,Bμbell(2k)\mathbf{B}^{\mu_{1}},...,\mathbf{B}^{\mu_{\textnormal{bell}(2k)}} (Definition 2) up to normalization.

We verify this claim for k=2k=2 (second-order; graphs) in a synthetic setup using Barabási-Albert random graphs. We use a multihead self-attention layer (Eq. (3)) with bell(2+2)=15\textnormal{bell}(2+2)=15 heads and explicitly supervise head-wise attention scores αh\boldsymbol{\alpha}^{h} to approximate each (normalized) equivariant basis tensor Bμh\mathbf{B}^{\mu_{h}} by minimizing L2 loss. Having the layer hyperparameters fixed, we provide different combinations of node and type identifiers, and test if multihead self-attention can jointly approximate all 15 equivariant basis on unseen graphs. We experiment with both dense and sparse graph representations; for graphs with nn nodes and mm edges, the dense graph considers all n2n^{2} pair-wise edges as input as in Section 3, whereas the sparse graph considers only the present mm edges as in Section 2. Further details can be found in Appendix A.3.2.

We outline the results in Table LABEL:table:equivariant_basis_approximation_std. Consistent with Lemma 1, self-attention achieves accurate approximation of equivariant basis only when both the orthonormal node identifiers and type identifiers are given. Here, Laplacian eigenvectors (Lap, ◯\bigcirc) often yield slightly better results than orthogonal random features (ORF, ◯\bigcirc) presumably due to less stochasticity. Interestingly, we see that self-attention transfers the learned (pseudo-)equivariant self-attention structure to unseen graphs near perfectly. Non-orthogonal random embeddings lead to inaccurate approximation (Random, ◯\bigcirc), highlighting the importance of orthogonality of node identifiers. The approximation is also inaccurate when we sample ORF Pt\mathbf{P}_{t} independently for each token tt (ORF (first-order), ◯\bigcirc) instead of using concatenated node identifiers [Pu,Pv][\mathbf{P}_{u},\mathbf{P}_{v}] for token (u,v)(u,v). This supports our argument in Section 2 that the incidence information implicitly provided via node identifiers plays a key role in approximation.

In Figure 2, we provide a visualization of self-attention maps learned under various node and type identifier choices. Additional results can be found in Appendix A.4.1.

2 Large-Scale Graph Learning

An exclusive characteristic of TokenGT is its minimal graph-specific inductive bias, which requires it to learn internal computation structure largely from data. As such models are commonly known to work well with large-scale data , we explore the capability of TokenGT on the PCQM4Mv2 quantum chemistry regression dataset , one of the current largest with 3.7M molecular graphs.

For TokenGT, we use both node and type identifiers, and use main Transformer encoder configuration based on Graphormer with 12 layers, 768 hidden dimension, and 32 attention heads. We try both ORF and Laplacian eigenvector as node identifiers, and denote corresponding models as TokenGT (ORF) and TokenGT (Lap) respectively. As an ablation, we also experiment with the same Transformer without node and type identifiers, which we denote as Transformer. Finally, we apply the kernel attention that approximates the attention computation to linear cost (TokenGT (Lap) + Performer). We use AdamW optimizer with (β1,β2)=(0.99,0.999)(\beta_{1},\beta_{2})=(0.99,0.999) and weight decay 0.1, and 60k learning rate warmup steps followed by linear decay over 1M iteration with batch size 1024. For fine-tuning, we use 1k warmup, 0.1M training steps, and cosine learning rate decay. We train the models on 8 RTX 3090 GPUs for 3 days. Further details are in Appendix A.3.3.

We provide the results in Table LABEL:table:pcqm4mv2. A standard Transformer on the node and edge tokens cannot recognize graph structure and shows low performance (0.2340 valid MAE). Yet, the picture changes as soon as we augment the tokens with node and type identifiers. Notably, TokenGT (ORF) achieves 0.0962 MAE, which is already better than all GNN baselines. This is a somewhat surprising result, as both ORF and the Transformer are not aware of graph structures. This implies Transformer is strong enough to learn to interpret and reason over the incidence structure of tokens provided only implicitly by the node and type identifiers. By further switching to Laplacian eigenvectors that encode position on graphs , we observe a performance boost to 0.0910 MAE, competitive to Transformers with sophisticated graph-specific modifications (e.g., shortest path-based spatial encoding ). While such methods inject graph structure into attention matrix via bias term and therefore strictly require O(n2)\mathcal{O}(n^{2}) cost, TokenGT enables adopting kernelization for pure self-attention , resulting in TokenGT (Lap) + Performer with the best performance among O(n+m)\mathcal{O}(n+m) models (0.0935 MAE). Further discussion on the empirical performance of TokenGT can be found in Appendix A.5.

While our theory in Section 3 guarantees that TokenGT can reduce to an equivariant layer by learning fixed equivariant basis at each attention head, in practice, it can freely utilize multihead self-attention to learn less restricted and more useful computation structure from data. To analyze such a structure, we compute the attention distance across heads and network depth by averaging pairwise token distances on a graph weighted by their attention scores (Figure 3). This distance is analogous to the number of hops in message-passing. In both TokenGT (ORF) and TokenGT (Lap), in the lowest layers, some heads attend globally over the graph while others consistently have small receptive fields (acting like a local message-passing operator). In deeper layers, the attention distances increase, and most heads attend globally. Interestingly, this behavior is highly consistent with Vision Transformers on image patches , suggesting that hybrid architectures based on convolution to aid ViT might also work well for graphs. While TokenGT (ORF) shows relatively consistent attention distance over heads, TokenGT (Lap) shows higher variance, implying that it learns more diverse attention patterns. Judging from the higher performance of TokenGT (Lap), this suggests that the graph structure information of the Laplacian eigenvector facilitates learning useful and diverse attention structures, which calls for future exploration of better node identifiers based on graph PEs .

Conclusion

We showed that Transformers directly applied to graphs can work well in both theory and practice. In the theoretical aspect, we proved that with appropriate token-wise embeddings, a Transformer on node and edge tokens is at least as expressive as kk-IGN and kk-WL test, making it more expressive than all message-passing GNNs. For such token-wise embeddings, we showed that a combination of simple orthonormal node identifiers and trainable type identifiers suffices, which we also verified with a synthetic experiment. In an experiment with PCQM4Mv2 large-scale dataset, we show that Tokenized Graph Transformer (TokenGT) performs significantly better than all GNNs and is competitive with Transformer variants with strong graph-specific architectural components .

While the results suggest a promising research direction, there are challenges to be addressed in future work. First, treating each node and edge as tokens requires O((n+m)2)\mathcal{O}((n+m)^{2}) asymptotic cost due to the quadratic nature of self-attention. While we address this to some degree with kernelization and achieve O(n+m)\mathcal{O}(n+m) cost, other types of efficient Transformers (e.g., sparse) that can deliver better performance are left to be tested. Another issue is slightly lower performance compared to the state-of-the-art. Adopting Transformer engineering techniques from vision and language domains, such as data scaling , deepening , hybrid architectures , and self-supervision , are promising. In the societal aspect, to prevent the potential risky behavior in, e.g., decision making from graph-structured inputs, interpretability research regarding self-attention on graphs is desired.

We finish with interesting research directions that stem from our work. As our approach advocates viewing a graph as (n+m)(n+m) tokens , it opens up new paradigms of graph learning, including autoregressive decoding, in-context learning, prompting, and multimodal learning. Another interesting direction is to extend our theory and use self-attention to approximate equivariant basis for general discrete group actions, which might be a viable approach for learning equivariance from data.

This work was supported in part by Institute of Information & communications Technology Planning & Evaluation (IITP) (No. 2022-0-00926, 2022-0-00959, 2021-0-02068, and 2019-0-00075) and the National Research Foundation of Korea (NRF) (No. 2021R1C1C1012540) grants funded by the Korea government (MSIT).

References

Appendix A Appendix

We now provide the complete definition of invariant graph networks (IGNs) and maximally expressive equivariant linear layers summarized in Section 3.1. We first recall Definition 1 and 2:

We now define equivalence classes and basis tensors mentioned briefly in Definition 2. The equivalence classes are defined upon a specific equivalence relation ∼\sim on the index space of higher-order tensors as follows:

An order-ll equivalence class γ∈[n]l/∼\gamma\in[n]^{l}/_{\sim} is an equivalence class of [n]l[n]^{l} under the equivalence relation ∼\sim, where the equivalence relation ∼\sim on multi-index space [n]l[n]^{l} relates i∼j\mathbf{i}\sim\mathbf{j} if and only if (i1,...,il)=(π(j1),...,π(jl))(i_{1},...,i_{l})=(\pi(j_{1}),...,\pi(j_{l})) for some node permutation π∈Sn\pi\in S_{n}.

We note that a multi-index i\mathbf{i} has the same permutation-invariant equality pattern to any j\mathbf{j} that satisfies i∼j\mathbf{i}\sim\mathbf{j}, i.e., ia=ib⇔ja=jb\mathbf{i}_{a}=\mathbf{i}_{b}\Leftrightarrow\mathbf{j}_{a}=\mathbf{j}_{b} for all a,b∈[k]a,b\in[k]. Consequently, each equivalence class γ\gamma in Definition 3 is a distinct set of all order-ll multi-indices having a specific equality pattern.

Now, for each equivalence class, we define the corresponding basis tensor as follows:

For a given ll, it is known that there exist bell(l)\textnormal{bell}(l) order-ll equivalence classes {γ1,...,γbell(l)}=[n]l/∼\{\gamma_{1},...,\gamma_{\textnormal{bell}(l)}\}=[n]^{l}/_{\sim} regardless of nn . This gives bell(l)\textnormal{bell}(l) order-ll basis tensors Bγ1,...,Bγbell(l)\mathbf{B}^{\gamma_{1}},...,\mathbf{B}^{\gamma_{\textnormal{bell}(l)}} accordingly. Thus, an equivariant linear layer Lk→lL_{k\to l} in Definition 2 has bell(l+k)\textnormal{bell}(l+k) weights and bell(l)\textnormal{bell}(l) biases.

A.1.2 Proof of Lemma 1 (Section 3.3)

To prove Lemma 1, we need to show that each basis tensor Bμ\mathbf{B}^{\mu} (Eq. (14)) in weights of equivariant linear layers (Eq. (2)) can be approximated by the self-attention coefficient αh\boldsymbol{\alpha}^{h} (Eq. (7)) to arbitrary precision up to normalization if its input is augmented by node and type identifiers (Section 3.3).

From Definition 4, each entry of basis tensor Bi,jμ\mathbf{B}_{\mathbf{i},\mathbf{j}}^{\mu} encodes whether (i,j)∈μ(\mathbf{i},\mathbf{j})\in\mu or not. Here, our key idea is to break down the inclusion test (i,j)∈μ(\mathbf{i},\mathbf{j})\in\mu into equivalent but simpler Boolean tests that can be implemented in self-attention (Eq. (8)) as dot product of i\mathbf{i}-th query and j\mathbf{j}-th key followed by softmax.

To achieve this, we show some supplementary Lemmas. We start with Lemma 2, which comes from Lemma 1 of Kim et al. (2021) (we repeat their proof here for completeness).

For any order-(l+k)(l+k) equivalence class μ\mu, the set of all i∈[n]l\mathbf{i}\in[n]^{l} such that (i,j)∈μ(\mathbf{i},\mathbf{j})\in\mu for some j∈[n]k\mathbf{j}\in[n]^{k} forms an order-ll equivalence class. Likewise, the set of all j\mathbf{j} such that (i,j)∈μ(\mathbf{i},\mathbf{j})\in\mu for some i\mathbf{i} forms an order-kk equivalence class.

We only prove for i\mathbf{i} as proof for j\mathbf{j} is analogous. For some (i1,j1)∈μ(\mathbf{i}^{1},\mathbf{j}^{1})\in\mu, let us denote the equivalence class of i1\mathbf{i}^{1} as γl\gamma^{l} (i.e., i1∈γl\mathbf{i}^{1}\in\gamma^{l}). It is sufficient that we prove i∈γl⇔∃j:(i,j)∈μ\mathbf{i}\in\gamma^{l}\Leftrightarrow\exists\mathbf{j}:(\mathbf{i},\mathbf{j})\in\mu.

(⇒\Rightarrow) For all i∈γl\mathbf{i}\in\gamma^{l}, as i1∼i\mathbf{i}^{1}\sim\mathbf{i}, there exists some π∈Sn\pi\in S_{n} such that i=π(i1)\mathbf{i}=\pi(\mathbf{i}^{1}) by definition. As π\pi acts on multi-indices entry-wise, we have π(i1,j1)=(i,π(j1))\pi(\mathbf{i}^{1},\mathbf{j}^{1})=(\mathbf{i},\pi(\mathbf{j}^{1})). As π(i1,j1)∼(i1,j1)\pi(\mathbf{i}^{1},\mathbf{j}^{1})\sim(\mathbf{i}^{1},\mathbf{j}^{1}) holds by definition, we have (i,π(j1))∼(i1,j1)(\mathbf{i},\pi(\mathbf{j}^{1}))\sim(\mathbf{i}^{1},\mathbf{j}^{1}), and thus (i,π(j1))∈μ(\mathbf{i},\pi(\mathbf{j}^{1}))\in\mu. Therefore, for all i∈γl\mathbf{i}\in\gamma^{l}, by setting j=π(j1)\mathbf{j}=\pi(\mathbf{j}^{1}) we can always obtain (i,j)∈μ(\mathbf{i},\mathbf{j})\in\mu.

(⇐\Leftarrow) For all (i,j)∈μ(\mathbf{i},\mathbf{j})\in\mu, as (i,j)∼(i1,j1)(\mathbf{i},\mathbf{j})\sim(\mathbf{i}^{1},\mathbf{j}^{1}), there exists some π∈Sn\pi\in S_{n} such that (i,j)=π(i1,j1)(\mathbf{i},\mathbf{j})=\pi(\mathbf{i}^{1},\mathbf{j}^{1}). This gives i=π(i1)\mathbf{i}=\pi(\mathbf{i}^{1}) and j=π(j1)\mathbf{j}=\pi(\mathbf{j}^{1}), leading to i∼i1\mathbf{i}\sim\mathbf{i}^{1} and therefore i∈γl\mathbf{i}\in\gamma^{l}. ∎

Lemma 2 states that the equivalence classes γl\gamma^{l} of i\mathbf{i} and γk\gamma^{k} of j\mathbf{j} are identical for all (i,j)∈μ(\mathbf{i},\mathbf{j})\in\mu. Based on this, we appropriately break down the test (i,j)∈μ(\mathbf{i},\mathbf{j})\in\mu into a combination of several simpler tests, in particular including i∈γl\mathbf{i}\in\gamma^{l} and j∈γk\mathbf{j}\in\gamma^{k}:

For a given order-(l+k)(l+k) equivalence class μ\mu, let γl\gamma^{l} and γk\gamma^{k} be equivalence classes of some i1∈[n]l,j1∈[n]k\mathbf{i}^{1}\in[n]^{l},\mathbf{j}^{1}\in[n]^{k} respectively that satisfies (i1,j1)∈μ(\mathbf{i}^{1},\mathbf{j}^{1})\in\mu. Then, for any i∈[n]l\mathbf{i}\in[n]^{l} and j∈[n]k\mathbf{j}\in[n]^{k}, (i,j)∈μ(\mathbf{i},\mathbf{j})\in\mu holds if and only if the following conditions both hold:

i∈γl\mathbf{i}\in\gamma^{l} and j∈γk\mathbf{j}\in\gamma^{k}

ia=jb⇔ia2=jb2\mathbf{i}_{a}=\mathbf{j}_{b}\Leftrightarrow\mathbf{i}^{2}_{a}=\mathbf{j}^{2}_{b} for all a∈[l]a\in[l], b∈[k]b\in[k], and (i2,j2)∈μ(\mathbf{i}^{2},\mathbf{j}^{2})\in\mu

(⇒\Rightarrow) If (i,j)∈μ(\mathbf{i},\mathbf{j})\in\mu, from Lemma 2 it follows that i∈γl\mathbf{i}\in\gamma^{l} and j∈γk\mathbf{j}\in\gamma^{k}. Also, as all (i2,j2)∈μ(\mathbf{i}^{2},\mathbf{j}^{2})\in\mu including (i,j)(\mathbf{i},\mathbf{j}) have the same equality pattern, it follows that for all a∈[l]a\in[l], b∈[k]b\in[k], and (i2,j2)∈μ(\mathbf{i}^{2},\mathbf{j}^{2})\in\mu, if ia2=jb2\mathbf{i}^{2}_{a}=\mathbf{j}^{2}_{b} then ia=jb\mathbf{i}_{a}=\mathbf{j}_{b} and if ia2≠jb2\mathbf{i}^{2}_{a}\neq\mathbf{j}^{2}_{b} then ia≠jb\mathbf{i}_{a}\neq\mathbf{j}_{b}.

(⇐\Leftarrow) We show that the conditions specify that the equivalence class of (i,j)(\mathbf{i},\mathbf{j}) is μ\mu.

For this, it is convenient to represent an order-ll equivalence class γ\gamma as an equivalent undirected graph G=(V,E)\mathcal{G}=(\mathcal{V},\mathcal{E}) defined on vertex set V={v1,...,vl}\mathcal{V}=\{v_{1},...,v_{l}\} where the vertices vav_{a} and vbv_{b} are connected, i.e., (va,vb)∈E(v_{a},v_{b})\in\mathcal{E} if and only if the equivalence class γ\gamma specifies ia=ib∀i∈γ\mathbf{i}_{a}=\mathbf{i}_{b}\forall\mathbf{i}\in\gamma. Then, for some multi-index i′∈[n]l\mathbf{i}^{\prime}\in[n]^{l}, the inclusion i′∈γ\mathbf{i}^{\prime}\in\gamma holds if and only if the equivalence class of i′\mathbf{i}^{\prime} is represented as G\mathcal{G}.

Given this, let us represent the equivalence classes γl\gamma^{l}, γk\gamma^{k}, and μ\mu as graphs Gl\mathcal{G}^{l}, Gk\mathcal{G}^{k}, and Gμ\mathcal{G}^{\mu} respectively:

From the precondition that γl\gamma^{l} and γk\gamma^{k} are equivalence classes of i1∈[n]l,j1∈[n]k\mathbf{i}^{1}\in[n]^{l},\mathbf{j}^{1}\in[n]^{k} that satisfies (i1,j1)∈μ(\mathbf{i}^{1},\mathbf{j}^{1})\in\mu, we can see that (va,vb)∈El⇔(va,vb)∈Eμ(v_{a},v_{b})\in\mathcal{E}^{l}\Leftrightarrow(v_{a},v_{b})\in\mathcal{E}^{\mu} and (ua,ub)∈Ek⇔(ua,ub)∈Eμ(u_{a},u_{b})\in\mathcal{E}^{k}\Leftrightarrow(u_{a},u_{b})\in\mathcal{E}^{\mu}. That is, if we consider Vl\mathcal{V}^{l} and Vk\mathcal{V}^{k} as a graph cut of Gμ\mathcal{G}^{\mu} and write the cut-set (edges between Vl\mathcal{V}^{l} and Vk\mathcal{V}^{k}) as EC={(va,ub)∣(va,ub)∈Eμ}\mathcal{E}^{C}=\{(v_{a},u_{b})|(v_{a},u_{b})\in\mathcal{E}^{\mu}\}, we obtain a partition {El,Ek,EC}\{\mathcal{E}^{l},\mathcal{E}^{k},\mathcal{E}^{C}\} of the edge set Eμ\mathcal{E}^{\mu}.

Let us assume the first condition that i∈γl\mathbf{i}\in\gamma^{l} and j∈γk\mathbf{j}\in\gamma^{k}, with the equivalence classes represented as Gl\mathcal{G}^{l} and Gk\mathcal{G}^{k}, respectively. Now, let us consider the equivalence class of (i,j)(\mathbf{i},\mathbf{j}) represented by (unknown) graph G=(V,E)\mathcal{G}=(\mathcal{V},\mathcal{E}). Considering Vk\mathcal{V}^{k} and Vl\mathcal{V}^{l} as a graph cut of G\mathcal{G}, we can see that E\mathcal{E} is partitioned as {El,Ek,ED}\{\mathcal{E}^{l},\mathcal{E}^{k},\mathcal{E}^{D}\} where ED\mathcal{E}^{D} is the cut-set (edges between Vl\mathcal{V}^{l} and Vk\mathcal{V}^{k}).

Let us also assume the second condition ia=jb⇔ia2=jb2\mathbf{i}_{a}=\mathbf{j}_{b}\Leftrightarrow\mathbf{i}^{2}_{a}=\mathbf{j}^{2}_{b} for all a∈[l]a\in[l], b∈[k]b\in[k], and (i2,j2)∈μ(\mathbf{i}^{2},\mathbf{j}^{2})\in\mu. This directly implies that e∈EC⇔e∈EDe\in\mathcal{E}^{C}\Leftrightarrow e\in\mathcal{E}^{D}, meaning that EC=ED\mathcal{E}^{C}=\mathcal{E}^{D}. As a result, we see that G\mathcal{G} and Gμ\mathcal{G}^{\mu} are identical graphs, and therefore the equivalence class of (i,j)(\mathbf{i},\mathbf{j}) is μ\mu and (i,j)∈μ(\mathbf{i},\mathbf{j})\in\mu holds.

In Figure 4, we provide an exemplary illustration of testing (i,j)∈μ(\mathbf{i},\mathbf{j})\in\mu following the above discussion. ∎

With Lemma 3, we have a decomposition of (i,j)∈μ(\mathbf{i},\mathbf{j})\in\mu into independent conditions on i\mathbf{i} and j\mathbf{j} combined with pairwise conditions between i\mathbf{i} and j\mathbf{j}. In the following Definition 5 and Property 1, we encode these tests into a single scoring function that can be later implemented by self-attention.

A scoring function δ(i,j;μ,ϵ)\delta(\mathbf{i},\mathbf{j};\mu,\epsilon) is a map that, given an order-(l+k)(l+k) equivalence class μ\mu and ϵ>0\epsilon>0, takes multi-indices i∈[n]l,j∈[n]k\mathbf{i}\in[n]^{l},\mathbf{j}\in[n]^{k} and gives the following:

An important property of the scoring function δ(i,j;μ)\delta(\mathbf{i},\mathbf{j};\mu) is that it gives the maximum possible value if and only if the input satisfies (i,j)∈μ(\mathbf{i},\mathbf{j})\in\mu, as shown in the below Property 1.

For given order-(l+k)(l+k) equivalence class μ\mu and positive real number ϵ>0\epsilon>0, for any i∈[n]l\mathbf{i}\in[n]^{l} and j∈[n]k\mathbf{j}\in[n]^{k}, (i,j)∈μ(\mathbf{i},\mathbf{j})\in\mu holds if and only if the scoring function δ(i,j;μ,ϵ)\delta(\mathbf{i},\mathbf{j};\mu,\epsilon) (Eq. (19)) outputs the maximum possible value.

As shown in Lemma 3, (i,j)∈μ(\mathbf{i},\mathbf{j})\in\mu holds if and only if the following two conditions are met.

i∈γl\mathbf{i}\in\gamma^{l} and j∈γk\mathbf{j}\in\gamma^{k}

ia=jb⇔ia2=jb2\mathbf{i}_{a}=\mathbf{j}_{b}\Leftrightarrow\mathbf{i}^{2}_{a}=\mathbf{j}^{2}_{b} for all a∈[l]a\in[l], b∈[k]b\in[k], and (i2,j2)∈μ(\mathbf{i}^{2},\mathbf{j}^{2})\in\mu

Thus, the scoring function δ(i,j;μ,ϵ)\delta(\mathbf{i},\mathbf{j};\mu,\epsilon) gives the maximum possible output if and only if (i,j)∈μ(\mathbf{i},\mathbf{j})\in\mu. ∎

We now use self-attention on Xinwin\mathbf{X}^{in}w^{in} to perform an accurate approximation of the equivariant basis. Specifically, we use each self-attention matrix αh\boldsymbol{\alpha}^{h} (Eq. (7)) to approximate each basis tensor Bμh\mathbf{B}^{\mu_{h}} of Lk→kL_{k\to k} (Eq. (2)) to arbitrary precision up to normalization.

where a>0a>0 is a positive real, I\mathbf{I} is an identity matrix, and sgn(⋅,⋅)\textnormal{sgn}(\cdot,\cdot) is the sign function defined in Eq. (23) (Definition 5). In Figure 5 we provide an illustration of the query and key weights whQ,whKw_{h}^{Q},w_{h}^{K}.

With the parameters, i\mathbf{i}-th query and j\mathbf{j}-th key entries are computed as follows:

Then, scaled pairwise dot product of query and key is given as follows:

We now let the type identifiers Eγ1,...,Eγbell(k)\mathbf{E}^{\gamma_{1}},...,\mathbf{E}^{\gamma_{\textnormal{bell}(k)}} be radially equispaced unit vectors on any two-dimensional subspace (Figure 6). This guarantees that any pair of type identifiers Eγ1,Eγ2\mathbf{E}^{\gamma_{1}},\mathbf{E}^{\gamma_{2}} with γ1≠γ2\gamma_{1}\neq\gamma_{2} have dot product (Eγ1)⊤Eγ2≤cos⁡(2π/bell(k))(\mathbf{E}^{\gamma_{1}})^{\top}\mathbf{E}^{\gamma_{2}}\leq\cos{\left(2\pi/\textnormal{bell}(k)\right)}. By setting ϵ=1−cos⁡(2π/bell(k))>0\epsilon=1-\cos{\left(2\pi/\textnormal{bell}(k)\right)}>0, this can be equivalently written as (Eγ1)⊤Eγ2≤1−ϵ(\mathbf{E}^{\gamma_{1}})^{\top}\mathbf{E}^{\gamma_{2}}\leq 1-\epsilon. We additionally note that (Eγi)⊤EγQ=1(\mathbf{E}^{\gamma^{\mathbf{i}}})^{\top}\mathbf{E}^{\gamma^{Q}}=1 if and only if i∈γQ\mathbf{i}\in\gamma^{Q} because γi=γQ⇔i∈γQ\gamma^{\mathbf{i}}=\gamma^{Q}\Leftrightarrow\mathbf{i}\in\gamma^{Q}.

Combining the above, Eq. (52), and Eq. (19), we have the following:

where ϵ=1−cos⁡(2π/bell(k))\epsilon=1-\cos{\left(2\pi/\textnormal{bell}(k)\right)} and δ(i,j;μ,ϵ)\delta(\mathbf{i},\mathbf{j};\mu,\epsilon) is the scoring function in Eq. (19) (Definition 5).

Thus, as shown in Eq. (55), the attention coefficient αh\boldsymbol{\alpha}^{h} can arbitrarily accurately approximate the normalized basis tensor Bμ\mathbf{B}^{\mu} for given equivalence class μ\mu. ∎

A.1.3 Proof of Theorem 1 (Section 3.3)

We continue from the proof of Lemma 1 and assume that each attention matrix α1,...,αbell(2k)\boldsymbol{\alpha}^{1},...,\boldsymbol{\alpha}^{\textnormal{bell}(2k)} in Eq. (7) head-wise approximates each normalized basis tensor Bμ1,...,Bμbell(2k)\mathbf{B}^{\mu_{1}},...,\mathbf{B}^{\mu_{\textnormal{bell}(2k)}} respectively, i.e., αi,jh=Bi,jμh/∑jBi,jμh\boldsymbol{\alpha}_{\mathbf{i},\mathbf{j}}^{h}=\mathbf{B}^{\mu_{h}}_{\mathbf{i},\mathbf{j}}/\sum_{\mathbf{j}}\mathbf{B}^{\mu_{h}}_{\mathbf{i},\mathbf{j}}. we handle the case ∑jBi,jμh=0\sum_{\mathbf{j}}\mathbf{B}^{\mu_{h}}_{\mathbf{i},\mathbf{j}}=0 later separately as mentioned in footnote 1.

Then, output projection applied after value projection of each i\mathbf{i}-th input entry gives the following:

Based on the results, we compute the MSA with skip connection H=X′+MSA(X′)\mathbf{H}=\mathbf{X}^{\prime}+\textnormal{MSA}(\mathbf{X}^{\prime}) (Eq. (9)):

where J=(d+kdp+de)+(h−1)dJ=(d+kd_{p}+d_{e})+(h-1)d, and bγ1,...,bγbell(k)b_{\gamma_{1}},...,b_{\gamma_{\textnormal{bell}(k)}} are biases of the given equivariant linear layer Lk→kL_{k\to k} with corresponding basis tensors Cγ1,...,Cγbell(k)\mathbf{C}^{\gamma_{1}},...,\mathbf{C}^{\gamma_{\textnormal{bell}(k)}} (Eq. (2)).

Based on the results, we compute the feedforward MLP with skip connection T(X′)=H+MLP(H)\mathcal{T}(\mathbf{X}^{\prime})=\mathbf{H}+\textnormal{MLP}(\mathbf{H}) (Eq. (10)), which is the output of Transformer layer T\mathcal{T}:

In conclusion, a Transformer layer with bell(2k)\textnormal{bell}(2k) self-attention heads that operates on augmented X′\mathbf{X}^{\prime} can approximate any given Lk→k(X)L_{k\to k}(\mathbf{X}) to arbitrary precision. ∎

A.1.4 Proof of Theorem 2 (Section 3.3)

We continue from the proof of Theorem 1, and assume that each Transformer layer T\mathcal{T} can approximate a given Lk→kL_{k\to k} by only updating the first dd channels.

Then, based on Theorem 1 we assume the following for each t<Tt<T:

where Xi′=[Xi,Pi1,...,Pik,Eγi,06]\mathbf{X}^{\prime}_{\mathbf{i}}=[\mathbf{X}_{\mathbf{i}},\mathbf{P}_{i_{1}},...,\mathbf{P}_{i_{k}},\mathbf{E}^{\gamma^{\mathbf{i}}},\mathbf{0}_{6}]. While Theorem 1 gives Lk→k(t)(X)L_{k\to k}^{(t)}(\mathbf{X}) in the first dd channels, we add elementwise activation σ(⋅)\sigma(\cdot) by absorbing it into the elementwise MLP in Eq. (66). Then, leveraging the property that each Transformer layer T(t)\mathcal{T}^{(t)} only updates the first dd channels, we stack T−1T-1 Transformer layers T(1)\mathcal{T}^{(1)}, …, T(T−1)\mathcal{T}^{(T-1)} and obtain the following:

For the last layer T(T)\mathcal{T}^{(T)}, we follow the procedure in the proof of Theorem 1 to approximate Lk→k(T)L_{k\to k}^{(T)}, but slightly tweak Eq. (66) so that elementwise MLP copies each output entry Lk→k(X)i(T)L_{k\to k}(\mathbf{X})^{(T)}_{\mathbf{i}} in appropriate reserved channels. Specifically, we let the elementwise MLP approximate following f′f^{\prime}:

where D=(d+kdp+de)D=(d+kd_{p}+d_{e}) and we abbreviate Fi,j=∑h∈[bell(2k)]g(Hi)hHi,j+J+b(Hi)j\mathbf{F}_{\mathbf{i},j}=\sum_{h\in[\textnormal{bell}(2k)]}{g(\mathbf{H}_{\mathbf{i}})_{h}\mathbf{H}_{\mathbf{i},j+J}}+b(\mathbf{H}_{\mathbf{i}})_{j} with J,g,bJ,g,b defined as same as in Eq. (66). Recall that Ciγa=1\mathbf{C}^{\gamma_{a}}_{\mathbf{i}}=1 if and only if i∈γa\mathbf{i}\in\gamma_{a}. Therefore, with Eq. (78), we are simply duplicating each output entry Fi=Lk→k(T)(X)i\mathbf{F}_{\mathbf{i}}=L_{k\to k}^{(T)}(\mathbf{X})_{\mathbf{i}} to spare channel indices reserved for the equivalence class of i\mathbf{i} (γa\gamma_{a} that i∈γa\mathbf{i}\in\gamma_{a}).

With the choice of T(T)\mathcal{T}^{(T)}, the layer output T(T)(X′)=H+MLP(H)\mathcal{T}^{(T)}(\mathbf{X}^{\prime})=\mathbf{H}+\textnormal{MLP}(\mathbf{H}) (Eq. (10)) is computed as:

Then, by applying T(T)\mathcal{T}^{(T)} (Eq. (81)) on top of T(T−1)∘...∘T(1)\mathcal{T}^{(T-1)}\circ...\circ\mathcal{T}^{(1)} (Eq. (74)), we obtain the following:

where we abbreviate Y=Lk→k(T)∘σ∘...∘σ∘Lk→k(1)(X)\mathbf{Y}=L_{k\to k}^{(T)}\circ\sigma\circ...\circ\sigma\circ L_{k\to k}^{(1)}(\mathbf{X}).

The remaining step is to utilize MLP∘sumpool\textnormal{MLP}\circ\textnormal{sumpool} to approximate MLPk∘Lk→0\textnormal{MLP}_{k}\circ L_{k\to 0} that tops FkF_{k}. By sum-pooling over all indices i\mathbf{i}, we obtain the following:

where the last equality comes from Definition 1.

Taken together, we arrive at the conclusion that MLP∘sumpool∘T(T)∘...∘T(1)(X′)\textnormal{MLP}\circ\textnormal{sumpool}\circ\mathcal{T}^{(T)}\circ...\circ\mathcal{T}^{(1)}(\mathbf{X}^{\prime}) can approximate Fk(X)F_{k}(\mathbf{X}) to arbitrary precision. ∎

A.2 Additional Discussion on Linear Attention for Graph Transformers (Section 4)

Unfortunately, this modification immediately precludes the adaptation of many efficient attention techniques developed for pure self-attention. As representative examples, we take Performer , Linear Transformer , Efficient Transformer , and Random Feature Attention . The methods are based on kernelization of the Att(⋅)\text{Att}(\cdot) operator as the following:

While above discussion regards kernelization, a wide range of other efficient Transformers, including Set Transformer , LUNA , Linformer , Nyströmformer , Perceiver , and Perceiver-IO are not applicable to Graphormer due to similar reasons.

A.3 Experimental Details (Section 5)

We provide detailed information on the datasets and models used in our experiments in Section 5. Dataset statistics can be found in Table 3.

For type identifiers E\mathbf{E}, we set ded_{e} equal to the hidden dimension dd of the main encoder de=dd_{e}=d and initialize and train them jointly with the model.

For orthonormal node identifiers P\mathbf{P}, we use normalized orthogonal random features (ORFs) or Laplacian eigenvectors obtained as follows:

As the Laplacian eigenvectors are defined up to the factor ±1\pm 1 after normalized to unit length , we randomly flip their signs during training. For PCQM4Mv2 (Section 5.2), we apply random dropout on eigenvectors during training, similar to 2D channel dropout in ConvNets . In our experiments with PCQM4Mv2, we find that both sign flip and eigenvector dropout work as effective regularizers and improves performance on validation data.

A.3.2 Second-Order Equivariant Basis Approximation (Section 5.1)

For the equivariant basis approximation experiment, we use a synthetic dataset containing Barabási-Albert (BA) random graphs . With U\mathcal{U} denoting discrete uniform distribution, each graph is generated by first sampling the number of nodes n∼U(10,20)n\sim\mathcal{U}(10,20) and the number for preferential attachment k∼U(2,3)k\sim\mathcal{U}(2,3), then iteratively adding nn nodes by linking each new node to kk random previous nodes. We do not utilize node or edge attributes and only use edge connectivity. We generate 1152 graphs for training and 128 for testing. Further dataset statistics is provided in Table 3(a).

Each model tested in Table LABEL:table:equivariant_basis_approximation_std is a single multihead self-attention layer (Eq. (9)) with hidden dimension d=1024d=1024, heads H=bell(2+2)=15H=\textnormal{bell}(2+2)=15, and head dimension dH=128d_{H}=128. As for the node identifier dimension, we use dp=24d_{p}=24 for ORF and dp=20d_{p}=20 for Laplacian eigenvectors.

We train and evaluate all models with L2 loss between attention matrix αh\boldsymbol{\alpha}^{h} and normalized basis tensor Bμh\mathbf{B}^{\mu_{h}} (involving [null] token) averaged over heads h=1,...,15h=1,...,15. We train all models with AdamW optimizer on 4 RTX 3090 GPUs each with 24GB. For sparse inputs we use batch size 512, and for dense inputs we use batch size 256 due to increased memory cost. We train all models for 3k steps (which takes about ∼\sim1.5 hours) and apply linear learning rate warmup for 1k steps up to 1e-4 followed by linear decay to 0. For all models, we use dropout rate of 0.1 on the input [X[null];Xinwin][\mathbf{X}_{\texttt{[null]}};\mathbf{X}^{in}w^{in}] to prevent overfitting.

A.3.3 Large-Scale Graph Learning (Section 5.2)

For large-scale learning, we use the PCQM4Mv2 quantum chemistry regression dataset from the OGB-LSC benchmark that contains 3.7M molecular graphs. Along with graph structure, we utilize both node and edge features e.g., atom and bond types following our standard procedure in Section 2. Dataset statistics is provided in Table 3(b).

All our models in Table LABEL:table:pcqm4mv2 (under Pure Transformers) have the same encoder configuration following Graphormer , with 12 layers, hidden dimension d=768d=768, heads H=32H=32, and head dimension dH=24d_{H}=24. We adopt PreLN that places layer normalization before MSA layer (Eq. (9)), MLP layer (Eq. (10)), and the final output projection after the last encoder layer. We implement MLP (Eq. (10)) as a stack of two linear layers with GeLU nonlinearity in between. As for node identifier dimension, we use dp=64d_{p}=64 for ORF and dp=16d_{p}=16 for Laplacian eigenvectors.

As an additional GNN baseline, we run Graph Attention Network (GATv2) under several configurations. For GAT and GAT-VN in Table LABEL:table:pcqm4mv2, we use 5-layer GATv2 with hidden dimension 600 and a single attention head, having 6.7M parameters in total. For GAT-VN (large), we use a 10-layer GATv2 with hidden dimension 1200 and a single attention head, having 55.2M parameters in total. For GAT-VN and GAT-VN (large), we use virtual node that helps modeling global interaction .

We mainly report and compare the Mean Absolute Error (MAE) on the validation data, and report MAE on the hidden test data if possible. We train all models with L1 loss using AdamW optimizer with gradient clipping at global norm 5.0. We use batch size 1024 and train the models on 8 RTX 3090 GPUs with 24GB for ∼\sim3 days. We train our models for 1M iterations, and apply linear lr warmup for 60k iterations up to 2e-4 followed by linear decay to 0. For our models in Table LABEL:table:pcqm4mv2 except TokenGT (Lap) + Performer, we use the following regularizers:

Stochastic depth with linearly increasing layer drop rate, reaching 0.1 at last layer

Eigenvector dropout rate 0.2 for TokenGT (Lap) (see Appendix A.3.1)

For TokenGT (Lap) + Performer in Table LABEL:table:pcqm4mv2, we load a trained model checkpoint of TokenGT (Lap), change its self-attention to FAVOR+ kernelized attention of Performer that can provably accurately approximate softmax attention, and fine-tune it with AdamW optimizer for 0.1M training steps with 1k warmup iterations and cosine learning rate decay. With batch size 1024 on 8 RTX 3090 GPUs, fine-tuning takes ∼12\sim 12 hours. We do not use stochastic depth and eigenvector dropout for fine-tuning. For GAT baselines in Table LABEL:table:pcqm4mv2, we use batch size 256 and train the models for 100 epochs with initial learning rate 0.001 decayed with a factor of 0.25 every 30 epochs.

A.4 Additional Experimental Results (Section 5)

We report additional experimental results and discussions that could not be included in the main text due to space restriction.

In addition to the Figure 2 in the main text that shows learned self-attention maps for dense input, in Figure 7, we provide an extended visualization of self-attention maps for both dense and sparse inputs. Consistent to Lemma 1 and Table LABEL:table:equivariant_basis_approximation_std, self-attention achieves accurate approximation of equivariant basis only when both the orthonormal node identifiers (ORF or Lap) and type identifiers are given.

A.4.2 Large-Scale Graph Learning (Section 5.2)

In addition to the Figure 3 in the main text that shows attention distance measured for the PCQM4Mv2 validation data, in Figure 8, we provide an extended figure of attention distance measured for the entire training set that contains ∼\sim3M graphs. Overall we find similar trends as analyzed in Section 5.2.

A.4.3 Transductive Node Classification on Large Graphs (Section 5)

While our main experiment in Section 5.2 focuses on graph-level predictions, TokenGT can in principle be applied to a more broad class of node-level or edge-level graph understanding tasks by putting prediction head on appropriate output tokens. To demonstrate this, we conduct additional experiments on a variety of transductive node classification datasets. In contrast to PCQM4Mv2, they involve large graphs with up to tens of thousands of nodes, posing a challenge to O(n2)\mathcal{O}(n^{2}) complexity methods such as graph Transformers that rely on dense attention bias.

We use transductive node classification datasets, where each data is represented as a node in a large-scale graph, including co-authorship (CS, Physics) , co-purchase (Photo, Computers) , and Wikipedia page networks (Chameleon, Crocodile) . We randomly split the dataset into train, validation, and test sets by randomly reserving 30 random nodes per class for validation and test respectively, and use the rest of the nodes for training. Dataset statistics is provided in Table 4.

We utilize simple variants of TokenGT with Performer kernel attention of O(n+m)\mathcal{O}(n+m) complexity. Due to the large number of nodes nn, an immediate challenge for TokenGT is dealing with the orthonormality assumption on the node identifiers (Lemma 1) as the maximal number of orthonormal node identifiers is bounded by dimension dpd_{p}. In this case, it is reasonable to introduce near-orthonormal vectors as node identifiers, as it is theoretically guaranteed that we can draw an exponential number O(eΩ(dp))\mathcal{O}(e^{\Omega(d_{p})}) of dpd_{p}-dimensional near-orthonormal vectors . For TokenGT (Near-ORF), we use dp=64d_{p}=64-dimensional random node identifiers where each entry is sampled from {−1/dp,+1/dp}\{-1/d_{p},+1/d_{p}\} with coin toss . For TokenGT (Lap), we use a subset of the Laplacian eigenvectors as node identifiers, specifically dp/2d_{p}/2 eigenvectors with lowest eigenvalues and dp/2d_{p}/2 eigenvectors with highest eigenvalues, and choose dpd_{p} among 6464-100100 based on validation performance.

While Near-ORF and Lap can theoretically serve as an efficient low-rank approximation for orthonormal node identifiers, their approximation can affect the quality of modeled equivariant basis (Section 3). In particular, equivariant basis (μ\mu) represented as sparse basis tensor (Bμ\mathbf{B}^{\mu}; Definition 4) are expected to be affected more, as they require most entries to be zero. To remedy this, we take a simple approach of residually adding one of such sparse equivariant operators Xii↦Xii+∑j≠iXij\mathbf{X}_{ii}\mapsto\mathbf{X}_{ii}+\sum_{j\neq i}\mathbf{X}_{ij} explicitly after each Transformer layer. We denote this variant as TokenGT (Lap) + Performer + SEB, where SEB abbreviates sparse equivariant basis. This fix is minimal, easy to implement, and highly efficient as it only requires a single torch.coalesce() call, and also empirically effective.

All our models in Table LABEL:table:transductive_node_classification utilize a linear prediction head on the node tokens obtained at the final Transformer layer to perform node-level classification. We perform an exploratory hyperparameter search over the number of layers from 22-44, heads HH from 11-44, hidden dimension dd from 128128-10241024, and dropout rate from {0.1,0.5}\{0.1,0.5\}, based on validation performance.

We employ strong message-passing GNN and graph Transformer baselines, including GCN , GAT , GIN which has 2-WL expressiveness similar to ours, and Graphormer based on fully-connected node self-attention. For message-passing GNNs, we use a 4-layer architecture and search hidden dimension dd from {64,1024}\{64,1024\} based on validation performance. For Graphormer, we perform an exploratory search on the number of layers from 11-44, heads HH from 11-44, and hidden dimension dd from 128128-10241024 based on validation performance. We apply 0.5 dropout for all baselines.

We report and compare classification accuracy on the test nodes at best validation accuracy aggregated over 7 randomized runs. We train all models with node-level categorical cross-entropy loss using Adam optimizer on a single RTX 3090 GPU with 24GB. We train all models with a learning rate of 1e-3 for 300 epochs.

The results are in Table LABEL:table:transductive_node_classification. Graphormer suffers out-of-memory in the Physics dataset mainly due to the spatial encoding that requires O(n2)\mathcal{O}(n^{2}) memory. By constraining the model capacity appropriately, we were able to run Graphormer on other datasets. However, we observe a low performance, presumably due to the memory cost that prevents depth and head scaling. As the spatial encoding is incorporated into the model via attention bias, the model strictly requires O(n2)\mathcal{O}(n^{2}) memory and cannot be easily made more efficient. On the other hand, TokenGT variants are able to utilize Performer attention with O(m+n)\mathcal{O}(m+n) cost, which allows using larger models to achieve the best performance in all but one dataset (Computers, where the performance is on par with the best model).

A.5 Additional Discussion on Performance on PCQM4Mv2 (Section 5.2)

As in the Table LABEL:table:pcqm4mv2 in the main text, TokenGT currently shows a slightly lower performance compared to the Graphormer and its successors in the PCQM4Mv2 benchmark. We conjecture this is partly because we intentionally keep its components simple to faithfully adhere to the equivariance theory. We discuss some engineering approaches that may enhance the performance of TokenGT at the cost of differentiating from the theory. We consider engineering TokenGT to match or outperform sophisticated graph Transformers as a promising and important next research direction.

Our best performing TokenGT (Lap) currently uses Laplacian eigenvectors as the node identifiers, which has been criticized for issues such as loss of structural information and sign ambiguity . Thus, one could try to relax the theoretical requirement for orthonormality of node identifiers and incorporate more powerful node positional encodings as node identifiers, which could potentially yield better performance in practice.

TokenGT currently treats an undirected input edge (u,v)(u,v) as if both directions (u,v)(u,v) and (v,u)(v,u) are present, leading to a pair of edge tokens [X(u,v),Pu,Pv][\mathbf{X}_{(u,v)},\mathbf{P}_{u},\mathbf{P}_{v}] and [X(v,u),Pv,Pu][\mathbf{X}_{(v,u)},\mathbf{P}_{v},\mathbf{P}_{u}]. Similarly, an undirected order-kk input hyperedge (v1,...,vk)(v_{1},...,v_{k}) of an higher-order hypergraph is parsed to all possible orderings of node identifiers. While this is a common characteristic of tensor-based permutation equivariant neural networks , they can lead to memory overhead and redundancy since multiple tokens represent an identical undirected edge. To avoid this, one can use a single token for each undirected (hyper)edge and pool the node identifiers as ∑i=1kρ(Pvi)\sum_{i=1}^{k}\rho(\mathbf{P}_{v_{i}}). Combined with powerful node identifiers, this approach could potentially enhance the model performance.