Graph Transformers Dream of Electric Flow

## Abstract

Abstract We show theoretically and empirically that the linear Transformer, when applied to graph data, can implement algorithms that solve canonical problems such as electric flow and eigenvector decomposition. The input to the Transformer is simply the graph incidence matrix; no other explicit positional encoding information is provided. We present explicit weight configurations for implementing each such graph algorithm, and we bound the errors of the constructed Transformers by the errors of the underlying algorithms. Our theoretical findings are corroborated by experiments on synthetic data. Additionally, on a real-world molecular regression task, we observe that the linear Transformer is capable of learning a more effective positional encoding than the default one based on Laplacian eigenvectors. Our work is an initial step towards elucidating the inner-workings of the Transformer for graph data.

## 1 Introduction

The Transformer architecture (Vaswani et al., ) has
seen great success in the design of graph neural networks (GNNs) (Dwivedi and Bresson, ; Ying et al., ; Kim et al., ; Muller et al., ), and it has demonstrated impressive performance in many applications ranging from prediction of chemical properties to analyzing social networks (Yun et al., ; Dwivedi et al., ; Rong et al., ). In contrast to this empirical success, the underlying reasons for *why* Transformers adapt well to graph problems are less understood. Several works study the *expressivity* of attention-based architectures (Kreuzer et al., ; Kim et al., , ; Ma et al., ), but such analyses often rely on the ability of neural networks to approximate arbitrary functions, and may require a prohibitive number of parameters.

This paper is motivated by the need to understand, at a mechanistic level, how the Transformer processes graph-structured data. Specifically, we study the ability of a *linear Transformer* to solve certain classes of graph problems. The linear Transformer is similar to the standard Transformer, but softmax-based activation is replaced with linear attention, and the MLP layers are replaced by linear layers. Notably, the linear Transformer contains no a priori knowledge of the graph structure; all information about the graph is provided via an *incidence matrix* $B$. For unweighted graphs, the columns of $B$ are just $\left\{-1,0,1\right\}$-valued indicator vectors that encode whether an edge touches a vertex; no other explicit positional or structural encodings are provided.

Even in this minimal setup, we are able to design *simple* configurations of the weight matrices of a Transformer that enable it to solve fundamental problems such as electric flow and Laplacian eigenvector decomposition. Furthermore, we provide explicit error bounds that scale well with the number of Transformer layers. Several of our constructions rely crucially on the structure of the linear attention module, and may help shed light on the success of attention-based GNNs. We hope that our analysis paves the way to a better understanding of the learning landscape of graph Transformers, such as concrete bounds on their generalization and optimization errors.

Besides enhancing our understanding of Transformers, our results are also useful for the practical design of graph Transformers. In Sections 3 and 4, we show that essentially the same linear Transformer architecture is capable of learning a number of popular positional encodings (PE). In Section 6, we provide experimental evidence that the linear Transformer can learn better PEs than hard-coded PEs.

### 1.1 Summary of Contributions

Below, we summarize the main content of our paper.

- 1.
We provide explicit weight configurations for which the Transformer *implements efficient algorithms for several fundamental graph problems*. These problems serve as important primitives in various graph learning algorithms, and have also been useful as PEs in state-of-the-art GNNs.
(a)
Lemma 1 constructs a Transformer that solves electric flows by *implementing steps of gradient descent to minimize flow energy*; consequently, it can also invert the graph Laplacian.
(b)
Lemmas 2 and 3 construct Transformers that compute low-dimensional resistive embeddings and heat kernels. Both constructions are based on implementing suitable power series.
(c)
By implementing a *multiplicative polynomial expansion*, Lemma 4 provides a construction for electric flow with exponentially higher accuracy than Lemma 1. Similarly, Lemma 5 provides a construction that computes the heat kernel using much fewer layers than Lemma 3.
(d)
In Lemma 6, we show that the *Transformer can implement subspace iteration for finding the top-$k$ (or bottom-$k$) eigenvectors of the graph Laplacian*. Central to this analysis is the ability of self-attention to compute a QR decomposition of the feature vectors.
We derive explicit error bounds for the Transformer based on the convergence rates of the underlying algorithm implemented by the Transformer. We summarize these results in Table 1.
- 2.
In Section 5, we provide a more efficient, constrained version of the linear Transformer with much fewer parameters. Although the constrained Transformer is less expressive by definition, we show that it can nonetheless implement all the above-mentioned constructions. Further, we show in Lemma 10 that the parameter-efficient linear Transformer has desirable invariance and equivariance properties.
- 3.
We test the empirical performance of our theory on synthetic random graphs. In Section 3.5, we verify that Transformers with a few layers can achieve high accuracy in computing electric flows, resistive embeddings, as well as heat kernels. In Section 4.1, we verify that the Transformer can accurately compute top-$k$ and bottom-$k$ eigenevectors of the graph Laplacian.
- 4.
In Section 6, we demonstrate the advantage of using the linear Transformer as a replacement for Laplacian eigenvector positional encoding on a molecular regression benchmark using the QM9 and ZINC datasets (Ruddigkeit et al., ; Ramakrishnan et al., ; Irwin et al., ). After replacing the Laplacian eigenvector-based PE with the linear Transformer, and training on the regression loss, we verify that the linear Transformer *automatically learns a good PE* for the downstream regression task that can outperform the original Laplacian eigenvector-based PE by a wide margin.

**Table 1: Summary of Error Bounds proved for various Transformer constructions. ${\mathcal{L}}$ is the graph Laplacian, ${\mathcal{L}}^{\dagger}$ denotes its pseudoinverse.**
| Lemma | Task | Transformer Implements: | # layers for $\varepsilon$ error |
| --- | --- | --- | --- |
| 1 | Electric Flow (${\mathcal{L}}^{\dagger}$) | Gradient Descent | $\log(1/\varepsilon)$ |
| 4 | Electric Flow (${\mathcal{L}}^{\dagger}$) | Multiplicative Expansion | $\log\log(1/\varepsilon)$ |
| 2 | Resistive Embedding ($\sqrt{{\mathcal{L}}^{\dagger}}$) | Power Series | $\log(1/\varepsilon)$ |
| 3 | Heat Kernel ($e^{-s{\mathcal{L}}}$) | Power Series | $\log(1/\varepsilon)+s\lambda_{\max}$ |
| 5 | Heat Kernel ($e^{-s{\mathcal{L}}}$) | Multiplicative Expansion | $\log(1/\varepsilon)+\log(s\lambda_{\max})$ |
| 6 & 7 | $k$-Eigenvector Decomp. of ${\mathcal{L}}$ | Subspace Iteration | (subspace-iteration steps)/$k$ |

### 1.2 Related Work

Numerous authors have proposed different ways of adapting Transformers to graphs (Dwivedi and Bresson, ; Ying et al., ; Rampasek et al., ; Muller et al., ). A particularly promising approach is to use a positional encodings to incorporate structural information in the input, examples include Laplacian eigenvectors (Dwivedi and Bresson, ; Kreuzer et al., ), heat kernel (Choromanski et al., ), resistance distance and commute time (Ma et al., ; Velingker et al., ; Zhang et al., ) and shortest path distance (Ying et al., ). Lim et al. () design a neural network to transform eigenvectors into an encoding that has certain invariance properties. Black et al. () compare the expressivity of different PE schemes.

Kim et al. () explore the possibility of using pure Transformers for graph learning. They provide both nodes and edges as input tokens, with a simple encoding scheme. They also prove that such a Transformer is as expressive as a second-order invariant graph network.

Ma et al. () propose a novel graph Transformer architecture that incorporates *learned* PEs based on learned relative random walk probabilities (RRWP). Kreuzer et al. () also propose learning PEs parameterized by eigenfunctions. In comparison, using a linear-Transformer to learn PEs has a few advantages: First, self attention can implement operations such as orthogonalization that are necessary for learning eigenvectors (Lemma 6). Second, self-attention enables some highly-efficient algorithms based on multiplicative polynomial expansions (Lemma 4). For these reasons, linear Transformers can learn good PEs given *only* the incidence matrix as input.

Finally, we note several other relevant papers that are unrelated to graph neural networks. A recent body of work proves the ability of Transformers to implement learning algorithms, to explain the in-context learning phenomenon (Schlag et al., ; Von Oswald et al., ). Surprisingly, our construction for Lemma 1 bears several remarkable parallels to the gradient descent construction by Von Oswald et al. (). We conjecture that the proof of Lemma 4 may be applicable for understanding the GD++ algorithm in the same paper. In another direction, Charton () show experimentally that Transformers can compute linear algebra operations such as eigenvector decomposition. Their work requires a relatively complicated matrix encoding and a large number of parameters.

## 2 Preliminaries and Notation

### 2.1 Graphs

We use ${\mathcal{G}}=({\mathcal{V}},{\mathcal{E}})$ to denote a graph with vertex set ${\mathcal{V}}$ and edge set ${\mathcal{E}}$; $n$ denotes $|{\mathcal{V}}|$ and $d$ represents $|{\mathcal{E}}|$. We often identify the vertex $v_{i}$ with its index $i$ for $i=1...n$, and the edge $e_{j}$ with $j$ for $j=1...d$. We will generally consider weighted graphs, where $r(\cdot):{\mathcal{E}}\to\mathbb{R}^{+}$ gives the edge weights. We will use $r_{j}:=r(e_{j})$. A central object of interest is the *incidence matrix* $B\in\mathbb{R}^{n\times d}$, defined as follows: to each edge $e_{j}\in{\mathcal{E}}$, assign an arbitrary orientation, i.e. $e=(u\to v)\in{\mathcal{E}}$. The matrix $B$ is given by

$$ $\displaystyle B_{ij}=\left\{\begin{array}[]{ll}-1/\sqrt{r_{j}},&\text{ if exists $v\in{\mathcal{V}}$ such that $e_{j}=(u_{i}\to v)$}\\ +1/\sqrt{r_{j}},&\text{ if exists $v\in{\mathcal{V}}$ such that $e_{j}=(v\to u _{i})$}\\ 0,&\text{ otherwise.}\end{array}\right.$ $$

Next, we define the graph Laplacian as ${\mathcal{L}}:=BB^{\top}\in\mathbb{R}^{n\times n}$. We will often need to refer to the maximum eigenvalue of ${\mathcal{L}}$, which we denote as $\lambda_{\max}$. Note that ${\mathcal{L}}$ always has 0 0 as its smallest eigenvalue, with corresponding eigenvector $\frac{1}{\sqrt{n}}\vec{1}$, the all-ones vector. This fact can be verified by noticing that each column of $B$ sums to 0 0. For a connected graph (as we will assume is the case throughout the paper), the second-smallest eigenvalue is always non-zero, and we will denote it as $\lambda_{\min}$.

Finally, we will frequently refer to the matrix $I_{n\times n}-\frac{1}{n}\vec{1}\vec{1}^{\top}$; for ease of reference, we will write $\hat{I}:=I_{n\times n}-\frac{1}{n}\vec{1}\vec{1}^{\top}$. This matrix is the projection onto span$({\mathcal{L}})$, and it essentially functions as the identity matrix, as we work within span$({\mathcal{L}})$ most of the time.

### 2.2 Linear Transformer

We will use $Z_{0}\in\mathbb{R}^{h\times n}$ to denote the input to the Transformer. $Z_{0}$ encodes a graph ${\mathcal{G}}$, and each column of $Z_{0}$ encodes a single vertex in $h$ dimensions. Let $W^{Q},W^{K},W^{V}\in\mathbb{R}^{h\times h}$ denote the key, query and value parameter matrices. We define linear attention $\mathrm{Attn}$ as

$$ $\displaystyle\mathrm{Attn}_{W^{V},W^{Q},W^{K}}(Z):=W^{V}ZZ^{\top}{W^{Q}}^{\top }W^{K}Z.$ (2.2) $$

Unlike standard attention, (2.2) does not contain softmax activation. We construct an $L$-layer Transformer by stacking $L$ layers of the attention module (with linear feed-forward). To be precise, let $Z_{l}$ denote the output of the $(l-1)^{th}$ layer of the Transformer. Then

$$ $\displaystyle Z_{l+1}:=Z_{l}+\mathrm{Attn}_{W^{V}_{l},W^{Q}_{l},W^{K}_{l}}{ \left(Z_{l}\right)}+{W^{R}}Z_{l},$ (2.3) $$

where $W^{V}_{l},W^{Q}_{l},W^{K}_{l}$ are the value, query and key weight matrices of the linear attention module at layer $l$, and $W^{R}\in\mathbb{R}^{h\times h}$ is the weight matrix of the linear module. Henceforth, we let $W^{V}:=\{W^{V}_{l}\}_{l=0\ldots L}$, $W^{Q}:=\{W^{Q}_{l}\}_{l=0\ldots L}$, $W^{K}_{l}:=\{W^{K}_{l}\}_{l=0\ldots L}$, $W^{R}_{l}:=\{W^{R}_{l}\}_{l=0\ldots L}$ denote collections of the parameters across all layers of an $L$-layer Transformer.

Finally, we will often need to refer to specific rows of $Z_{l}$. We will use ${\left[Z_{l}\right]}_{i...j}$ to denote rows $i$ to $j$ of $Z_{l}$.

## 3 Transformers as powerful solvers for Laplacian problems

In this section, we discuss the capacity of the linear Transformer 2.3 to solve certain classes of canonical graph problems. We begin with the problem of Electric Flow in Section 3.2, where the constructed Transformer can be interpreted as implementing steps of gradient descent with respect to the energy of the induced flow. Subsequently, in Section 3.3, we provide constructions for computing the resistive embedding, as well as the heat kernel, based on implementing a truncated power series. Finally, in Section 3.4, we provide faster alternative constructions for solving electric flow and computing heat kernels, based on implementing a *multiplicative polynomial expansion*. In each case, we bound the error of the Transformer by the convergence rate of the underlying algorithms.

### 3.1 Additional Setup

We introduce some additional setup that is common to many lemmas in this section. We will generally consider an $L$-layer Transformer, as defined in (2.3), for some arbitrary $L\in\mathbb{Z}^{+}$. As in (2.3), we use $Z_{l}$ to denote the input to layer $l$. The input $Z_{0}$ will encode information about a graph ${\mathcal{G}}$, along with a number of demand vectors $\psi_{1}\ldots\psi_{k}\in\mathbb{R}^{n}$. We use $\Psi$ to denote the $n\times k$ matrix whose $i^{th}$ column is $\psi_{i}$. Unless otherwise stated, $Z_{l}\in\mathbb{R}^{(d+2k)\times n}$, where $n$ is the number of nodes, $d$ is the number of edges, and $k$ is the number of demands/queries. $Z_{0}^{\top}:=\begin{bmatrix}B,&\Psi,&0_{n\times k}\end{bmatrix}$.

On parameter size: In a straightforward implementation, the above Transformer has feature dimension $h=(d+2k)$. The size of $W^{Q},W^{K},W^{V},W^{R}$ is $O(h^{2})=O(d^{2}+k^{2})$, which is prohibitively large as $d$ can itself be $O(n^{2})$. The size of parameter matrices can be significantly reduced to $O(k^{2})$ by imposing certain constraints on the parameter matrices; we present this reduction in (5.1) in Section 5. For simplicity of exposition, lemmas in this section will use the naive implementation in (2.3). We verify later that all the constructions presented in this section can also be realized in (5.1).

### 3.2 Solving Electric Flow with Gradient Descent

Assume we are given a graph ${\mathcal{G}}=({\mathcal{V}},{\mathcal{E}})$, along with a non-negative vector of resistances $r\in\mathbb{R}_{+}^{d}$. Let $R$ be the $d\times d$ diagonal matrix with $r$ on its diagonal. A flow is represented by $f\in\mathbb{R}^{d}$, where $f_{j}$ denotes the (directed) flow on edge $e_{j}$. The energy of an electric flow is given by
$\sum_{j=1}^{d}r_{j}f_{j}^{2}$. Let $\psi\in\mathbb{R}^{n}$ denote a *vector of demands*. Throughout this paper, we will assume that the demand vectors satisfy *flow conservation*, i.e., $\langle{\psi,\vec{1}}\rangle=0$. The *$\psi$-electric flow* is the unique minimizer of the following (primal) flow-optimization problem (by convex duality, this is equivalent to a dual potential-optimization problem):

$$ (primal) $\displaystyle\min_{f\in\mathbb{R}^{d}}\quad\sum_{j=1}^{d}r_{j}f_{j}^{2}\qquad \qquad\text{subject to the constraint}\quad BR^{1/2}f=\psi.$ (3.1) (dual) $\displaystyle-\min_{\phi\in\mathbb{R}^{n}}\phi^{\top}{\mathcal{L}}\phi-2\phi^{ \top}\psi.$ (3.2) $$

The argument is standard; for completeness, we provide a proof of equivalence between (3.1) and (3.2) in (8.1) in Appendix 8.1. It follows that the optimizer $\phi^{*}$ of (3.2) has closed-form solution $\phi^{*}={\mathcal{L}}^{\dagger}\psi$. In Lemma 1 below, we show a simple construction that enables the Transformer in (2.3) to compute in parallel, the optimal potential assignments for a set of $k$ demands $\left\{\psi_{i}\right\}_{i=1...k}$, where $\psi_{i}\in\mathbb{R}^{n}$.

Motivation: Effective Resistance Metric
An important practical motivation for solving the electric flow (or equivalently computing ${\mathcal{L}}^{\dagger}$) is to obtain the Effective Resistance matrix ${\mathcal{R}}\in\mathbb{R}^{n\times n}$. GNNs that use positional encodings derived from ${\mathcal{R}}$ have demonstrated state-of-the-art performance on numerous tasks, and can be shown to have good theoretical expressivity (Zhang et al., ; Velingker et al., ; Black et al., ). Formally, ${\mathcal{R}}$ is defined as ${\mathcal{R}}_{ij}:=(u_{i}-u_{j})^{\top}{\mathcal{L}}^{\dagger}(u_{i}-u_{j})$, where $u_{i}$ denotes the vector that has a $1$ in the $i^{th}$ coordinate, and 0 0s everywhere else. Intuitively, ${\mathcal{R}}_{ij}$ is the potential drop required to send 1-unit of electric flow from node $i$ to node $j$. Let $\ell\in\mathbb{R}^{n}$ denote the vector of diagonals of ${\mathcal{L}}^{\dagger}$ (i.e. $\ell_{i}:={\mathcal{L}}_{ii}$). Then ${\mathcal{R}}=\vec{1}\ell^{\top}+\ell\vec{1}^{\top}-2{\mathcal{L}}^{\dagger}$; thus computing ${\mathcal{L}}^{\dagger}$ essentially also computes ${\mathcal{R}}$.

###### Lemma 1 (Transformer solves Electric Flow by implementing Gradient Descent) .

Consider the setup in Section 3.1. Assume that $\langle{\psi_{i},\vec{1}}\rangle=0$ for each $i=1...k$. For any $\delta>0$ and for any $L$-layer Transformer, there exists a choice of weights $W^{V},W^{Q},W^{K},W^{R}$, such that each layer of the Transformer (2.3) implements a step of gradient descent with respect to the dual electric flow objective in (3.2), with stepsize $\delta$. Consequently, the following holds for all $i=1...k$ and for any graph Laplacian with maximum eigenvalue $\lambda_{\max}\leq 1/\delta$ and minimum nontrivial eigenvalue $\lambda_{\min}$:

$$ $\displaystyle{\left\|{\left[Z_{L}\right]}_{d+k+i}^{\top}-{\mathcal{L}}^{ \dagger}\psi_{i}\right\|}_{2}\leq\frac{\exp{\left(-\delta\lambda_{min}/2\right )}}{\sqrt{\lambda_{min}}}\|\psi_{i}\|_{2}^{2}{\left\|\psi_{i}\right\|}_{2}.$ $$

Discussion. In the special case when $k=n$ and $\Psi:=I_{n\times n}-\frac{1}{n}\vec{1}\vec{1}^{\top}$, ${\left[Z_{L}\right]}_{d+k+1...d+2k}\approx{\mathcal{L}}^{\dagger}$. An $\varepsilon$-approximate solution requires $L=O(\log(1/\varepsilon))$ layers; this is exactly the convergence rate of gradient descent on a Lipschitz smooth and strongly convex function. In Lemma 4 below, we show an alternate construction that reduces this to $O(\log\log(1/\varepsilon))$.

We defer details of the proof of Lemma 1 to Appendix 8.1, and we provide the explicit choice of weight matrices in (8.3). The constructed weight matrices are very sparse; each of $W^{V},W^{Q},W^{K},W^{R}$ contains a single identity matrix in a sub-block. This sparse structure makes it possible to drastically reduce the number of parameters needed, which we exploit in Section 5 to design a more parameter efficient Transformer. We provide experimental validation of Lemma 1 in Section 3.5.

###### Lemma 1 (Transformer solves Electric Flow by implementing Gradient Descent) .

### 3.3 Implementing Truncated Power Series

In this section, we present two more constructions: one for computing $\sqrt{{\mathcal{L}}^{\dagger}}$ (Lemma 2), and one for computing the heat kernel $e^{-s{\mathcal{L}}}$ (Lemma 3). Both quantities have been successfully used for positional encoding in various GNNs. The constructions proposed in these two lemmas are also similar, and involve implementing the power series of the respective targets.

#### 3.3.1 Computing The Principal Square Root ℒ † superscript ℒ † \sqrt{{\mathcal{L}}^{\dagger}} square-root start_ARG caligraphic_L start_POSTSUPERSCRIPT † end_POSTSUPERSCRIPT end_ARG

Motivation : Resistive Embedding
The following fact relates the effective resistance matrix ${\mathcal{R}}$ to any “square root” of ${\mathcal{L}}^{\dagger}$:

###### Fact 1 .

Let ${\mathcal{M}}$ denote *any matrix* that satisfies ${\mathcal{M}}{\mathcal{M}}^{\top}={\mathcal{L}}^{\dagger}$. Let ${\mathcal{R}}\in\mathbb{R}^{n\times n}_{+}$ denote the matrix of effective resistances (see Section 3.2). Then ${\mathcal{R}}_{ij}={\left\|{\mathcal{M}}_{i}-{\mathcal{M}}_{j}\right\|}_{2}^{2}$, where ${\mathcal{M}}_{i}$ is the $i^{th}$ row of ${\mathcal{M}}$.

One can verify the above by noticing that ${\left\|{\mathcal{M}}_{i}-{\mathcal{M}}_{j}\right\|}_{2}^{2}={\mathcal{M}}_{i}
^{\top}{\mathcal{M}}_{i}+{\mathcal{M}}_{j}^{\top}{\mathcal{M}}_{j}-2{\mathcal{
M}}_{i}^{\top}{\mathcal{M}}_{j}={\left[{\mathcal{L}}\right]}_{ii}+{\left[{
\mathcal{L}}\right]}_{jj}-2{\mathcal{L}}_{ij}$. In some settings, it is more natural to use the rows of ${\mathcal{M}}$ to embed node position, instead of directly using ${\mathcal{R}}$: By assigning an embedding vector $w_{i}:={\mathcal{M}}_{i}$ to vertex $i$, the Euclidean distance between $w_{i}$ and $w_{j}$ equals the resistance distance.

The matrix ${\mathcal{M}}$ is under-determined, and for any $m>n$, there are infinitely many choices of ${\mathcal{M}}$ that satisfy ${\mathcal{M}}{\mathcal{M}}^{\top}={\mathcal{L}}^{\dagger}$. Fact 1 applies to any such ${\mathcal{M}}$. Velingker et al. () uses the rows of ${\mathcal{M}}={\mathcal{L}}^{\dagger}B$ for resistive embedding. Under this choice, ${\mathcal{M}}_{i}$ has dimension $d$, which is the number of edges and can be quite large. To deal with this, Velingker et al. () additionally performs a dimension-reduction step using Johnson Lidenstrauss.

Among all valid choices of ${\mathcal{M}}$, there is a unique choice that is symmetric and minimizes $\|{\mathcal{M}}\|_{F}$, namely, $US^{-1/2}U^{\top}$, where $USU^{\top}={\mathcal{L}}$ is the eigenvector decomposition of ${\mathcal{L}}$. We reserve $\sqrt{{\mathcal{L}}^{\dagger}}$ to denote this matrix; $\sqrt{{\mathcal{L}}^{\dagger}}$ is called the *principal square root of ${\mathcal{L}}^{\dagger}$*. In practice, $\sqrt{{\mathcal{L}}^{\dagger}}$ might be preferable to, say, ${\mathcal{L}}^{\dagger}B$ because it has an embedding dimension of $n$, as opposed to the possibly much larger $d$. We present in Lemma 2 a Transformer construction for computing $\sqrt{{\mathcal{L}}^{\dagger}}$.

###### Lemma 2 (Principal Square Root $\sqrt{{\mathcal{L}}^{\dagger}}$ ) .

Consider the setup in Section 3.1. Assume that $\psi_{1}...\psi_{k}\in\mathbb{R}^{n}$ satisfy $\langle{\psi_{i},\vec{1}}\rangle=0$. For any $L$-layer Transformer (2.3), there exists a configuration of weights $W^{V},W^{Q},W^{K},W^{R}$ such that the following holds: For any graph with maximum Laplacian eigenvalue less than $\lambda_{\max}$ and minimum non-trivial Laplacian eigenvalue greater than $\lambda_{\min}$, and for all $i=1...k$:

$$ $\displaystyle{\left\|{\left[Z_{L}\right]}_{d+k+i}^{\top}-\sqrt{{\mathcal{L}}^{ \dagger}}\psi_{i}\right\|}_{2}\leq\frac{e^{-L\lambda_{\min}/\lambda_{\max}}}{ \lambda_{\min}\sqrt{L/\lambda_{\max}}}{\left\|\psi_{i}\right\|}_{2}.$ $$

Discussion. We defer a proof of Lemma 2 to Appendix 8.2. The high-level idea is that each layer of the Transformer implements one additional term of the power series expansion of $\sqrt{{\mathcal{L}}^{\dagger}}$. Under the choice $k=n$ and $\Psi=I_{n\times n}-(1/n)\vec{1}\vec{1}^{\top}$, ${\left[Z_{L}\right]}_{d+k+1...d+2k}\approx\sqrt{{\mathcal{L}}^{\dagger}}$. An $\varepsilon$ approximation requires $\log(1/\varepsilon)$ layers. We consider the more general setup involving arbitrary $\psi_{i}^{\prime}s$ as they are useful for projecting the resistive embedding onto a lower-dimensional space; this is relevant when $\psi_{i}$’s are trainable parameters (see e.g., the setup in Appendix 12.3).
We empirically validate Lemma 2 in Section 3.5.

###### Fact 1 .

###### Lemma 2 (Principal Square Root ℒ † superscript ℒ † \sqrt{{\mathcal{L}}^{\dagger}} square-root start_ARG caligraphic_L start_POSTSUPERSCRIPT † end_POSTSUPERSCRIPT end_ARG ) .

#### 3.3.2 Computing the heat kernel: exp ⁡ ( − s ⁢ ℒ ) 𝑠 ℒ \exp{\left(-s{\mathcal{L}}\right)} roman_exp ( - italic_s caligraphic_L )

Finally, we present a result on learning heat kernels. The heat kernel has connections to random walks and diffusion maps Coifman and Lafon (). It plays a central role in semi-supervised learning on graphs (Xu et al., ); it is also used for positional encoding (Choromanski et al., ). We note that in some settings, the heat kernel excludes the nullspace of ${\mathcal{L}}$ and is instead defined as $e^{-s{\mathcal{L}}}-\vec{1}\vec{1}^{\top}/n$.

###### Lemma 3 (Heat Kernel $e^{-s{\mathcal{L}}}$ ) .

Consider the setup in Section 3.1. Assume that $\psi_{1}...\psi_{k}\in\mathbb{R}^{n}$ satisfy $\langle{\psi_{i},\vec{1}}\rangle=0$. Let $s>0$ be an arbitrary temperature parameter. There exists a configuration of weights for the $L$-layer Transformer (2.3) such that the following holds: for any input graph whose Laplacian ${\mathcal{L}}$ satisfies $8s\lambda_{\max}\leq L$, and for all $i=1...k$,

$$ $\displaystyle{\left\|{\left[Z\right]}_{L,i}^{\top}-e^{-s{\mathcal{L}}}\psi_{i} \right\|}_{2}\leq 2^{-L+8s\lambda_{\max}+1}{\left\|\psi_{i}\right\|}_{2}$ $$

Discussion. We defer the proof of Lemma 3 to Appendix 8.3. To obtain $\varepsilon$ approximation error, we need number of layers $L\geq{O{\left(\log(1/\varepsilon)+s\lambda_{\max}\right)}}$. As with the preceding lemmas, the flexibility of choosing any number of $\psi_{i}$’s enables the Transformer to learn a low-dimensional projection of the heat kernel. The dependence on $s\lambda_{\max}$ is fundamental, stemming from the fact that the truncation error of the power series of $e^{-s{\mathcal{L}}}$ begins to shrink only after $O(s\lambda_{\max})$ the first terms. In Lemma 5 in the next section, we weaken this dependence from $s\lambda_{\max}$ to $\log(s\lambda_{\max})$. We empirically validate Lemma 3 in Section 3.5.

###### Lemma 3 (Heat Kernel e − s ⁢ ℒ superscript 𝑒 𝑠 ℒ e^{-s{\mathcal{L}}} italic_e start_POSTSUPERSCRIPT - italic_s caligraphic_L end_POSTSUPERSCRIPT ) .

### 3.4 Implementing Multiplicative Polynomial Expansion

We present two alternative Transformer constructions that can achieve vastly higher accuracy than the ones in preceding sections: Lemma 4 computes an $\varepsilon$-accurate electric flow in exponentially fewer layers than Lemma 1. Lemma 5 approximates the heat kernel with higher accuracy than Lemma 3 when the number of layers is small. The key idea in both Lemmas 4 and 5 is to use the Transformer to implement a multiplicative polynomial; this in turn *makes key use of the self-attention module*.

The setup for Lemmas 4 and 5 differs in two ways from that presented in Section 3.1. First, the input to layer $l$, $Z_{l}$, are now in $\mathbb{R}^{3n\times n}$, instead of $\mathbb{R}^{(d+2k)\times n}$. When the graph ${\mathcal{G}}$ is sparse and the number of demands/queries $k$ is small, the constructions in Lemma 1 and 3 may use considerably less memory. This difference is *fundamental*, due to the storage required for raising matrix powers. Second, the input is also different; in particular, information about the graph is provided via ${\mathcal{L}}$ as part of the input $Z_{0}$, as opposed to via the incidence matrix $B^{\top}$ as done in Section 3.1. This difference is *not fundamental*: one can compute ${\mathcal{L}}=B^{\top}B$ from $B$ in a single attention layer; in the spirit of brevity, we omit this step. We begin with the faster construction for electric flow:

###### Lemma 4 .

Let $\delta>0$. Let $Z_{0}^{\top}:=\begin{bmatrix}(\hat{I}_{n\times n}-\delta{\mathcal{L}}),&I_{n
\times n},&\delta I_{n\times n}\end{bmatrix}$. Then there exist a choice of $W^{V},W^{Q},W^{K},W^{R}$ for a $L$-layer Transformer (2.3) such that for any graph with Laplacian with smallest non-trivial eigenvalue $\lambda_{\min}$ and largest eigenvalue $\lambda_{\max}\leq 1/\delta$,

$$ $\displaystyle{\left\|{\left[Z_{L}\right]}_{2n+1...3n}-{\mathcal{L}}^{\dagger} \right\|}_{2}\leq\frac{1}{\lambda_{\min}}\exp{\left(-\delta 2^{L}\lambda_{\min }\right)}.$ $$

Discussion. Lemma 4 shows that the Transformer can compute an $\varepsilon$-approximation to ${\mathcal{L}}^{\dagger}$ (which is sufficient but not necessary for solving arbitrary electric flow demands) using $\log\log(1/\varepsilon)$ layers. This is much fewer than the $\log(1/\varepsilon)$ layers required in Lemma 1. The key idea in the proof is to implement a multiplicative polynomial expansion for ${\mathcal{L}}^{\dagger}$. We defer the proof to Appendix 8.4.

Next, we show the alternate construction for computing the heat kernel:

###### Lemma 5 (Fast Heat Kernel) .

Let $s>0$. Let $L$ be the number of Transformer layers. Let $Z_{0}^{\top}:=(I_{n\times n}-3^{-L}s{\mathcal{L}})$. Then there exist a choice of $W^{V},W^{Q},W^{K},W^{R}$ such that for any graph whose Laplacian ${\mathcal{L}}$ satisfies $s\lambda_{\max}\leq 3^{L}$,

$$ $\displaystyle{\left\|Z_{L}-\exp(-s{\mathcal{L}})\right\|}_{2}\leq 3^{-L+1}{s^{ 2}\lambda_{\max}^{2}}.$ $$

Discussion. Lemma 5 shows that the Transformer can compute an $\varepsilon$-approximation to $e^{-s{\mathcal{L}}}$ using $O(\log(1/\varepsilon)+\log(s\lambda_{\max}))$ layers. The $\varepsilon$ dependence is the same as Lemma 3, but the $\log(s\lambda_{\max})$ is an improvement. When the number of layers is small, Lemma 5 gives a significantly more accurate approximation. The proof is based on the well-known approximation $e^{x}\approx(1+x/L)^{L}$. We defer proof details for Lemma 5 to Appendix 8.4.

###### Lemma 4 .

###### Lemma 5 (Fast Heat Kernel) .

### 3.5 Experiments

In Figure 1, we experimentally verify that the Transformer is capable of learning to solve the three objectives presented in Lemmas 1, 2 and 3. The setup is as described in Section 3.1, with the Transformer described in (2.3) with $k=n$, but with the following important difference: the output of each layer is additionally normalized as follows: ${\left[Z_{l}\right]}_{1...n}\leftarrow{\left[Z_{l}\right]}_{1...n}/\|{\left[Z_
{l}\right]}_{1...n}\|_{F}$, ${\left[Z_{l}\right]}_{n+1...n+2k}\leftarrow{\left[Z_{l}\right]}_{n+1...n+2k}/
\|{\left[Z_{l}\right]}_{n+1...n+2k}\|_{F}$, where $\|\|_{F}$ is the Frobenius norm. Without this normalization, training the Transformer becomes very difficult beyond 5 layers.

We consider two kinds of random graphs: fully-connected graphs ($n=10,d=45$) and Circular Skip Links (CSL) graphs ($n=10,d=20$). Edge resistances are randomly sampled. We provide details on the sampling distributions in Appendix 11. For each input graph ${\mathcal{G}}$, we sample $n$ demands $\psi_{1}...\psi_{n}\in\mathbb{R}^{n}$ independently from the unit sphere. Let $\Psi={\left[\psi_{1}...\psi_{n}\right]}$. The input to the Transformer is $\begin{bmatrix}B^{\top},&\Psi^{\top},&0_{n\times n}\end{bmatrix}$, consistent with the setup described in Section 3.1. The training/test loss is given by
$\text{loss}_{U}:=\mathbb{E}{\left[\frac{1}{n}\sum_{i=1}^{n}{\left\|\frac{{
\left[Z_{l}\right]}_{d+n+i}^{\top}}{\|{\left[Z_{l}\right]}_{d+n+i}\|_{2}}-
\frac{U\psi_{i}}{\|U\psi_{i}\|_{2}}\right\|}_{2}^{2}\right]},$
where $U\in\left\{{\mathcal{L}}^{\dagger},\sqrt{{\mathcal{L}}^{\dagger}},e^{-0.5{
\mathcal{L}}}\right\}$. We learn the correct solutions only up to scaling, because we need to normalize $Z_{l}$ per-layer. The expectation is over randomness in sampling ${\mathcal{L}}$ and $\Psi$. We plot the log of the respective losses against number of layers after training has converged. As can be seen, in each plot, and for both types of architectures, the loss appears to decrease exponentially with the number of layers.

Figure: Figure 1: $\text{loss}_{U}$ against number of layers at convergence for $U\in\left\{{\mathcal{L}}^{\dagger},\sqrt{{\mathcal{L}}^{\dagger}},e^{-0.5{ \mathcal{L}}}\right\}$.
Refer to caption: x1.png

## 4 Transformers can Implement Subspace Iteration to Compute Eigenvectors

We present a Transformer construction for finding the eigenvectors of the graph Laplacian ${\mathcal{L}}$. The eigenvector for the smallest non-trivial eigenvalue, for example, has been applied with great success in graph segmentation (Shi and Malik, ) and clustering (Bühler and Hein, ). Additionally, the Laplacian eigenvectors are also commonly used for positional encoding (see Section 1.2). Our construction is based on the *subspace iteration* algorithm (Algorithm 1), aka *block power method*—see e.g., (Bentbib and Kanber, ). The output $\Phi$ of Algorithm 1 converges to the top-$k$ eigenvectors of ${\mathcal{L}}$. We show in Corollary 7 that a modified construction can also find the *bottom-$k$* eigenvectors of ${\mathcal{L}}$.

Figure: Algorithm 1 Subspace Iteration

For the purposes of this section, we consider a variant of the Transformer defined in (2.3).

$$ $\displaystyle\hat{Z}_{l+1}:=Z_{l}+\mathrm{Attn}_{W^{V}_{l},W^{Q}_{l},W^{K}_{l} }{\left(Z_{l}\right)}+{W^{R}}Z_{l}$ $\displaystyle{Z}_{l+1}=\text{normalize}(\hat{Z}_{l+1}),$ (4.1) $$

where $\text{normalize}(Z)$ applies row-wise normalization: ${\left[\text{normalize}(Z)\right]}_{i}\leftarrow{\left[Z\right]}_{i}/\|{\left[
Z\right]}_{i}\|_{2}$ for $i=d+1...d+k$. We use $B_{l}\in\mathbb{R}^{n\times d}$ and $\Phi_{l}\in\mathbb{R}^{n\times k}$ to denote refer to specific columns of $Z_{l}^{\top}$, defined as $Z_{l}^{\top}=:\begin{bmatrix}B_{l}^{T},&\Phi_{l}^{\top}\end{bmatrix}$. The notation is chosen as $\Phi_{l}$ corresponds to $\Phi$ in Algorithm 1. We initialize $B_{0}=B$ and let $\Phi_{0}$ be any column-orthogonal matrix.

###### Lemma 6 (Subspace Iteration for Finding Top $k$ Eigenvectors) .

Consider the Transformer defined in (4.1). There exists a choice of $W^{V},W^{Q},W^{K},W^{R}$ such that $k+1$ layers of the Transformer implements one iteration of Algorithm 1. Consequently, the output $\Phi_{L}$ of a $L$-layer Transformer approximates the top-$k$ eigenvectors of ${\mathcal{L}}$ to the same accuracy as $L/(k+1)$ steps of Algorithm 1.

Discussion. We bound the Transformer’s error by the error of Algorithm 1, but do not provide an explicit convergence rate. This omission is because the convergence rate of Algorithm 1 itself is difficult to characterize, and has a complicated dependence on pairwise spectral gaps. The high-level proof idea is to use self-attention to orthogonalize the columns of $\Phi_{l}$ (see Lemma 8). We defer the proof of Lemma 6 to Appendix 9. We experimentally validate Lemma 6 in Section 4.1.

The construction in Lemma 6 explicitly requires $k$ layers to perform a QR decomposition of $\Phi$ plus 1 layer to multiply by ${\mathcal{L}}$. The layer usage can be much more efficient in practice: First, multiple ${\mathcal{L}}$-multiplications can take place before a single QR-factorization step. Second, the $k$ layers for performing QR decomposition can be implemented in a single layer with $k$ parallel heads.

In graph applications, one is often interested in the *smallest-$k$* eigenvectors of ${\mathcal{L}}$:

###### Corollary 7 (Subspace Iteration for Finding Bottom $k$ Eigenvectors) .

Consider the same setup as Lemma 6. Let $\mu>0$ be some constant. There exists a construction for a $L$-layer Transformer (similar to Lemma 6), which implements Algorithm 1 with ${\mathcal{L}}$ replaced by $\mu I-{\mathcal{L}}$, and $\Phi_{L}$ approximates the smallest $k$ eigenvectors of ${\mathcal{L}}$ if $\lambda_{\max}({\mathcal{L}})\leq\mu$.

We provide a short proof in Appendix 9. The key idea is that a minor modification of the contruction in Lemma 6 will instead compzute the bottom $k$ eigenvectors. Alternative to the construction in Corollary 7, one can also first compute ${\mathcal{L}}^{\dagger}$ (via Lemma 4), and then perform subspace iteration for ${\mathcal{L}}^{\dagger}$.

###### Lemma 6 (Subspace Iteration for Finding Top k 𝑘 k italic_k Eigenvectors) .

###### Corollary 7 (Subspace Iteration for Finding Bottom k 𝑘 k italic_k Eigenvectors) .

### 4.1 Experiments for Lemma 6

We verify Lemma 6 and Corollary 7 experimentally by evaluating the ability of the Transformer (2.3) to learn top-$k$ and bottom-$k$ eigenvectors. As in Section 3.5, we consider two kinds of random graphs with $n=10$ nodes: fully connected ($d=45$ edges) and CSL ($d=20$ edges); each edge is has a randomly sampled resistance; see Appendix 11 for details. For a graph ${\mathcal{G}}$ with Laplacian ${\mathcal{L}}$, let $\lambda_{1}\leq\lambda_{2}\leq...\lambda_{10}$ denote its eigenvalues. Let $v_{1},\dots,v_{10}$ denote its eigenvectors. $\lambda_{1}$ is always 0 0 and $v_{1}$ is always $\vec{1}/\sqrt{n}$.

The Transformer architecture is as defined in Section 4.1, with $k=n$. We increase the dimension of $\Phi_{l}$ to $(2n)\times n$, and thus the dimension of $Z_{l}$ to $(d+n+n)\times n$. We read out the last $n$ rows of $Z_{L}$ as output. The purpose of increasing the dimension is to make the architecture identical to the one used in the experiments in Section 3.5; the construction in Lemmas 6 and Corollary 7 extend to this setting by setting appropriate parameters to 0 0. In addition, we also normalize ${\left[Z_{l}\right]}_{1...d}$ each layer by its Frobenius norm, i.e., ${\left[Z_{l}\right]}_{1...d}\leftarrow{\left[Z_{l}\right]}_{1...d}/\|{\left[Z_
{l}\right]}_{1...d}\|_{F}$ (the proof of Lemma 6 still holds as subspace iteration is scaling-invariant). The input to the Transformer is $Z_{0}^{\top}=\begin{bmatrix}B,&\Phi_{0}\end{bmatrix}$, and we make $\Phi_{0}\in\mathbb{R}^{2n\times n}$ a trainable parameter along with $W^{V},W^{Q},W^{K},W^{R}$. We define $\text{loss}_{i}:=\mathbb{E}{\left[\min\left\{\|\phi_{L,i}-v_{i}\|_{2}^{2},\|
\phi_{L,i}+v_{i}\|_{2}^{2}\right\}\right]}$, where $\phi_{L,i}$ is the $i^{th}$ row of $\Phi_{L}$ and expectation is taken with respect to randomness in sampling the graph; the $\min$ is required because eigenvectors are invariant to sign-flips. We train and evaluate the Transformer on two kinds of losses: $\text{loss}_{1-5}:=\frac{1}{5}\sum_{i=1}^{5}\text{loss}_{i}$ and $\text{loss}_{1-10}:=\frac{1}{10}\sum_{i=1}^{10}\text{loss}_{i}$. We plot the results in Figure 2, and summarize our findings below:

- 1.
2(a) and 2(d): Both $\text{loss}_{1-5}$ and $\text{loss}_{1-10}$ appear to decrease exponentially with the number of Transformer layers, for both FC and CSL graphs. This is consistent with Lemma 6 and Corollary 7.
- 2.
In Figures 2(e) and 2(f), when the Transformer is trained on $\text{loss}_{1-10}$, larger eigenvectors are learned more accurately, with the exception of $loss_{2}$. This is mostly consistent with our construction in Lemma 6, where the larger eigenvectors are computed more quickly.
In contrast, in Figures 2(b) and 2(c), when the Transformer is trained on $\text{loss}_{1-5}$, the smaller eigenvectors are learned more accurately. This is consistent with our construction in Corollary 7, where the smaller eigenvectors of ${\mathcal{L}}$ are also the larger eigenvectors of $\alpha I-{\mathcal{L}}$, and are thus computed more quickly. One expects to observe the same ordering if the Transformer is instead computing ${\mathcal{L}}^{\dagger}$ first, followed by subspace iteration.

We omit $\text{loss}_{1}$ from Figures 2(b), 2(c), 2(e), 2(f) because $v_{1}$ is a constant so $\text{loss}_{1}$ goes to 0 0 extremely fast, making it hard to see the other lines.

Figure: Figure 2: $\log(\text{loss}_{*})$ vs. number of layers. Top row: various losses for the Transformer trained on $\text{loss}_{1-5}$. Bottom row: various losses for the Transformer trained on $\text{loss}_{1-10}$.
Refer to caption: x4.png

## 5 Parameter-Efficient Implementation

As explained in Section 3.1, the sizes of the $W^{Q},W^{K},W^{V},W^{R}$ matrices can scale with $O(n^{4})$ in the worst case, where $n$ is the number of nodes. This makes the memory requirement prohibitive.
To alleviate this, we present below in (5.1) a more efficient Transformer implementation than the one defined in (2.3). (5.1) is strictly more constrained than (2.3), but it is still expressive enough to implement all the previous constructions. For each layer $l$, let $\alpha^{V}_{l}$, $\alpha^{Q}_{l}$, $\alpha^{K}_{l}$, $\alpha^{R}_{l}$ be scalar weight parameters, and let $W_{l}^{V,\Phi}$, $W_{l}^{Q,\Phi}$, $W_{l}^{K,\Phi}$, $W_{l}^{R,\Phi}\in\mathbb{R}^{2k\times 2k}$.
Let $B_{l},\Phi_{l}$ evolve as

$$ $\displaystyle B_{l+1}^{\top}=(1+\alpha^{R}_{l})B_{l}^{\top}+\alpha^{V}_{l}B_{l }^{\top}{\left(\alpha^{Q}_{l}\alpha^{K}_{l}B_{l}B_{l}^{\top}+\Phi_{l}{W_{l}^{Q ,\Phi}}^{\top}W_{l}^{K,\Phi}\Phi_{l}^{\top}\right)}$ (5.1) $\displaystyle\Phi_{l+1}^{\top}={\left(I+W_{l}^{R,\Phi}\right)}\Phi_{l}^{\top}+ W_{l}^{V,\Phi}\Phi_{l}^{\top}{\left(\alpha^{Q}_{l}\alpha^{K}_{l}B_{l}B_{l}^{ \top}+\Phi_{l}{W_{l}^{Q,\Phi}}^{\top}W_{l}^{K,\Phi}\Phi_{l}^{\top}\right)},$ $$

with initialization $B_{0}:=B$, and $\Phi_{0}=[\Psi,0_{k\times n}]$. We verify that (5.1) matches (2.3), with $Z_{l}=\begin{bmatrix}B_{l}^{\top},\Phi_{l}^{\top}\end{bmatrix}$; the difference is that certain blocks of $W^{V}_{l}$, $W^{Q}_{l}$, $W^{K}_{l}$, $W^{R}_{l}$ constrained to be zero or some scaling of identity. Nonetheless, we verify that the constructions in Lemmas 1, 2, 3 and 6 can all be realized within the constrained dynamics (5.1). We prove this in Lemma 9 in Appendix 10.

Besides the reduced parameter size, we highlight two additional advantages of (5.1):

- 1.
Let ${\sf TF}^{B}_{l}({\color[rgb]{0,0,1}B},{\color[rgb]{0,0,1}\Phi})$ (resp ${\sf TF}^{\Phi}_{l}({\color[rgb]{0,0,1}B},{\color[rgb]{0,0,1}\Phi}))$ be defined as the value of $B_{l}^{\top}$ (resp $\Phi_{l}^{\top}$) when initialized at $B_{0}={\color[rgb]{0,0,1}B}$ and $\Phi_{0}={\color[rgb]{0,0,1}\Phi}$ under the dynamics (5.1). Let $U\in\mathbb{R}^{d\times d}$ be some permutation matrix over edge indices. Then
(a)
${\sf TF}^{B}_{l}$ is *equivariant* to edge permutation, i.e. ${\sf TF}^{B}_{l}(BU,\Phi)=U^{\top}{\sf TF}^{B}_{l}(B,\Phi)$
(b)
${\sf TF}^{\Phi}_{l}$ is *invariant* to edge permutation, i.e. ${\sf TF}^{\Phi}_{l}(BU,\Phi)={\sf TF}^{\Phi}_{l}(B,\Phi)$.
We provide a short proof of this in Lemma 10 in Appendix 10.
- 2.
If $B_{l}$ is sparse, then $B_{l}^{\top}B_{l}$ can be efficiently computed using sparse matrix multiply. This is the case for all of our constructions for all layers $l$.

## 6 Learning Positional Encoding for Molecular Regression

In Sections 3.5 and 4.1, we saw that the Transformer is capable of learning a variety of embeddings based on ${\mathcal{L}}^{\dagger},\sqrt{{\mathcal{L}}},e^{-s{\mathcal{L}}}$, and EVD(${\mathcal{L}}$), when the training loss is explicitly the recovery loss for that embedding.
An natural question is then: *Can a GNN perform as well on a downstream task if we replace its PE by a linear Transformer, and train the GNN together with the linear Transformer?* There are two potential benefits to this approach: First, the Transformer can learn a PE that is better-suited to the task than hard-coded PEs, and thus achieve higher accuracy. Second, the Transformer with a few layers/dimensions may learn to compute only the most relevant features, and achieve comparable accuracy to the hard-coded PE using less computation.

To test this, we evaluate the performance of our proposed linear Transformer on a molecular regression task on two real-world datasets: QM9 (Ruddigkeit et al., ; Ramakrishnan et al., ) and ZINC (Irwin et al., ). The regression target is constrained solubility (Dwivedi et al., ). Our experiments are based on the Graph Transformer (GT) implementation from Dwivedi and Bresson (). In Table 2, we compare three loss values: GT without PE, GT with Laplacian Eigenvector as PE (LapPE), and GT with Linear Transformer output as PE. We choose to use LapPE as a baseline as it was the original PE of choice in Dwivedi and Bresson (). We present details of the datasets in Appendix 12.1. The architecture of linear Transformer is a modified version of (5.1), detailed in Appendix 12.2. Other experiment details, including precise definitions of each model, can be found in Appendix 12.3.

**Table 2: Regression Loss for ZINC and QM9 for different choices of PE.**
|  | Model | # Parameters | Loss |
| --- | --- | --- | --- |
| ZINC | Graph Transformer | $800771-891$ | $0.286\pm 0.0078$ |
| Graph Transformer + LapPE | $800771$ | $0.201\pm 0.0034$ |  |
| Graph Transformer + Linear Transformer | $800771+488$ | $0.138\pm 0.012$ |  |
| QM9 | Graph Transformer | $799747-512$ | $0.419\pm 0.0047$ |
| Graph Transformer + LapPE | $799747$ | $0.227\pm 0.0094$ |  |
| Graph Transformer + Linear Transformer | $799747+240$ | $0.221\pm 0.0060$ |  |

The difference between GT and GT + LapPE is substantial for both QM9 and ZINC, highlighting the importance of PE in both cases.

Going from GT + LapPE to GT + Linear Transformer for ZINC, there is a significant further improvement in loss (a drop of 0.063). This is remarkable, considering that the linear Transformer accounts for less than $0.7\%$ of the total number of parameters. Note that the SOTA error for ZINC regression is significantly lower than 0.138 on more recent architectures (see e.g. Lim et al. ()); the significance of our result is in demonstrating the improvement *just by replacing the LapPE with the linear Transformer, while keeping everything else fixed.*

In contrast, when going from GT + LapPE to GT + Linear Transformer for QM9, the difference is essentially zero. We conjecture that this may be because QM9 molecules (average of about $9$ nodes and $19$ edges) are considerably simpler than ZINC (average of about $23$ nodes and $40$ edges). Thus there may not be too many additional useful features to learn, and LapPE close to optimal. It is still consistent with our theory, for the Linear Transformer to do as well as LapPE.

## 7 Acknowledgement

The authors would like to thank Professor Xavier Bresson from the National University of Singapore for providing the GitHub code which facilitated some of the experiments in this work. Suvrit Sra acknowledges generous support from the Alexander von Humboldt Foundation.

## 8 Proofs for Section 3

### 8.1 Electric Flow

###### Proof of Primal Dual Equivalence for Electric Flow.

By convex duality, the primal problem in (3.1) can be reformulated as

$$ $\displaystyle\min_{f:BR^{1/2}f=\psi}\quad\sum_{j=1}^{d}r_{j}f_{j}^{2}$ $\displaystyle=$ $\displaystyle\min_{f}\max_{\phi}f^{\top}Rf-2\phi^{\top}(BR^{1/2}f-\psi)$ $\displaystyle=$ $\displaystyle\max_{\phi}\min_{f}f^{\top}Rf-2\phi^{\top}(BR^{1/2}f-\psi)$ $\displaystyle=$ $\displaystyle\max_{\phi}-\phi^{\top}BB^{\top}\phi+2\phi^{\top}\psi$ $\displaystyle=$ $\displaystyle-\min_{\phi\in\mathbb{R}^{n}}\phi^{\top}{\mathcal{L}}\phi-2\phi^{ \top}\psi$ (8.1) $$

∎

###### Proof of Lemma 1 .

Let $F_{\psi}(\phi):=\frac{1}{2}\phi^{\top}{\mathcal{L}}\phi-\phi^{\top}\psi$ denote ($1/2$ times) the dual optimization objective from (3.2). Its gradient is given by

$$ $\displaystyle\nabla F_{\psi}(\phi)={\mathcal{L}}\phi-\psi.$ $$

Let $Z_{l}$ denote the output after $l$ layers of the Transformer (2.3), i.e. $Z_{l}$ evolves according to (2.3):

$$ $\displaystyle Z_{l+1}:=Z_{l}+W^{V}_{l}Z_{l}Z_{l}^{\top}{W^{Q}_{l}}^{\top}W^{K} _{l}Z_{l}+W^{R}_{l}Z_{l}.$ $$

We use $B_{l}^{\top}$ to denote the first $d$ rows of $Z_{l}$, $\Lambda_{l}^{\top}$ to denote the $(d+1)^{th}$ row to $(d+k)^{th}$ row of $Z_{l}$ and $\Phi_{l}^{\top}$ to denote the last $k$ rows of $Z_{l}$, i.e. $Z_{l}=\begin{bmatrix}B_{l}^{\top}\\
\Lambda_{l}^{\top}\\
\Phi_{l}^{\top}\end{bmatrix}$. For $i=1...k$, let $\phi_{l,i}$ denote the $i^{th}$ column of $\Phi_{l}$. Then there exists a choice of $W^{V},W^{Q},W^{K},W^{R}$, such that for all $i$,

$$ $\displaystyle\phi_{l+1,i}=\phi_{l,i}-\delta\nabla F_{\psi_{i}}(\phi_{l,i}).$ (8.2) $$

Before proving (8.2), we first consider its consequences. We can verify that $\nabla^{2}F_{\psi}(\cdot)={\mathcal{L}}$, which is in turn upper and lower bounded by $\lambda_{\min}\prec{\mathcal{L}}\prec\lambda_{\max}$. By standard analysis of gradient descent for strongly convex and Lipschitz smooth functions, for $\delta<\frac{1}{\lambda_{\max}}$, we verify that

$$ $\displaystyle\|\phi_{l+1,i}-{\mathcal{L}}^{\dagger}\psi_{i}\|_{2}^{2}\leq{ \left(1-{\delta\lambda_{min}}\right)}\|\phi_{l,i}-{\mathcal{L}}^{\dagger}\psi_ {i}\|_{2}^{2}$ $\displaystyle\Rightarrow\qquad$ $\displaystyle\|\phi_{L,i}-{\mathcal{L}}^{\dagger}\psi_{i}\|_{2}^{2}\leq e^{- \delta\lambda_{min}}\|{\mathcal{L}}^{\dagger}\psi_{i}\|_{2}^{2}\leq\frac{\exp{ \left(-\delta\lambda_{min}\right)}}{\lambda_{min}}\|\psi_{i}\|_{2}^{2}$ $$

As a final note, $F$ is only weakly convex along the $\vec{1}$ direction, but we can ignore this because $\phi_{l,i}$ will always be orthogonal to $\vec{1}$ as long as $\phi_{l,0}$ is (as we assumed in the lemma statement).

The remainder of the proof will be devoted to showing (8.2). Recall that the input to the Transformer $Z_{0}$ is initialized as $Z_{0}=\begin{bmatrix}B^{\top}\\
\Psi^{\top}\\
0_{k\times n}\end{bmatrix}\in\mathbb{R}^{(d+2k)\times n}$. For some fixed $\delta$, our choice of parameter matrices will be the same across layers:

$$ $\displaystyle W^{V}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}0_{d\times d}&0_{d\times k}&0_{d\times k}\\ 0_{k\times d}&0_{k\times k}&0_{k\times k}\\ 0_{k\times d}&0_{k\times k}&{\color[rgb]{0,0,1}-\delta I_{k\times k}}\end{ bmatrix},\ {W^{Q}_{l}}^{\top}W^{K}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}{\color[rgb]{0,0,1}I_{d\times d}}&0_{d\times k}&0_ {d\times k}\\ 0_{k\times d}&0_{k\times k}&0_{k\times k}\\ 0_{k\times d}&0_{k\times k}&0_{k\times k}\end{bmatrix},\ W^{R}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}0_{d\times d}&0_{d\times k}&0_{d\times k}\\ 0_{k\times d}&0_{k\times k}&0_{k\times k}\\ 0_{k\times d}&{\color[rgb]{0,0,1}\delta I_{k\times k}}&0_{k\times k}\end{bmatrix}$ (8.3) $$

By the choice of $W^{V},W^{R}$ in (8.3), we verify that for all layers $l$, $B_{l}=B_{0}=B$, so that $Z_{l}^{\top}(W^{Q}_{l})^{\top}W^{K}_{l}Z_{l}={\mathcal{L}}$. Again by choice of $W^{V},W^{R}$ in (8.3), $\Lambda_{l}=\Psi$ for all $l$. It thus follows from induction that

$$ $\displaystyle\Phi_{l+1}=\Phi_{l}-\delta{\mathcal{L}}\Phi_{l}+\delta\Psi$ (8.4) $\displaystyle\Leftrightarrow\qquad$ $\displaystyle\phi_{l+1,i}=\phi_{l,i}-\delta{\mathcal{L}}\phi_{l,i}+\delta\psi_ {i}=\phi_{l,i}-\delta\nabla F_{\psi_{i}}(\phi_{l,i})\qquad\qquad\text{for $i=1 ...k$},$ $$

thus proving (8.2).

∎

###### Proof of Primal Dual Equivalence for Electric Flow.

###### Proof of Lemma 1 .

### 8.2 Resistive Embedding

###### Proof of Lemma 2 .

Let $\hat{I}:=I_{n\times n}-\frac{1}{n}\vec{1}\vec{1}^{\top}$. Let $\delta:=1/\lambda_{\max}$.

Consider the matrix power series, which converges under our choice of $\delta$:

$$ $\displaystyle\sqrt{{\mathcal{L}}^{\dagger}}=\sqrt{\delta}\sqrt{{\left(\hat{I}- (\hat{I}-\delta{\mathcal{L}})\right)}^{\dagger}}=\sqrt{\delta}\sum_{l=0}^{ \infty}{2l\choose l}\frac{{\left(I-\delta{\mathcal{L}}\right)}^{l}}{4^{l}}\hat {I},$ $$

where the second inequality uses the fact that ${\left(I-\delta{\mathcal{L}}\right)}\hat{I}={\left(\hat{I}-\delta{\mathcal{L}}
\right)}\hat{I}$.

We define $\alpha_{l}:=\sqrt{\delta}{2l\choose l}\frac{1}{4^{l}}$.

$$ $\displaystyle W^{V}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}0_{d\times d}&0_{d\times k}&0_{d\times k}\\ 0_{k\times d}&{\color[rgb]{0,0,1}-\delta I_{k\times k}}&0_{k\times k}\\ 0_{k\times d}&0_{k\times k}&0_{k\times k}\end{bmatrix},\ {W^{Q}_{l}}^{\top}W^{ K}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}{\color[rgb]{0,0,1}I_{d\times d}}&0_{d\times k}&0_ {d\times k}\\ 0_{k\times d}&0_{k\times k}&0_{k\times k}\\ 0_{k\times d}&0_{k\times k}&0_{k\times k}\end{bmatrix},\ W^{R}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}0_{d\times d}&0_{d\times k}&0_{d\times k}\\ 0_{k\times d}&0_{k\times k}&0_{k\times k}\\ 0_{k\times d}&{\color[rgb]{0,0,1}\alpha_{l}I_{k\times k}}&0_{k\times k}\end{bmatrix}$ (8.5) $$

Define $Z_{l}=:\begin{bmatrix}B_{l}^{\top}\\
\Lambda_{l}\\
\Phi_{l}^{\top}\end{bmatrix}$. We verify that for all $l$, $B_{l}=B$, and

$$ $\displaystyle\Lambda_{l+1}={\left(I-\delta{\mathcal{L}}\right)}\Lambda_{l}={ \left(I-\delta{\mathcal{L}}\right)}^{l}$ $\displaystyle\Phi_{l+1}=\Phi_{l}+\alpha_{l}\Lambda_{l}=\sum_{i=0}^{l}\alpha_{i }(I-\delta{\mathcal{L}})^{i}\hat{I}\Psi,$ $$

where we use the fact that $\Psi=\hat{I}\Psi$ by assumption. Therefore,

$$ $\displaystyle{\left\|{\left[Z\right]}_{L,i}^{\top}-\sqrt{{\mathcal{L}}^{ \dagger}}\psi_{i}\right\|}_{2}\leq{\left\|\sum_{i=L}^{\infty}\alpha_{i}(\hat{I }-\delta{\mathcal{L}})^{i}\right\|}_{2}{\left\|\psi_{i}\right\|}_{2}$ $$

By upper and lower bounds of Stirling’s formula $\sqrt{2\pi L}L^{L}e^{-L}\leq L!\leq e\sqrt{L}L^{L}e^{-L}$, we can bound $\alpha_{L}\leq\sqrt{\delta/L}$. Using the fact that $(\hat{I}-\delta{\mathcal{L}})\prec{\left(I-\delta\lambda_{min}\right)}\hat{I}
\prec e^{-\delta\lambda_{min}}\hat{I}$, and using the bound on gemetric sum, the above is bounded by $\frac{e^{-L\delta\lambda_{\min}}}{\lambda_{\min}\sqrt{\delta L}}{\left\|\psi_{
i}\right\|}_{2}$. The conclusion follows by plugging in $\delta=1/\lambda_{\max}$.
∎

###### Proof of Lemma 2 .

### 8.3 Heat Kernel

###### Proof of Lemma 3 .

The power series for $e^{-s{\mathcal{L}}}$ is given by

$$ $\displaystyle e^{-s{\mathcal{L}}}=\sum_{l=0}^{\infty}\frac{(-s)^{l}{\mathcal{L }}^{l}}{l!}.$ $$

We define $\alpha_{l}:=\frac{(-s)^{l}}{l!}$. For each layer $l$, define

$$ $\displaystyle W^{V}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}0_{d\times d}&0_{d\times k}&0_{d\times k}\\ 0_{k\times d}&{\color[rgb]{0,0,1}I_{k\times k}}&0_{k\times k}\\ 0_{k\times d}&0_{k\times k}&0_{k\times k}\end{bmatrix},\ {W^{Q}_{l}}^{\top}W^{ K}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}{\color[rgb]{0,0,1}I_{d\times d}}&0_{d\times k}&0_ {d\times k}\\ 0_{k\times d}&0_{k\times k}&0_{k\times k}\\ 0_{k\times d}&0_{k\times k}&0_{k\times k}\end{bmatrix},\ W^{R}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}0_{d\times d}&0_{d\times k}&0_{d\times k}\\ 0_{k\times d}&{\color[rgb]{0,0,1}-I_{k\times k}}&0_{k\times k}\\ 0_{k\times d}&{\color[rgb]{0,0,1}\alpha_{l}I_{k\times k}}&0_{k\times k}\end{bmatrix}$ $$

Define $Z_{l}=:\begin{bmatrix}B_{l}^{\top}\\
\Lambda_{l}\\
\Phi_{l}^{\top}\end{bmatrix}$. We verify that for all $l$, $B_{l}=B$, and

$$ $\displaystyle\Lambda_{l+1}={\mathcal{L}}\Lambda_{l}={\mathcal{L}}^{l+1}\Psi$ $\displaystyle\Phi_{l+1}=\Phi_{l}+\alpha_{l}\Lambda_{l}=\sum_{i=0}^{l}\alpha_{i }{\mathcal{L}}^{i}\Psi.$ $$

Therefore,

$$ $\displaystyle{\left\|{\left[Z\right]}_{L,i}^{\top}-e^{-s{\mathcal{L}}}\psi_{i} \right\|}_{2}\leq{\left\|\sum_{i=L+1}^{\infty}\alpha_{i}{\mathcal{L}}^{i} \right\|}_{2}{\left\|\psi_{i}\right\|}_{2}$ $$

By lower bound of Stirling’s formula, $L!\geq{\left(L/e\right)}^{L}$. Therefore, for $L\geq 8s\lambda_{\max}$, we have ${\left\|\alpha_{L}{\mathcal{L}}^{L}\right\|}_{2}\leq 2^{-L+8s\lambda_{\max}}$. For $L\geq 2$, the infinite sum is within a factor 2 of the first term, thus ${\left\|\sum_{i=L+1}^{\infty}\alpha_{i}{\mathcal{L}}^{i}\right\|}_{2}\leq 2^{-
L+8s\lambda_{\max}+1}$.
∎

###### Proof of Lemma 3 .

### 8.4 Faster Constructions

###### Proof of Lemma 4 .

We begin by recalling the Taylor expansion of ${\mathcal{L}}^{\dagger}$:

$$ $\displaystyle{\mathcal{L}}^{\dagger}=\delta\sum_{l=0}^{\infty}{\left(\hat{I}- \delta{\mathcal{L}}\right)}^{l}.$ $$

(recall that $\hat{I}:=I_{n\times n}-\vec{1}\vec{1}^{\top}/n$). Our proof of this section uses a simple but powerful alternative expansion (see for example Peng and Spielman ()): for any integer $t$,

$$ $\displaystyle\delta\prod_{l=0}^{t}{\left(I+{\left(\hat{I}-\delta{\mathcal{L}} \right)}^{2^{l}}\right)}=\delta\sum_{l=0}^{2^{t}}(\hat{I}-\delta{\mathcal{L}}) ^{l}.$ (8.6) $$

Notice that $t$ terms in the LHS equals $2^{t}$ terms of the RHS. This is exactly why we will get a doubly exponential convergence. As seen in the proof of Lemma 1, each term in the RHS of (8.6) coincides with one step of gradient descent. Therefore, if one layer of the Transformer can implement one additional product on the LHS, a $L$ layer Transformer can efficiently implement $2^{L}$ steps of gradient descent. In the remainder of the proof, we will show exactly this.
For all layers $l$, let

$$ $\displaystyle W^{V}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}{\color[rgb]{0,0,1}I_{n\times n}}&0_{n\times n}&0_ {n\times n}\\ 0_{n\times n}&0_{n\times n}&0_{n\times n}\\ {\color[rgb]{0,0,1}I_{n\times n}}&0_{n\times n}&0_{n\times n}\end{bmatrix},\ { W^{Q}_{l}}^{\top}W^{K}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}0_{n\times n}&0_{n\times n}&0_{n\times n}\\ {\color[rgb]{0,0,1}I_{n\times n}}&0_{n\times n}&0_{n\times n}\\ 0_{n\times n}&0_{n\times n}&0_{n\times n}\end{bmatrix},\ W^{R}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}{\color[rgb]{0,0,1}-I_{n\times n}}&0_{n\times n}&0 _{n\times n}\\ 0_{n\times n}&0_{n\times n}&0_{n\times n}\\ 0_{n\times n}&0_{n\times n}&0_{n\times n}\end{bmatrix}.\$ $$

Let $Z_{l}^{\top}=:\begin{bmatrix}\Gamma_{l},&\Lambda_{l},&\Phi_{l}\end{bmatrix}$, where $\Gamma_{l},\Lambda_{l},\Phi_{l}\in\mathbb{R}^{n\times n}$. Under the configuration of weight matrices above, we verify that $\Lambda_{l}=I_{n\times n}$ for all $l$, and thus $Z_{l}^{\top}{W^{Q}_{l}}^{\top}W^{K}_{l}Z_{l}=\Lambda_{l}\Gamma_{l}^{\top}=
\Gamma_{l}$. for all $l$. Next, we verify by induction that $\Gamma_{l+1}=\Gamma_{l}-\Gamma_{l}+\Gamma_{l}^{\top}\Gamma_{l}=\Gamma_{l}^{
\top}\Gamma_{l}={\left(\hat{I}-\delta{\mathcal{L}}\right)}^{2^{l}}$. Note that $\Gamma_{l}$ is symmetric.

Finally, we verify that $\Phi_{l+1}=\Phi_{l}+\Gamma_{l}^{\top}\Phi_{l}={\left(I+{\left(\hat{I}-\delta{
\mathcal{L}}\right)}^{2^{l}}\right)}\Phi_{l}$. Thus by induction,

$$ $\displaystyle\Phi_{L}=\delta\prod_{i=0}^{L}{\left(I+(\hat{I}-\delta{\mathcal{L }})^{2^{i}}\right)}.$ $$

Finally, again using (8.6), the residual term is given by

$$ $\displaystyle{\mathcal{L}}^{\dagger}-\Phi_{L}=\delta\sum_{i=2^{L}+1}^{\infty}{ \left(\hat{I}-\delta{\mathcal{L}}\right)}^{i}.$ $$

Noting that $(\hat{I}-\delta{\mathcal{L}})\prec(1-\delta\lambda_{\min}{\mathcal{L}})\hat{I}$, we can bound

$$ $\displaystyle{\left\|{\mathcal{L}}^{\dagger}-\Phi_{L}\right\|}_{2}\leq\frac{ \exp{\left(-2^{L}\delta\lambda_{\min}\right)}}{\lambda_{\min}}$ $$

∎

###### Proof of Lemma 5 .

Let $C:=3^{L}$. We will use the bound

$$ $\displaystyle{\left(I-s{\mathcal{L}}/C\right)}^{C}\prec e^{-s{\mathcal{L}}} \prec{\left(I-s{\mathcal{L}}/C\right)}^{C}{\left(I-s^{2}{\mathcal{L}}^{2}/C \right)}^{-1}\prec{\left(I-s{\mathcal{L}}/C\right)}^{C}{\left(I+2s^{2}{ \mathcal{L}}^{2}/C\right)},$ $$

where the second inequality holds by our assumption that $s\lambda_{max}<1/C$. Therefore,

$$ $\displaystyle{\left\|{\left(I-s{\mathcal{L}}/C\right)}^{C}-\exp(-s{\mathcal{L} })\right\|}_{2}\leq\frac{2s^{2}{\mathcal{L}}^{2}}{C}{\left\|\exp(-s{\mathcal{L }})\right\|}_{2}\leq\frac{2s^{2}\lambda_{\max}^{2}}{C}.$ $$

We will now show that $Z_{L}={\left(I-s{\mathcal{L}}/C\right)}^{C}$. Let us define, for all $l$,

$$ $\displaystyle W^{V}_{l}$ $\displaystyle=I_{n\times n},\qquad{W^{Q}_{l}}^{\top}W^{K}_{l}=I_{n\times n}, \qquad W^{R}_{l}=-I_{n\times n}.$ $$

Then we verify that $Z_{l+1}=Z_{l}-Z_{l}+Z_{l}Z_{l}^{\top}Z_{l}=Z_{l}^{3}$ (by symmetry of $Z_{l}$). Thus by induction, $Z_{l}=Z_{0}^{3^{l}}={\left(I-s{\mathcal{L}}/C\right)}^{3^{l}}={\left(I-s{
\mathcal{L}}/C\right)}^{C}$.

∎

###### Proof of Lemma 4 .

###### Proof of Lemma 5 .

## 9 Proofs for Section 4

###### Lemma 8 (Single Index Orthogonalization) .

Consider the same setup as Lemma 6, with Transformer defined in (4.1). Let $\phi_{l,j}\in\mathbb{R}^{n}$ denote the $j^{th}$ column of $\Phi_{l}$. For any $i=1...k$, there exists a choice of $W^{V},W^{Q},W^{K},W^{R}$, such that

$$ $\displaystyle\hat{\phi}_{l+1,i}=\phi_{l,i}-\sum_{j=i+1}^{k}\bm{\left\langle} \phi_{l,i},\phi_{l,j}\bm{}\phi_{l,j},\qquad\qquad{\phi}_{l+1,i}=\frac{\hat{ \phi}_{l+1,i}}{{\left\|\hat{\phi}_{l+1,i}\right\|}_{2}},$ $$

and for any $j\neq i$,

$$ $\displaystyle\phi_{l+1,j}=\phi_{l,j}.$ $$

###### Proof of Lemma 8 .

Recall that $Z_{l}^{\top}=:\begin{bmatrix}B_{l},&\Phi_{l}\end{bmatrix}$. Let $A\in\mathbb{R}^{k\times k}$ denote the matrix where $A_{ii}=1$ and is 0 0 everywhere else. Let $H$ denote the matrix where $H_{jj}=1$ for all $j>i$, and is 0 0 everywhere else. Let the weight matrices be defined as

$$ $\displaystyle W^{V}_{l}$ $\displaystyle=-$ $\displaystyle\begin{bmatrix}0_{d\times d}&0_{d\times k}\\ 0_{k\times d}&A\end{bmatrix},\qquad{W^{Q}_{l}}^{\top}W^{K}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}0_{d\times d}&0_{d\times k}\\ 0_{k\times d}&H\end{bmatrix},\qquad W^{R}$ $\displaystyle=$ $\displaystyle 0$ $$

Under the above definition, $B_{l}^{\top}=B^{\top}$ is a constant across all layers $l$. We verify that $\Phi_{l}$ evolves as

$$ $\displaystyle\Phi_{l+1}^{\top}=\Phi_{l}^{\top}-A\Phi_{l}^{\top}\Phi_{l}H\Phi_{ l}^{\top}.$ $$

We verify that the effect of left-multiplication by $A$ "selects the $i^{th}$ row of $\Phi_{l}^{\top}\Phi_{l}$" and the effect of right-multiplication by $H$ "selects the $(i+1)^{th}...k^{th}$ columns of $\Phi_{l}^{\top}\Phi_{l}$". Thus

$$ $\displaystyle A\Phi^{\top}\Phi H=\begin{bmatrix}&0&...&0&...&0\\ &\vdots&&\vdots&&\vdots\\ &0&...&\bm{\left\langle}\phi_{l,i},\phi_{l,j+1}\bm{}&...&\bm{\left\langle}\phi _{l,i},\phi_{l,k}\bm{}\\ &\vdots&&\vdots&&\vdots\\ &0&...&0&...&0\end{bmatrix}.$ $$

The conclusion can be verified by right-multiplying the above matrix with $\Phi_{l}^{\top}$, and then applying columnn-wise normalization to $\Phi_{l}$ (or equivalently, applying row-wise normalization to ${\left[Z\right]}_{d...d+k}$), as described in (4.1).
∎

###### Proof of Lemma 6 .

Recall that $Z_{l}=:\begin{bmatrix}B_{l}^{T}\\
\Phi_{l}^{\top}\end{bmatrix}$. Assume for now that $B_{l}=B$ for all layers $l$. Let $\phi_{l,i}$ denote the $i^{th}$ column of $\Phi_{l}$. Let $l$ be some fixed layer with weights

$$ $\displaystyle W^{V}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}0_{d\times d}&0_{d\times k}\\ 0_{k\times d}&{\color[rgb]{0,0,1}I_{k\times k}}\end{bmatrix},\qquad{W^{Q}_{l}} ^{\top}W^{K}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}{\color[rgb]{0,0,1}I_{d\times d}}&0_{d\times k}\\ 0_{k\times d}&0_{k\times k}\end{bmatrix},\qquad W^{R}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}I_{d\times d}&0_{d\times k}\\ 0_{k\times d}&{\color[rgb]{0,0,1}-I_{k\times k}}\end{bmatrix}.$ (9.1) $$

Combined with (4.1), these imply that $\hat{\Phi}_{l+1}={\mathcal{L}}\Phi_{l}$, and that $\phi_{l+1,i}={\phi_{l+1,i}}/{{\left\|\phi_{l+1,i}\right\|}_{2}}$. This implements the first step in the loop of Algorithm 1. Although Algorithm 1 does not contain the normalization step, the result is identical, because $QR(\Phi)$ is invariant to column-scaling of $\Phi$.

We now show a (different) configuration of weight matrices which enable a sequence of layers to perform QR decomposition: Consider the construction in Lemma 8. For each $i$, we can use a single layer to make $\phi_{l+1,i}$ orthogonal with to $\phi_{l,j}$ for all $j>i$. By putting $k$ such layers in sequence, we can ensure that $\phi_{l+k,i}$ is orthogonal to $\phi_{l+k,j}$ for all $i=1...k$ and for all $j=i+1...k$. Thus $\Phi_{l+k}$ is exactly the column-orthogonal matrix in a QR decomposition of $\Phi_{l}$.

Finally, we observe that $B_{l}$ is unchanged in both (9.1) and in the construction of Lemma 8. Thus we verify the assumption at the beginning of the proof that $B_{l}=B$ for all $l$. This concludes the proof.
∎

###### Proof of Corollary 7 .

The construction is almost identical to that in the proof of Lemma 6 above. The only difference is that we replace the weight configuration in (9.1) by

$$ $\displaystyle W^{V}_{l}$ $\displaystyle=$ $\displaystyle-\begin{bmatrix}0_{d\times d}&0_{d\times k}\\ 0_{k\times d}&{\color[rgb]{0,0,1}I_{k\times k}}\end{bmatrix},\qquad{W^{Q}_{l}} ^{\top}W^{K}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}{\color[rgb]{0,0,1}I_{d\times d}}&0_{d\times k}\\ 0_{k\times d}&0_{k\times k}\end{bmatrix},\qquad W^{R}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}I_{d\times d}&0_{d\times k}\\ 0_{k\times d}&{\color[rgb]{1,0,0}(\mu-1)I_{k\times k}}\end{bmatrix},$ $$

where the change is highlighted in red. Under this, we verify that $\hat{\Phi}_{l+1}=(\mu I-{\mathcal{L}})\Phi_{l}$.

The remainder of the proof, including construction for the $QR(\Phi)$ operation, are unchanged from Lemma 6.
∎

###### Lemma 8 (Single Index Orthogonalization) .

###### Proof of Lemma 8 .

###### Proof of Lemma 6 .

###### Proof of Corollary 7 .

## 10 Proofs for Section 5

###### Lemma 9 (Constructions under ( 5.1 )) .

The constructions in Lemmas 1, 2, 3 and 6 can be realized within the constrained dynamics (5.1).

###### Proof of Lemma 9 .

In general, we verify that (5.1) is equivalent to (2.3) with weights satisfying the following form:

$$ $\displaystyle W^{V}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}{\color[rgb]{1,0,0}\alpha^{V}_{l}I_{d\times d}}&0_ {d\times 2k}\\ 0_{2k\times d}&{\color[rgb]{1,0,0}W^{V,\Phi}_{l}}\end{bmatrix},\ W^{Q}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}{\color[rgb]{1,0,0}\alpha^{Q}_{l}I_{d\times d}}&0_ {d\times 2k}\\ 0_{2k\times d}&{\color[rgb]{1,0,0}W^{Q,\Phi}_{l}}\end{bmatrix},\ W^{K}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}{\color[rgb]{1,0,0}\alpha^{K}_{l}I_{d\times d}}&0_ {d\times 2k}\\ 0_{2k\times d}&{\color[rgb]{1,0,0}W^{K,\Phi}_{l}}\end{bmatrix},\ W^{R}_{l}$ $\displaystyle=$ $\displaystyle\begin{bmatrix}{\color[rgb]{1,0,0}\alpha^{R}_{l}I_{d\times d}}&0_ {d\times 2k}\\ 0_{2k\times d}&{\color[rgb]{1,0,0}W^{R,\Phi}_{l}}\end{bmatrix}.$ $$

Below, we state the weight configurations for (5.1) which will recover the constructions in each of the stated lemmas. Note that there is a small change in notation: $\Phi_{l}$ as defined in Section 5 corresponds to $[\Lambda_{l};\Phi_{l}]$ from the proofs of Lemmas 1, 2 and 3.

We leave the simple verification of this equivalence to the reader.

The construction in Lemma 1 is equivalent to (5.1) with weight configuration $\alpha_{l}^{V}=0$, $\alpha_{l}^{Q}=\alpha_{l}^{K}=1$, $\alpha_{l}^{R}=0$, $W^{V,\Phi}_{l}=\begin{bmatrix}0_{k\times k}&0_{k\times k}\\
{-\delta I_{k\times k}}&0_{k\times k}\end{bmatrix}$, ${W^{Q,\Phi}_{l}}=W^{K,\Phi}_{l}=0$, $W^{R}_{l}=\begin{bmatrix}0_{k\times k}&0_{k\times k}\\
{\delta I_{k\times k}}&0_{k\times k}\end{bmatrix}$.

The construction in Lemma 2 is equivalent to (5.1) with weight configuration $\alpha_{l}^{V}=0$, $\alpha_{l}^{Q}=\alpha_{l}^{K}=1$, $\alpha_{l}^{R}=0$, $W^{V,\Phi}_{l}=\begin{bmatrix}-\frac{1}{\lambda_{\max}}I_{k\times k}&0_{k
\times k}\\
{0_{k\times k}}&0_{k\times k}\end{bmatrix}$, ${W^{Q,\Phi}_{l}}=W^{K,\Phi}_{l}=0$, $W^{R}_{l}=\begin{bmatrix}0_{k\times k}&0_{k\times k}\\
{\frac{1}{\lambda_{\max}}I_{k\times k}}&0_{k\times k}\end{bmatrix}$.

The construction in Lemma 3 is equivalent to (5.1) with weight configuration $\alpha_{l}^{V}=0$, $\alpha_{l}^{Q}=\alpha_{l}^{K}=1$, $\alpha_{l}^{R}=0$, $W^{V,\Phi}_{l}=\begin{bmatrix}I_{k\times k}&0_{k\times k}\\
{0_{k\times k}}&0_{k\times k}\end{bmatrix}$, ${W^{Q,\Phi}_{l}}=W^{K,\Phi}_{l}=0$, $W^{R}_{l}=\begin{bmatrix}-I_{k\times k}&0_{k\times k}\\
\frac{(-s)^{l}}{l!}I_{k\times k}&0_{k\times k}\end{bmatrix}$, where $s$ is the temperature parameter.

The construction in Lemma 6 is equivalent to (5.1) with the following weight configurations:

- 1.
To implement the first step inside the loop of Algorithm 1, let $\alpha_{l}^{V}=0$, $\alpha_{l}^{Q}=\alpha_{l}^{K}=1$, $\alpha_{l}^{R}=0$, $W^{V,\Phi}_{l}=\begin{bmatrix}0_{k\times k}&0_{k\times k}\\
{0_{k\times k}}&I_{k\times k}\end{bmatrix}$, ${W^{Q,\Phi}_{l}}=W^{K,\Phi}_{l}=0$, $W^{R}_{l}=\begin{bmatrix}0_{k\times k}&0_{k\times k}\\
{0_{k\times k}}&-I_{k\times k}\end{bmatrix}$.
- 2.
To implement the QR decomposition step inside the loop of Algorithm 1, we will need to an equivalent construction as in Lemma 8. Let $\alpha_{l}^{V}=0$, $\alpha_{l}^{Q}=\alpha_{l}^{K}=1$, $\alpha_{l}^{R}=0$, and let $W^{V,\Phi}_{l}=\begin{bmatrix}0_{k\times k}&0_{k\times k}\\
{0_{k\times k}}&A\end{bmatrix}$, ${W^{Q,\Phi}_{l}}^{\top}W^{K,\Phi}_{l}=\begin{bmatrix}0_{k\times k}&0_{k\times k
}\\
{0_{k\times k}}&H\end{bmatrix}$, $W^{R}_{l}=0$, where $A$ and $H$ are as defined in the proof of Lemma 8.

∎

###### Lemma 10 (Invariance and Equivariance) .

Let ${\sf TF}^{B}_{l}$ and ${\sf TF}^{\Phi}_{l}$ be as defined in Section 5. Let $U\in\mathbb{R}^{d\times d}$ be any permutation matrix. Then for all layers $l$,

$$ $\displaystyle{\sf TF}^{B}_{l}(BU,\Phi)=U^{\top}{\sf TF}^{B}_{l}(B,\Phi)$ $\displaystyle{\sf TF}^{\Phi}_{l}(BU,\Phi)={\sf TF}^{\Phi}_{l}(B,\Phi)$ (10.1) $$

###### Proof of Lemma 10 .

We will prove these two claims by induction simultaneously. Recall from (5.1) that

$$ $\displaystyle B_{l+1}^{\top}=(1+\alpha_{R,l})B_{l}^{\top}+\alpha_{V,l}B_{l}^{ \top}{\left(\alpha_{Q,l}\alpha_{K,l}B_{l}B_{l}^{\top}+\Phi_{l}{W_{l}^{Q,\Phi}} ^{\top}W_{l}^{K,\Phi}\Phi_{l}^{\top}\right)}$ $\displaystyle\Phi_{l+1}^{\top}={\left(I+W_{l}^{R,\Phi}\right)}\Phi_{l}^{\top}+ W_{l}^{V,\Phi}\Phi_{l}^{\top}{\left(\alpha_{Q,l}\alpha_{K,l}B_{l}B_{l}^{\top}+ \Phi_{l}{W_{l}^{Q,\Phi}}^{\top}W_{l}^{K,\Phi}\Phi_{l}^{\top}\right)}.$ $$

Recall from the definition that ${\sf TF}^{B}_{0}(B,\Phi):=B_{0}:=B$ and ${\sf TF}^{\Phi}_{l}(B,\Phi):=\Phi_{0}:=\Phi$. Thus (10.1) holds by definition. Now suppose (10.1) holds for some $l$. By (5.1),

$$ $\displaystyle{\sf TF}^{B}_{l+1}(BU,\Phi)$ $\displaystyle=$ $\displaystyle(1+\alpha_{R,l}){\sf TF}^{B}_{l}(BU,\Phi)$ $\displaystyle\quad+\alpha_{V,l}{\sf TF}^{B}_{l}(BU,\Phi){\left(\alpha_{Q,l} \alpha_{K,l}{\sf TF}^{B}_{l}(BU,\Phi)^{\top}{\sf TF}^{B}_{l}(BU,\Phi)\right)}$ $\displaystyle\quad+\alpha_{V,l}{\sf TF}^{B}_{l}(BU,\Phi){\left({\sf TF}^{\Phi} _{l}(BU,\Phi)^{\top}{W_{l}^{Q,\Phi}}^{\top}W_{l}^{K,\Phi}{\sf TF}^{\Phi}_{l}( BU,\Phi)\right)}$ $\displaystyle=$ $\displaystyle(1+\alpha_{R,l})U^{\top}{\sf TF}^{B}_{l}(B,\Phi)$ $\displaystyle\quad+\alpha_{V,l}U^{\top}{\sf TF}^{B}_{l}(B,\Phi){\left(\alpha_{ Q,l}\alpha_{K,l}{\sf TF}^{B}_{l}(B,\Phi)^{\top}{\sf TF}^{B}_{l}(B,\Phi)\right)}$ $\displaystyle\quad+\alpha_{V,l}U^{\top}{\sf TF}^{B}_{l}(B,\Phi){\left({\sf TF} ^{\Phi}_{l}(B,\Phi)^{\top}{W_{l}^{Q,\Phi}}^{\top}W_{l}^{K,\Phi}{\sf TF}^{\Phi} _{l}(B,\Phi)\right)}$ $\displaystyle=$ $\displaystyle U^{\top}{\sf TF}^{B}_{l+1}(B,\Phi),$ $$

where we use the fact that $UU^{\top}=I_{d\times d}$. By similar steps as above, we also verify that

$$ $\displaystyle{\sf TF}^{\Phi}_{l+1}(BU,\Phi)={\sf TF}^{\Phi}_{l+1}(B,\Phi).$ $$

This concludes the proof.
∎

###### Lemma 9 (Constructions under ( 5.1 )) .

###### Proof of Lemma 9 .

###### Lemma 10 (Invariance and Equivariance) .

###### Proof of Lemma 10 .

## 11 Details for Synthetic Experiments

We consider two ways of sampling random graphs:

- 1.
Fully Connected (FC) graphs: $n=10$ nodes and $d=45$ edges.
- 2.
Circular Skip Links (CSL) graphs: $n=10$ nodes and $d=20$ edges. The skip-length is sampled uniformly at random from $\left\{2,4,6,8\right\}$. See (Dwivedi et al., ) for a detailed definition of CSL graphs.

For both FC and CSL graphs, the resistance of an edge $e$ is $r(e)=e^{u(e)}$, where $u(e)$ is independently sampled uniformly from $[-2,2]$.

## 12 Details for Molecular Regression Experiment

Below, we provide various details for the molecular regression experiment in Section 6.

### 12.1 Dataset Details

For QM9, the training set size is 20,000, the validation set size is 2000, the test set size is 100,000. The training/validation set are subsampled from the full training/validation set. The average number of nodes is 8.79, and the average number of edges is 18.8.

For ZINC, the training set size is 20,000, the validation set size is 2000, the test set size is 24,445. The training/validation set are subsampled from the full training/validation set. The average number of nodes is 23.16, and the average number of edges is 39.83.

### 12.2 Architecture for Molecular Regression Experiment

The linear Transformer we use for the experiment in Section 6 is described in (12.1) below:

$$ $\displaystyle B_{l+1}^{\top}=(1+\alpha_{R,l})B_{l}^{\top}+\alpha_{V,l}B_{l}^{ \top}{\left({\color[rgb]{0,0,1}\beta_{l,1}}\alpha_{Q,l}\alpha_{K,l}{\color[rgb ]{1,0,0}D_{l}^{-1/2}}B_{l}B_{l}^{\top}{\color[rgb]{1,0,0}D_{l}^{-1/2}}+{\color [rgb]{0,0,1}\beta_{l,2}}\Phi_{l}{W_{l}^{Q,\Phi}}W_{l}^{K,\Phi}\Phi_{l}^{\top} \right)}$ $\displaystyle\Phi_{l+1}^{\top}={\left(I+W_{l}^{R,\Phi}\right)}\Phi_{l}^{\top}+ W_{l}^{V,\Phi}\Phi_{l}^{\top}{\left({\color[rgb]{0,0,1}\beta_{l,3}}\alpha_{Q,l }\alpha_{K,l}{\color[rgb]{1,0,0}D_{l}^{-1/2}}B_{l}B_{l}^{\top}{\color[rgb]{ 1,0,0}D_{l}^{-1/2}}+{\color[rgb]{0,0,1}\beta_{l,4}}\Phi_{l}{W_{l}^{Q,\Phi}}W_{ l}^{K,\Phi}\Phi_{l}^{\top}\right)}$ $\displaystyle B_{l+1}\leftarrow B_{l+1}/\|B_{l+1}\|_{F}$ $\displaystyle\phi_{l+1,i}\leftarrow\phi_{l+1,i}/\|\phi_{l+1,i}\|_{2}\qquad \qquad\text{(for i=1...k)}$ (12.1) $$

It is similar to the memory-efficient Transformer architecture (5.1) from Section 5, with a number of modifications which we explain below. Let the input to the transformer be $Z_{0}\in\mathbb{R}^{d+k}$, where $d$ denotes the number of edges, and $k$ is the dimension of learned features.

- 1.
Scaling by ${\color[rgb]{1,0,0}D^{-1}}$: The GT in Dwivedi and Bresson () uses eigenvectors of the *normalized Laplacian* $\bar{{\mathcal{L}}}:={D^{-1/2}}{\mathcal{L}}{D^{-1/2}}$, where $D$ is the diagonal matrix whose $i^{th}$ diagonal entry is given by ${\left[D\right]}_{ii}:=|{\mathcal{L}}_{ii}|=\sum_{j=1}^{d}{\left|B_{ij}\right|}$. To be consistent with this setup, we modify the dynamics in (5.1) to add the scaling by ${\color[rgb]{1,0,0}D_{l}^{-1/2}}$ on the part of the self-similarity matrix involving $B_{l}$, highlighted in red in (12.1), where $D_{l}$ is the diagonal matrix with the $i^{th}$ diagonal entry given by
$\displaystyle{\left[D_{l}\right]}_{ii}:=\sum_{j=1}^{d}{\left|B_{l}\right|}_{ij}.$
With this additional scaling in the dynamics, the same weight constructions in all the lemmas in this paper will compute the corresponding quantities for the normalized Laplacian $\bar{{\mathcal{L}}}$ instead. For instance, with the $D_{l}^{-1/2}$ scaling, the construction in Lemma 1 computes $\bar{{\mathcal{L}}}^{\dagger}$, and the construction in Lemma 6 computes the top-$k$ eigenvectors of $\bar{{\mathcal{L}}}$. This can be verified using the following two facts: First, in all our constructions, $\Phi_{l}$ interacts with $B_{l}$ only via the self-similarity matrix $B_{l}B_{l}^{\top}$. Second, $D^{-1/2}BB^{\top}D^{-1/2}=\bar{{\mathcal{L}}}$.
- 2.
Independently scaled similarity matrix: For each layer $l$, we introduce additional scalar parameters ${\color[rgb]{0,0,1}\beta_{l,1},\beta_{l,2},\beta_{l,3},\beta_{l,4}}$. One layer of (12.1) is more expressive than one layer of (5.1) but less expressive than two layers of (5.1) (ignoring the difference due to $D^{-1/2}$).
- 3.
Diagonal constraints on $W$: We constrain $W^{V,\Phi},W^{Q,\Phi},W^{K,\Phi}$ to be diagonal, and $W^{R,\Phi}$ to be a scaling of identity.
- 4.
Weight sharing: Layers $3l,3l+1,3l+2$ share the same parameters, for all integers $l$. Phrased another way, each layer is looped 3 times.
- 5.
Per-layer Scaling: after each layer, we scale $B_{l}$ to have Frobenius norm 1, and we scale each column of $\Phi_{l}$ to have Euclidean norm 1.

Items 2-4 are useful for reducing the parameter count and improving generalization. Item 5 makes training feasible for deeper layers. The construction in Lemma 4 for subspace iteration can still be realised under the changes in items 2-5. Under the change in item 1, the construction in Lemma 4 will find eigenvectors of $\bar{{\mathcal{L}}}$ instead of ${\mathcal{L}}$.

### 12.3 Experiment Details

The GT we use has 128 hidden dimensions, 8 heads, and 4 layers. The position encoding dimension is $3$ for QM9, and $6$ for ZINC.

The linear Transformer we use contain $L=9$ layers, with parameters shared every 3 layers, as described in Section 12.2. The dimension of $\Phi_{l}$ is $8$. We use a linear map, with parameters $M$, to project $\Phi_{L}$ down to the PE dimension (PE_dim=3 for QM9 and PE_dim=6 for ZINC). This output is then passed to the GNN in the same way as the LapPE. To clarify the three models, we provide pseudo-code for Graph Transformer, Graph Transformer + LapPE and Graph Transformer + linear Transformer below:

Let GT denote the graph transformer from (Dwivedi and Bresson, ). Let $G$ denote the collection of basic graph information, including edge list, edge features, and node features. Let LapPE(G) return the Laplacian eigenvector positional encoding for $G$. Let $B$ be the incidence matrix of $G$. Let LT denote the linear Transformer, which takes $B$ as input ($\Phi_{0}$ can be viewed as internal parameters of LT)

Then the predictions for each model in Table 2 are given by

$$ Graph Transformer $\displaystyle\texttt{GT}(G,\texttt{None})$ Graph Transformer + LapPE $\displaystyle\texttt{GT}(G,\texttt{LapPE}(G))$ Graph Transformer + linear Transformer $\displaystyle\texttt{GT}(G,\texttt{linear}(M,\texttt{LT}(B)))$ (12.2) $$

The trainable parameters are given by

$$ {all the parameters of GT } + {all the parameters of LT } $\displaystyle=$ $\displaystyle\text{\{all the parameters of {GT}\} + \{$M$, $\Phi_{0}$, ${\left (\text{$\alpha$'s, $\beta$'s, $W$'s from \eqref{e:z_dynamics_molecule}}\right) }$\}}.$ $$

Before training on the actual regression task, we pretrain the linear Transformer to return the top PE_dim Laplacian eigenvectors. This gives a good initialization, and improves the optimization landscape.

We train using AdamW. Graph Transformer parameters are updated with initial 0.001 lr. Linear Transformer parameters are updated with initial 0.01 lr. For ZINC, we train for 2000 epochs with lr halved every 800 epochs. For QM9, we train for 1000 epochs with lr halved ever 400 epochs. The means and standard deviations in Table 2 are each computed over 4 independent seeded runs.

## Peer Reviews

confidence: 4
contribution: 2
initial_rating: 5
presentation: 3
questions: Please address the points raised in the previous section.
soundness: 2
strengths: **Originality**: This paper introduces a novel use of a linear Transformer, to perform core graph algorithms like electric flow and eigenvector decomposition without explicit positional encodings. 

**Quality**: The paper offers rigorous theoretical analysis with explicit weight constructions and error bounds for each algorithm.

**Clarity**: The paper is well-organized, clearly written, and enjoyable to read.
summary: The paper investigates the capabilities of the linear Transformer when applied to graph data, particularly its ability to implement algorithms for core graph tasks without explicit positional encodings. The authors demonstrate that the linear Transformer, which uses the graph incidence matrix as input, can solve canonical problems like electric flow computation and eigenvector decomposition. Key contributions include explicit configurations for weight matrices, error bounds for each task, and empirical results validating theoretical findings on synthetic data.
weaknesses: 1. Since the paper’s contribution is primarily theoretical, providing a proof sketch under the main results would be highly beneficial. Additionally, a more detailed description of the weight matrices would enhance clarity.

2. The theoretical results are not particularly surprising given the use of a linear Transformer. Could these results also apply to GNNs?

3. The practical impact of the proposed approach is unclear, as the empirical results are limited compared to numerous existing works. For instance, the performance on the ZINC dataset is significantly lower than the state-of-the-art, with an error approximately twice as large.

---

confidence: 4
contribution: 3
initial_rating: 5
presentation: 3
questions: - How would the analysis be impacted if nonlinearity in self-attention was re-introduced? In order to "understand, at a mechanistic level, how the Transformer processes graph-structured data" (lines 32-33), we are expected to remove only non-essential elements of Transformer architecture (and nonlinearity seems to be a critical one). The linearity in the Transformer, means that if its operations are expanded for a number of layers we'll reduce to a simple matrix operator.
soundness: 3
strengths: - The idea is novel and appealing: using a transformer to compute the solution to a graph problem as part of the latent vectors in its node output representations adds another level of applicability of transformers well beyond language understanding or generation.

- Lemmas are well organized, follow similar themes and the narrative is smooth and clear.
summary: The authors introduce a simplified (linear) Transformer architecture (no softmax activation in self-attention layers) and use it to show (theoretically and empirically) that it can implement graph algorithms. In particular they present a series of lemmas providing bounds in approximating the solution to problems like flow and heat kernel computation, finding resistive embeddings and performing eigenvalue decomposition (assuming specific weight matrices). Their input encodings include the incidence matrix representation of the graph and then the approximate solution will land in a subset of columns in the output encodings' matrix,  after passing through a a number L of transformer layers (where L is decided by the target approximation error). A parameter efficient variant is also presented. The linear transformer is tested on a series of small graph instances of the problems (e.g. of the order of 10 nodes and 20 edges) and for learning a positional encoding (PE) for a molecular regression task.
weaknesses: - Removing the nonlinear softmax terms from standard transformer architecture, facilitates analysis but severely impacts the power of the model.

- Complexity of the approach is prohibitive: it can be O(n^4) and this explains their experimentation with very small synthetic graphs. Parameter efficient implementation is promising, but still the original idea is far from being scalable and thus practically testable beyond a couple of tens' of graph nodes.

---

confidence: 4
contribution: 2
initial_rating: 5
presentation: 2
questions: Q1. Can you elaborate on the practical implications of your findings (see W1)?

Q2. I think the eigenvectors you converge to have sign/basis ambiguities derived from the choice of $\Phi_0$. How do you deal with these ambiguities? Do you perform sign flipping at every forward pass?

Q3. I think denoting by $d$ the number of edges (Line 128) is a bit confusing, because $d$ is usually the embedding dimension. Also, in Equation 1, since $j= 1, \ldots, d$ is the first index of $B$, I think $B \in \mathbb{R}^{d \times n }$, but you wrote $B \in \mathbb{R}^{n \times d }$ (Line 132). Please clarify.
soundness: 3
strengths: The results are interesting. I particularly appreciated the structure of the paper, in which experimental results are shown after their corresponding theoretical claims instead of having them all the end, which highlights the connection between the presented theory and the experimental results.
summary: The paper shows that Linear Transformers (and their variant) using the incidence matrix can implement canonical problems, such as electric flow and subspace iteration. While the contribution is mainly theoretical, the authors also empirically validate their findings, and further show that on existing molecular datasets the linear transformer is capable of learning better performing positional encodings than standard laplacian eigenvectors.
weaknesses: W1. Generally speaking, I think the impact of the paper tends to be a bit limited. This is especially true because the considered architecture (linear Transformers), and in particular its variant which includes an L2 normalization, is not widely used. The main implication I can see is to use the variant of the linear transformer in place of existing predefined positional encodings, and therefore as an additional component of a bigger architecture.


W2. I find a bit confusing that the authors claim that the input to the Transformer is only the graph incidence matrix, without any other positional encoding (Lines 11-13), while for instance for the subspace iteration $\Phi_0$ is required to be some arbitrary column-orthogonal matrix. I think -- depending on the graph -- $\Phi_0$ might need to be a positional encoding to ensure all columns are orthogonal (note that if $\Phi_0$ is a random matrix then it is a positional encoding [Srinivasan and Ribeiro, 2020]). I think the authors need to clarify this point and adjust accordingly in the entire paper.


Srinivasan and Ribeiro, 2020. On the Equivalence between Positional Node Embeddings and Structural Graph Representations.

---

confidence: 2
contribution: 2
initial_rating: 6
presentation: 3
questions: * While the paper concerns two graph problems: electric flow and Laplacian eigenvector decomposition, why the title mentions only the first one?
soundness: 3
strengths: * The organisation of the paper is clear, it's easy to understand the main contribution of the paper. And mathematically, it's generally well-written.
* The idea of solving the traditional graph problem with a Transformer is novel. 
* For the proposed lemmas, the paper provides the relevant experiments which are quite nice.
summary: The papers show theoretically and empirically that the linear transformer can approximate the hypothesis function space of several graph problem (electric flow and Laplacian eigenvector decomposition). The authors also conduct a real-world experiment on molecular regression, in which positional encoding outputs by transformers are adopted.
weaknesses: * My main concern is that since the neural network is a universe approximator, it's not surprising that it (in this paper, even it concerns linear Transformer, which is more like in a polynomial function) can solve approximate the hypothesis function space of several graph problems. I wonder how the lemmas shown in the paper can provide us with more useful information.
* The paper lacks a conclusion section.
* The real-world experiment concerns only the Laplacian eigenvector decomposition, it would be nice to have another for the electric flow.
* See the questions.

Meta-review: The paper explores the application of linear Transformers to graph-structured data, demonstrating both theoretical and empirical capabilities in solving canonical graph problems such as electric flow and eigenvector decomposition. The authors provide explicit weight configurations, error bounds, and validate their theoretical claims through synthetic and real-world experiments, particularly focusing on learning positional encodings for molecular regression tasks. The strengths include originality and novelty, theoretical rigor, as well as synthetic experiments consistent with the theory. Suggestion for improvement include conducting more experiments against other PEs and on larger and more diverse datasets, and finding more graph applications for linear Transformers to broaden the impact.

Decision: Accept (Poster)