Understanding Transformer Reasoning Capabilities via Graph Algorithms

Authors: clayton  sanford
bahare  fatemi
ethan  hall
anton  tsitsulin
mehran  kazemi
jonathan  halcrow
bryan  perozzi
vahab  mirrokni
google  research
Venue: NeurIPS_cc_2024_Conference
Published: 2024-05-14 22:18:51

Abstract: Which transformer scaling regimes are able to perfectly solve different classes of algorithmic problems?   While tremendous empirical advances have been attained by transformer-based neural networks, a theoretical understanding of their algorithmic reasoning capabilities in realistic parameter regimes is lacking.  We investigate this question in terms of the network’s depth, width, and number of extra tokens for algorithm execution.  Our novel representational hierarchy separates 9 algorithmic reasoning problems into classes solvable by transformers in different realistic parameter scaling regimes.  We prove that logarithmic depth is necessary and sufficient for tasks like graph connectivity, while single-layer transformers with small embedding dimensions can solve contextual retrieval tasks. We also support our theoretical analysis with ample empirical evidence using the GraphQA benchmark.  These results show that transformers excel at many graph reasoning tasks, even outperforming specialized graph neural networks.

Main paper: 
 introduction: 
 The transformer neural network architecture, which was initially introduced for neural machine translation [6, 77] , quickly became the standard neural network architecture across many fields, powering recent breakthroughs in language modeling [20, 66, 12, 76, 3, 75, 67] , computer vision [21, 49] , and natural sciences [36, 53] . Across fields, transformers have superseded other architectures, surpassing them in downstream performance while maintaining reasonable computational footprint.How can we analyze reasoning capabilities of neural networks? One approach is to study algorithms executable with their internal representations. Neural algorithmic reasoning [30, 89, 34, 37, 78] is a field of research dedicated to exploring such capabilities. Algorithmic execution is desirable because models use it to generalize out-of-distribution [92, 46] and scale to larger problem sizes [93] .In this work, we focus on classes of transformers solving algorithmic reasoning problems on graphs. Why graph problems in particular? Recent research by Besta et al. [10] suggests that graphs are an ideal abstraction of complex reasoning with dependencies, including chain-of-thought [82] and its generalizations [86, 17, 41, 40] . Furthermore, we investigate graph reasoning in order to evaluate transformer capabilities compared to specialized models that explicitly capture the structure of data. Graph neural networks (GNNs) [72, 44, 28, 7, 15] offer strong baselines for algorithmic reasoning [79, 13] and comprehensive theoretical frameworks for their capabilities and limitations [51, 84] . The complexity of graph reasoning tasks varies greatly; some are easily solved by non-graph architectures and others require sophistication beyond standard GNNs [90] . This makes graph tasks a compelling testbed for both theoretical and empirical evaluations.While transformer-based models are commonly optimized for downstream performance [38, 32, 64] , theoretical investigations of transformer capabilities in realistic parameter regimes have been limited.v 1 v 2 v 3 v 4 v 5 v 6 v 7 v 8Graph G Task: Are v 2 and v 4 connected? v 1 v 2 v 3 v 4 v 5 v 6 v 7 v 8 v 1 , v 2 v 2 , v 3 v 3 , v 4 v 6 , v 7 v 6 , v 8 v 7 , v 8 v 2 , v 4Transformer f ∅ ∅ ∅ ∅ ∅ ∅ ∅ ∅ ∅ ∅ ∅ ∅ ∅ ∅ Yes Target f (X)Figure 1 : The graph encoding scheme employed in our theoretical and empirical analysis that presents a graph reasoning task (e.g. connectivity) as a tokenized input to a standard transformer model.We analyze the capabilities of standard transformer models to solve graph reasoning tasks by employing a graph tokenization scheme similar to [42] ; see Figure 1 for a graph encoding example. We generalize the insights of [71] -which established that graph connectivity can be computed in a more depth-efficient manner with transformers than GNNs-to broader families of graph reasoning tasks. We also study the representational impacts of blank tokens, which can be thought of as a theoretically-tractable version of either chain-of-thought prompting [82] , scratch space [61] , or pause/filler tokens [29, 65] .We conduct an extensive study of graph reasoning problems with transformers from both theoretical and empirical perspectives. We summarize our principal contributions as follows:1. We introduce a novel representational hierarchy of graph reasoning tasks that formalizes reasoning capabilities of transformers in several realistic parameter scaling regimes. This includes two graph reasoning task classes-which we refer to as the parallelizable and search tasks and include well-known algorithmic tasks like connectivity and shortest path respectively. 2. We prove that logarithmic-depth transformers are necessary and sufficient to solve parallelizable tasks in a highly parameter-efficient manner; similar constructions for search tasks employ much larger networks. We distinguish both of these classes from an easier family of problems-retrieval tasks, such as node count and edge existence-by showing that retrieval tasks can be efficiently computed by single-layer transformers, while parallelizable and search tasks cannot.Question: Do the main claims made in the abstract and introduction accurately reflect the paper's contributions and scope?Answer: [Yes] Justification: The empirical and theoretical claims discussed accurately represent the detailed theoretical analysis and the wide-ranging experimentation on graph reasoning benchmarks.Guidelines:• The answer NA means that the abstract and introduction do not include the claims made in the paper. • The abstract and/or introduction should clearly state the claims made, including the contributions made in the paper and important assumptions and limitations. A No or NA answer to this question will not be perceived well by the reviewers. • The claims made should match theoretical and experimental results, and reflect how much the results can be expected to generalize to other settings. • It is fine to include aspirational goals as motivation as long as it is clear that these goals are not attained by the paper. 
related work: 
 Fundamental capabilities of transformers. Early representational research [88, 62, 81] established the universality of transformers by simulating Turing machines step-by-step, albeit in an unrealistic polynomial-depth scaling regime. These universality results were extended to boundeddepth transformers with chain-of-thought tokens [56, 52] , but with a persistent gap between positive and negative results. A more fine-grained theoretical approach established the limitations of boundedsize transformers by relating them to threshold circuits, implying that L-complete tasks like graph connectivity are unsolvable by constant-depth transformers [55, 54, 57] . However, these circuit complexity reductions are not bidirectional and their positive results pertaining to classes of regular languages [31] reveal little about when tasks like connectivity can be expressed.The closest analytical framework to ours characterizes transformers as distributed computing protocols by quantifying the informational bandwidth of their self-attention units. This line of work sharply separates transformers from other architectures and provides width and depth separations [70, 71] . The ability of transformers to simulate finite-state automata in logarithmic depth provides a further roadmap for how transformers efficiently leverage parallel computation [48] .Recent work [18] similarly focuses on understanding the capabilities of transformers to solve graph algorithms, but they focus instead on looped transformers, where a constant-size transformer model is iterated up to a polynomial number of times in the size of the input graph. While their constructions for tasks like graph connectivity are more parameter-efficient than our own, this comes at the cost of a very high depth, which presents both run-time and learnability concerns. Our depth-efficient constructions emerge by simulating parallel graph algorithms, rather than well-known serial algorithms, such as Dijkstra's.Empirical analysis of transformer reasoning capabilities. Multiple empirical investigations explore the algorithmic capabilities of transformer-based models [91, 47, 46] . Graph reasoning problems have been used to evaluate capabilities of transformer-based LLMs [24, 80, 87, 74, 33] including works with graph-specific GNN adapters [14, 63] . In the empirical part of our study, we use the GraphQA dataset [24] -which was evaluated initially on LLM prompting appraoches and later on GNN-augmented prompts [62] -to validate our complexity hierarchy and compare transformers with GNNs and prompt-based LLMs on a selection of graph reasoning tasks.Transformers and graph neural networks. GNNs provide a useful benchmark for model expressivity on graph inputs. For instance, the inability of GNNs to efficiently solve "global structure" tasks like subgraph connectivity made evident by a connection to the CONGEST distributed computing model [51] . A further connection [59] to the Weisfeiler-Lehman (WL) isomorphism heuristic [83] captures the inability of feature-less GNNs to distinguish certain graph instances [84] . The featureless assumption is burdensome and representationally costly; GNNs with randomly intialized node features are known to be universal [2] . See Appendix D for a further discussion of the representational limitations of GNNs.Graph transformers [22, 68, 58] integrate the transformer architecture with graph-structured data.While GNNs can simulate the WL test [1] , transformers can simulate GNNs and exceed their WL limitations [90] ; they are strictly more expressive than 2-WL [42] . Despite our focus on standard transformers, our empirical results in Section 4 include comparisons to a wide range of GNNs.Question: Does the paper discuss the limitations of the work performed by the authors?Answer: [Yes]Justification: Theoretical limitations are discussed in the presentation of the results in Section 3 and detailed more comprehensively in Appendix A. We discuss limitations of experimental results in Section 4.Guidelines:• The answer NA means that the paper has no limitation while the answer No means that the paper has limitations, but those are not discussed in the paper. • The authors are encouraged to create a separate "Limitations" section in their paper.• The paper should point out any strong assumptions and how robust the results are to violations of these assumptions (e.g., independence assumptions, noiseless settings, model well-specification, asymptotic approximations only holding locally). The authors should reflect on how these assumptions might be violated in practice and what the implications would be. • The authors should reflect on the scope of the claims made, e.g., if the approach was only tested on a few datasets or with a few runs. In general, empirical results often depend on implicit assumptions, which should be articulated. • The authors should reflect on the factors that influence the performance of the approach.For example, a facial recognition algorithm may perform poorly when image resolution is low or images are taken in low lighting. Or a speech-to-text system might not be used reliably to provide closed captions for online lectures because it fails to handle technical jargon. • The authors should discuss the computational efficiency of the proposed algorithms and how they scale with dataset size. • If applicable, the authors should discuss possible limitations of their approach to address problems of privacy and fairness. • While the authors might fear that complete honesty about limitations might be used by reviewers as grounds for rejection, a worse outcome might be that reviewers discover limitations that aren't acknowledged in the paper. The authors should use their best judgment and recognize that individual actions in favor of transparency play an important role in developing norms that preserve the integrity of the community. Reviewers will be specifically instructed to not penalize honesty concerning limitations. 
we empirically validate our representational contrast by showing that transformers outperform: 
 GNNs on tasks that require the analysis of long-range dependencies, including parallelizable tasks like connectivity. Our experiments suggest that GNNs perform better on simpler tasks that require only local analysis of neighboring nodes in low sample-complexity regimes, benefiting from their well-aligned inductive bias.We provide our core result: a rigorous quantification of the hardness of graph reasoning tasks for transformer-based models. While graph reasoning tasks, like other algorithmic problems, can be categorized into well-known computational and circuit complexity classes (e.g. TC 0 , L, NL, NP, NP), the relationship between membership in these classes and the hardness of solving a task with a parameter-efficient neural network is not immediately obvious. Our hierarchy bridges the gap between these worst-case computational classes and the representational capabilities of bounded-size transformers of different parameter scaling regimes. These regimes include transformers whose depth L scales with the input sequence length N ; this contrasts with most theoretical results, which study on the constant-depth regime.Our positive and negative theoretical results employ the transformer model of [71] , which is presented in Appendix A.1 and assumes that the embedding dimension m grows less rapidly than than the sequence length N and that the multi-layer perceptrons (MLPs) are arbitrary functions. The result is a model of a transformer as a bounded-capacity communication protocol. In this model, arbitrary functions of each individual embedding vector can be computed, but the interactions between these vectors are restricted by the low-rank of the attention matrix. The relevance of this model is motivated by the rapid scaling in the context lengths of modern transformers in recent years and the high ratio of MLP parameter count to the embedding dimension each operates on.This model also permits the inclusion of blank pause token inputs of [29] , which provide additional computational power to the transformer model by extending the computational "tape" without introducing new information about the input. These results divide the tasks that are we empirically investigate in Section 4 into three difficulty families based on the hardness of solving the task with parallel computation.Search1. Retrieval tasks-including node count, edge count, edge existence, and node degree-are tasks that can intuitively be solved by a single lookup step or global aggregation. These are the easiest tasks in our framework, and we show in Section 3.3 that these retrieval tasks can be computed by a single-layer transformer with small embedding dimension. (In contrast, all other examined tasks cannot be solved in that regime.) 2. Parallelizable tasks-including connectivity, connected nodes, and cycle check from the experimental results and a host of other graph reasoning tasks, such as bipartiteness, planarity, and minimum spanning forest-are non-trivial tasks that can be solved efficiently in a parallel computation setting. Section 3.1 establishes that these tasks can be solved by bounded-size transformers with logarithmic depth. 3. Search tasks-including shortest path and other tasks like diameter and directed reachabilitycomprise a harder family of tasks that are less easily solved by parallel algorithms. In Section 3.2, we prove that these tasks belong in an equivalence class and exhibit large-model scaling regimes where they can be computed.The representational hardness of these classes is quantified by several results that determine whether transformers that obey different parameter scaling rules can compute them. We define the following scaling regimes for the depth L, embedding dimension m, and number of "pause" tokens N of a family of transformers as a function of the size of the input graph, N = O(|V | + |E|).• Depth1 (D1): Single-layer multi-headed transformers with small embedding dimension m = O(log N ) without any pause tokens.• LogDepth (LD): Transformers with depth L = O(log N ), embedding dimension m = O(N ) for any fixed > 0, and no pause tokens.• LogDepthPause (LDP): Transformers with the same depth and width constraints as LogDepth, with at most N = poly(N ) blank "pause" tokens appended to the input sequence.• LogDepthWide (LDW): Transformers with depth L = O(log N ), embedding dimension m = O(N 1/2+ ), and no pause tokens.Our positive and negative results that relate scaling regimes and graph reasoning tasks are displayed in Figure 2 . We present high-level result summaries in the following sections with proofs in Appendix.The most technically significant results concern LogDepth models and are provided in Appendix B. These bounds are consequences of Theorem 1, an improved analysis of the relationship between transformers and the massively parallel computation (MPC) distributed computing model of [39] 2 . This connection between MPC and transformers is a sharp improvement of a similar result by [71] . Theorem 1 (Simplified version of Theorem 8). For constant δ, > 0, any R-round MPC protocol with N machines with O(N δ ) bits of local memory each can be simulated by a transformer of depth L = O(R) and embedding dimension m = O(N δ+ ).Results pertaining to Depth1 are stated in detail and proved in Appendix C. In addition, we discuss the triangle counting task (and the more general clique counting task) in Section 3.4, where we show a distinct result for much smaller depth (L = O(log log N )) that includes pause tokens.We define the family of parallelizable tasks to consist of graph reasoning tasks that are L-complete and are equivalent to graph connectivity in O(1)-rounds, as proved by [60] . This family includes (but is not limited to): graph connectivity, minimum spanning forest, cycle detection, st-connectivity, number of connected components, graph bipartiteness, planarity testing, and one-cycle vs two-cycles testing. While graph connectivity and minimum spanning forest were shown to be computable by logarithmic depth transformers with small polynomial width (LogDepth) by previous work [71] , this poses broader questions: Are all parallelizable graph reasoning tasks computable by a transformer of logarithmic depth and small embedding dimension? And do sub-logarithmic-depth transformers exist that solve any parallelizable tasks?We first show that all parallelizable tasks can be solved in two logarithmic-depth scaling settings. Theorem 2. For any parallelizable task, there exists transformers in LogDepthPause and LogDepthPause that solve the task.Theorem 2 is stated formally as Theorem 18 and proved in Appendix B.2.1. Both components of the theorem are a consequence of a novel relationship between the MPC model and transformers (Theorem 1) and the analysis of MPC protocols for graph reasoning tasks by [60] . The LogDepthPause result is the direct implication of an O(1)-round MPC equivalence (Theorem 9) between all parallelizable tasks and an MPC protocol that solves the connectivity task (Theorem 11). The LogDepthWide bound is a consequence of Theorem 15, which shows that all languages in NC 2 (including all languages in L and NL) can be evaluated by an MPC protocol with O(log N ) rounds and with local memory O(N 1/2+ ) [60] .We further prove the conditional optimality of logarithmic depth. Theorem 3. Conditional on Conjecture 13, any transformer that solves some parallelizable task with width mH = O(N ) and pause tokens N = poly(N ) must have depth L = Ω(log N ).This result (stated formally as Theorem 19 is a combination of the conditional depth lower bound on graph connectivity by [71] and the O(1)-round equivalence between all parallel tasks.Search tasks are similarly defined to be those that are NL-complete and equivalent to shortest path in O(1)-rounds of MPC and include shortest path, strong connectivity, st-reachability, radius, diameter, and median. Like before, the O(1)-round MPC equivalence translates to an O(1)-depth equivalence in transformers. We give a similar positive result for LogDepthWide transformers; whether these tasks can be solved by LogDepthPause transformers is unknown. Theorem 4. For any search task, there exists a transformer in LogDepthWide that sovles the task.This theorem, which is restated in Appendix B.2.2 as Theorem 21, is also an immediate consequence of Theorem 15.While the minimum depth of a transformer with small embedding dimension that solves a search task is not identified, we prove that the minimum depth needed to solve some all search task is approximately equivalent in Theorem 22.Graph tasks whose algorithms consist of a single look-up or aggregation step can be efficiently solved by single-layer transformers. This result assumes that the graph G = (V , E) is encoded as some input sequence X of length N = O(|V | + |E|) that expresses each edge and vertex a single token. This encoding scheme is detailed in Appendix C. Theorem 5. For any retrieval task (including node count, edge count, edge existence, and node degree) there exists a transformer in Depth1 that solves the task.We formalize this statement in Theorem 36 and prove it their in Appendix C.1. These rely on proving the existence of a useful input MLP φ that precomputes embeddings with useful structure for all retrieval tasks.In contrast, we show that a collection of parallelizable and search tasks cannot be efficiently solved by transformers in Depth1. Theorem 6. Any single-layer transformer that solves the graph connectivity, shortest path, or cycle detection task has width satisfying mH = Ω(N ).The proof of the formal counterpart of this statement (Theorem 38) appears in Appendix C.2 and is a consequence of a standard communication complexity argument. A more generalized result than Theorem 6 was proved by [57] , which establishes that all problems outside of NC 1 -which include all L-complete and NL-complete languages, and hence, all parallelizable and search tasks-cannot be solved by constant-depth transformers with polynomial width because they cannot be computed by TC 0 (constant-depth threshold circuits). We nonetheless include this theorem to demonstrate a clean lower bound that applies to very simple input graph instances.We finally construct depth-efficient transformers for triangle counting due to the MPC algorithms of [11] . Unlike previous positive results, which applied uniformly across all graphs instances of bounded size, the complexity of the corresponding transformers for triangle counting is a function of the arboricity3 of the input graph. When the arboricity grows sub-polynomially with N -as is the case for bounded-degree graphs-no pause tokens are necessary. Unlike the parallelizable and search classes of problems, strictly sub-logarithmic depth is attainable with pause tokens, even for worst-case graphs. Theorem 7. There exists a transformer that computes the number of triangles in any input graph of arboricity α and has embedding dimension m = O(N ), depth L = O(log log N ), and pause tokensN = O(αN 1-) if α = Ω(N ) 0 otherwise.This result is a special case of Theorem 23, a more general result about clique counting that appears in Appendix B.2.3.Theoretical conclusions. These results provide a tight characterization of the the reasoning capabilities of transformers whose depth, width, and input padding conform to different scaling regimes. They strengthen the established connection between transformers and massively parallel computation (MPC) [71] and generalize the resulting representational bounds to broader categories of graph tasks. We conclude that the logarithmic-depth regime is apt for for considering tasks in L and NL, which had previous illuminated the limitations of transformers with constant depth and a limited number of chain-of-thought tokens [56] . While expressivity does not imply learnability, these theoretical benchmarks sharply characterize the fundamental limitations of transformers and coincide with experimental results conveyed in the subsequent section.Our theoretical model of a transformer has certain limitations, namely the universality of the multilayer perceptron units. When maximally exploited (e.g. by solving NP-hard problems within each MLP), this assumption exaggerates the computational capabilities of transformers. However, the local computational complexity of the MPC algorithms employed in this paper tend to be strongly sublinear in the size of the graph input (see, e.g. the connectivity algorithms of Andoni et al. [4] ), which implies the existence of compact ReLU circuits for each of the model's MLPs. Furthermore, the ratio of model parameters that belong to MLPs in state-of-the-art language modelsis known to be high, which suggests that it is reasonable to assume that MLP units in our theoretical model are algorithmically rich. We would be interested in pursuing further theoretical research that combine the computational model [54] and the communication model of [71] to assess the capabilities of transformers whose MLPs are represented as bounded-size boolean circuits.The last class of model are task-specific vanilla transformer models [77] . The 60M transformer-1K model is the one described above trained on 1, 000 training examples from the GraphQA training set. To investigate the impact of training data scale, we generated a larger dataset containing 100, 000 examples, ensuring the same distribution as the original training set by using the official GraphQA code and trained 60M transformer-100K on that. The 11B transformer (FT)-1K is a vanilla transformer model that is started with a pre-trained checkpoint of T5 [66] and is fine-tuned on the 1K training dataset. We also include two fine-tuned PaLM 2 [5] transformers of size XXS and XS. Similar to prompting baselines, this model receives a textual description of the graph as input to leverage its textual reasoning capabilities.The results for ZERO-SHOT, ZERO-COT, FEW-SHOT, COT, and COT-BAG are taken from Fatemi et al. [24] . Results for SOFT-PROMPT and GraphToken are sourced from Perozzi et al. [63] .We independently evaluated GCN, MPNN, and GIN models on these tasks. We used the original architectures proposed in their respective papers and performed hyperparameter tuning on the GraphQA Dev dataset. obtained the full accuracy on most of such tasks. One exception here is the node degree task that GNNs outperform transformers but still transformers perform relatively well. We discuss why GNNs outperform transformers well for this task.• The factors of variability that the error bars are capturing should be clearly stated (for example, train/test split, initialization, random drawing of some parameter, or overall run with given experimental conditions). • The method for calculating the error bars should be explained (closed form formula, call to a library function, bootstrap, etc.) • The assumptions made should be given (e.g., Normally distributed errors). • It should be clear whether the error bar is the standard deviation or the standard error of the mean. • It is OK to report 1-sigma error bars, but one should state it. The authors should preferably report a 2-sigma error bar than state that they have a 96% CI, if the hypothesis of Normality of errors is not verified. • For asymmetric distributions, the authors should be careful not to show in tables or figures symmetric error bars that would yield results that are out of range (e.g. negative error rates). • If error bars are reported in tables or plots, The authors should explain in the text how they were calculated and reference the corresponding figures or tables in the text. 
empirical graph reasoning capabilities: 
 We further illuminate the reasoning capabilities of transformers by conducting an empirical investigation of the abilities of a variety of neural architecture and training settings to learn graph algorithmic tasks. We use the GraphQA benchmark tasks [24] for our experiments. We evaluate standard autoregressive transformers-both small models (at most 60M parameters) trained from scratch and fine-tuned (FT) T5-11B model (with 11B parameters) [66] . For the fine-tuned models, we explore task-specific fine-tuning-and contrast those results with graph neural networks (GNNs) and prompting-based methods on pre-trained LLMs.These experimental results validate key tenets of our theoretical results and demonstrate the utility of transformers' algorithmic reasoning capabilities. Our principal empirical conclusions are as follows:1. Transformers excel at global reasoning tasks. Transformers outperform GNNs on tasks that require efficiently aggregating information about distant nodes in a graph, such as connectivity and shortest path.2. GNNs uncover local graph structure with few samples. While transformers are capable of efficiently expressing all graph learning tasks under investigating, the structural limitations of GNNs provide them with favorable inductive biases for intrinsically local tasks, such as cycle check and node degree, and permit them to outperform transformers in a low-sample regime.3. Trained transformers outperform LLM prompting. Transformers trained to explicitly solve graph reasoning tasks consistently attain greater accuracy across tasks than a variety of prompting strategies applied to more recent larger LMs.A comprehensive evaluation of each GraphQA task on every training setting appears in Appendix E, in addition details about transformer training, the GraphQA benchmark, and alternative GNN and prompting approaches.As indicated in Section 3, graph reasoning algorithms can be categorized based on the extent to which they entail aggregating "local" information about nodes and their immediate neighbors or modeling "global" connections between nodes separated by a long distances. This section investigates the following question about transformers and long-distance reasoning:When do transformers outperform GNNs on tasks that require global reasoning?We consider two tasks that require reasoning across long distances in a graph instance: evaluating connectivity and computing the shortest path between a pair of nodes. Neither of these tasks can be solved by only investigating the neighbors of the source and sink node, which therefore implies that some analysis of global graph structure is necessary.Figure 3a displays the accuracy of a variety of trained transformers and GNNs on the connectivity task contrastsing the performance of all such models when trained on 1,000 and 100,000 graph connectivity instances. In the most restricted sample complexity regime, trained GNNs are consistently more accurate than the small transformer; however, increasing the number of training samples yields a far more substantial improvement in the performance of the small transformer, which outperforms all GNNs trained on 100,000 samples. Notably, the pre-trained transformer, fine-tuned on just 1000 training instances, nearly solves the connectivity task. This suggests significant enhancements due to the larger model size and the data-rich fine-tuning phase. Figure 3b On the other hand, Table 1 demonstrates that the MPNN GNN models outperform small transformers when trained to compute the shortest path, even on larger training datasets. However, the fine-tuned T5 model has far higher accuracy than all alternatives, even when trained only 1000 samples.Theoretical interpretation: Because connectivity is the prototypical example of a task in the parallelizable class and can thus be efficiently implemented by LogDepth transformers with very small width (Theorem 2), the fact that small transformers succeed in solving nearly all connectivity instances is illuminating but not surprising. In contrast, message-passing GNNs are unable to solve connectivity in a similarly depth-and width-efficient manner due to fundamental capacity limitations. 4Shortest path belongs to the search class of graph reasoning tasks and is NL-complete. Theorem 4 implies that shortest path is computable by LogDepthWide transformers, which are likely to require very large embedding dimension to be learnable by finite samples. This task can only be computed in a depth-and parameter-efficient manner if a variety of search tasks, including all-pairs shortest-path and diameter, are as well (Theorem 22). The fact that only the pre-trained model has nearly optimal performance on shortest path reinforces the theoretical intuition that solving shortest path requires a very large number of model parameters.While small transformers outperform GNNs on graph reasoning algorithms that entail analysis of long-range graph structure, their empirical successes are not uniform. Here, we investigate the following question:When do GNNs outperform transformers on graph reasoning tasks?Figure 3b and Table 1 demonstrate that GNNs outperform small transformers in the low-sample regime, despite the sufficient expressivity of transformers. This gap in performance, which is reinforced for the node degree and cycle check tasks in Theoretical interpretation: While model expressivity is necessary for learnability, it is not sufficient. The locality constraints of message-passing GNNs likely provides a favorable inductive bias for learning tasks like node degree with an exclusively on local structure that makes learning these tasks possible in a sample-efficient manner. While cycle check is more representationally difficult for GNNs than transformers in the worst case (see Appendix A.2), the random graphs sampled for the GraphQA benchmark have very small cycles (Figure 7 ) and do not resemble the large-diameter worst-case instance.Large language models (LLMs) are regularly evaluated by their reasoning abilities, and it remains an open research question to determine what kinds of training data best teaches models to solve logical problems. We investigate the extent to which LLMs can already perform graph reasoning tasks without being trained explicitly to do so.Do transformers trained explicitly to solve graph reasoning tasks outperform prompt-tuning approaches on much larger LLMs?In Table 3 , we contrast the capabilities of trained transformer models with several prompt-based approaches to querying LLMs. Task-specific transformers-including the fine-tuned 11B transformersconsistently dominated the prompt-based approaches, despite the vast difference in parameter count and the almost certain presence of graph reasoning in the LLM's corpus.Theoretical interpretation: While the representational capabilities of LLMs to solve reasoning tasks is much greater than that of small transformers, this performance gap suggests that their effective reasoning capacity is much weaker and that it may be improved by a richer training corpus that includes synthetic tasks.Finally, we observe that the near-perfect performance of trained transformers on the node count, edge count, and edge existence is consistent with the representational easy of those tasks, as suggested by the existence of efficient Depth1 transformer implementations. 
conclusion: 
 This paper provides a comprehensive evaluation of transformer models' graph reasoning capabilities, shedding light on their effectiveness across diverse graph reasoning tasks. By introducing a novel representational hierarchy, the study distinguishes between retrieval, parallelizable, and search reasoning tasks and offers insights into the performance of transformers at varying levels of granularity.The empirical investigation reveals that transformers exhibit strong performance in graph-based reasoning problems, often matching or surpassing specialized graph models. Furthermore, the study highlights transformers' exceptional ability to capture global graph patterns effectively, showcasing their capability in understanding long-range dependencies, a critical factor in solving tasks involving global graph structures. Overall, this work crystallizes precise representational trade-offs that reflect the fundamental reasoning capabilities of transformers and demonstrates that the tasks used to quantify those capabilities are indeed learnable in a sample-efficient and parameter-efficient manner.While the hierarchy introduced by this work effectively separates graph algorithmic tasks into distinct equivalence classes with significant implications for their computability by transformers, several questions remain for future research. We focused on graph reasoning tasks due to their relevance to the broader context of transformers, GNNs, and parallel algorithms. However, the complexity classes presented here could potentially be extended to a wider range of algorithmic problems.While our assumption of unbounded-size MLPs provides strong lower bounds, further research into whether parallelizable tasks can be represented by transformers with bounded-size MLP units would complement this existing work. Broader experimental results that empirically evaluate the scaling laws would more directly assess the relevance of representational theoretical results to learnability. 
experiments compute resources: 
 Question: For each experiment, does the paper provide sufficient information on the computer resources (type of compute workers, memory, time of execution) needed to reproduce the experiments?Answer: [Yes]Justification: The type of the accelerator used in the experiments is in Appendix.Guidelines:• The answer NA means that the paper does not include experiments.• The paper should indicate the type of compute workers CPU or GPU, internal cluster, or cloud provider, including relevant memory and storage. • The paper should provide the amount of compute required for each of the individual experimental runs as well as estimate the total compute. • The paper should disclose whether the full research project required more compute than the experiments reported in the paper (e.g., preliminary or failed experiments that didn't make it into the paper). 
code of ethics: 
 Question: Does the research conducted in the paper conform, in every respect, with the NeurIPS Code of Ethics https://neurips.cc/public/EthicsGuidelines? 
broader impacts: 
 Question: Does the paper discuss both potential positive societal impacts and negative societal impacts of the work performed?Answer: [NA] Justification: The paper is focused on reasoning capabilities of transformers using theoretical and empirical evaluation. To the best of our knowledge, there is no societal impact for the work.Guidelines:• The answer NA means that there is no societal impact of the work performed.• If the authors answer NA or No, they should explain why their work has no societal impact or why the paper does not address societal impact. • Examples of negative societal impacts include potential malicious or unintended uses (e.g., disinformation, generating fake profiles, surveillance), fairness considerations (e.g., deployment of technologies that could make decisions that unfairly impact specific groups), privacy considerations, and security considerations. • The conference expects that many papers will be foundational research and not tied to particular applications, let alone deployments. However, if there is a direct path to any negative applications, the authors should point it out. For example, it is legitimate to point out that an improvement in the quality of generative models could be used to generate deepfakes for disinformation. On the other hand, it is not needed to point out that a generic algorithm for optimizing neural networks could enable people to train models that generate Deepfakes faster. • The authors should consider possible harms that could arise when the technology is being used as intended and functioning correctly, harms that could arise when the technology is being used as intended but gives incorrect results, and harms following from (intentional or unintentional) misuse of the technology. • If there are negative societal impacts, the authors could also discuss possible mitigation strategies (e.g., gated release of models, providing defenses in addition to attacks, mechanisms for monitoring misuse, mechanisms to monitor how a system learns from feedback over time, improving the efficiency and accessibility of ML). 
safeguards: 
 Question: Does the paper describe safeguards that have been put in place for responsible release of data or models that have a high risk for misuse (e.g., pretrained language models, image generators, or scraped datasets)?Answer: [NA] Justification: This is because the datasets used are synthetically generated and reflect random graphs, no risks of data leakage are present.Guidelines:• The answer NA means that the paper poses no such risks.• Released models that have a high risk for misuse or dual-use should be released with necessary safeguards to allow for controlled use of the model, for example by requiring that users adhere to usage guidelines or restrictions to access the model or implementing safety filters. • Datasets that have been scraped from the Internet could pose safety risks. The authors should describe how they avoided releasing unsafe images. • We recognize that providing effective safeguards is challenging, and many papers do not require this, but we encourage authors to take this into account and make a best faith effort.12. Licenses for existing assets Question: Are the creators or original owners of assets (e.g., code, data, models), used in the paper, properly credited and are the license and terms of use explicitly mentioned and properly respected?Answer: [Yes] Justification: The papers are cited, the link to the source codes used is states along with their license.Guidelines:• The answer NA means that the paper does not use existing assets.• The authors should cite the original paper that produced the code package or dataset.• The authors should state which version of the asset is used and, if possible, include a URL. • The name of the license (e.g., CC-BY 4.0) should be included for each asset.• Depending on the country in which research is conducted, IRB approval (or equivalent) may be required for any human subjects research. If you obtained IRB approval, you should clearly state this in the paper. • We recognize that the procedures for this may vary significantly between institutions and locations, and we expect authors to adhere to the NeurIPS Code of Ethics and the guidelines for their institution. • For initial submissions, do not include any information that would break anonymity (if applicable), such as the institution conducting the review. 
 
 Appendix: For some vector v ∈ R N , letsoftmax(v) = 1 N i=1 exp(v i ) (exp(v 1 ), . . . , exp(v N )) ∈ R N .Let e i ∈ R m denote the ith elementary vector, 1 = (1, . . . , 1) ∈ R m and 0 = (0, . . . , 0) ∈ R m . Let[n] = {1, . . . , n}.We use a similar theoretical definition of a multi-layer transformer model to the one employed by [71] . We use a bounded communication theoretical model of the standard bidirectional transformer of [77] , which assumes that the principal limitation of the transformer's representational power is the low rank of the self-attention matrix. Several theoretical assumptions are necessary to model transformers in this regime:• the interleaved element-wise multi-layer perceptron (MLP) units compute arbitrary functions; • the embedding dimension m and number of heads per layer H are much smaller than the sequence length N ; and • all model parameters, inputs, and intermediate products can be represented with O(log N )bit numbers.These assumptions are justified in greater detail by [71] .Furthermore, we also model transformers as having N additional "pause token" inputs, which are embeddings that contain no information relevant information about the input instance, but which provide a longer "work tape" that can be utilized for computational purposes [see e.g. 29, 65] . While structurally similar to chain-of-thought reasoning [82] , these pause tokens are not determined by multiple auto-regressive passes over the transformer and do not encode useful information as input. Such pause tokens exist both in the theoretical results of Section 3 (as blank tokens at the end of the sequence) and in the empirical results of Section 4 (as placeholders between the graph representation and the task query for graphs that can be represented in fewer tokens than the maximum sequence length).Definition 1. Let Transformer N ,N m,H,L denote the family of all bidirectional transformers with embedding dimension m, number of heads H, and depth L, which operate on input sequences on length N with N blank pause tokens appended to the end 5 . Any transformer f ∈ Transformer N ,N m,H,L is a function of the form f : R N ×d → R N for some input dimension d, which parameterized by query, key, and value matricesQ ,h , K ,h , V ,h ∈ R m×m , for ∈ [L], h ∈ [H],and arbitrary element-wise MLPs with positional embeddings φ 0 , . . . , φ L and ψ withφ 0 :R d × N → R m , φ :R m × N → R m , for ∈ {1, . . . , L}, ψ :R m × N → R, where for sequence Y of length N + N , φ (Y ) = (φ (y 1 , 1), . . . , φ (y N +N , N + N )). To evaluate f (X) on some input sequence X = (x 1 , . . . , x N ) ∈ R N ×d , we define intermediate embeddings Y 0 , . . . , Y L ∈ R (N +N )×m as follows:• The initial embedding is computed by applying the first MLP φ 0 to all elements of the input X, along with N "blank" inputs:Y 0 = φ 0 (X) = (φ 0 (x 1 , 1), . . . , φ 0 (x N , N ), φ 0 (0, N + 1), . . . , φ 0 (0, N + N )).• The intermediate embeddings Y for ∈ {1, . . . , L} are computed by applying a unit of multi-headed attention (parameterized by Q ,h , K ,h , V ,h for all h ∈ [H]) to the previous embedding Y -1 , followed by an element-wise application of the MLP φ . That is,Y = φ H h=1 softmax φ(Y -1 )Q h K T h φ(Y -1 ) T φ(Y -1 )V h . • The output f (X) ∈ R N is computed to be the first N outputs of ψ(Y L ). That is, f (X) = (ψ(Y L 1 , 1), . . . , ψ(Y L N , N )).While our theoretical results pertain to the bidirectional regime (where no masking is applied to the self-attention layer), all results in Appendix C and all lower bounds in Appendix B apply to autoregressive transformers as well. Our empirical results utilize causal masking.Furthermore, an L-layer bidirectional transformer that operates on sequences of length N with N pause tokens can be simulated by and L-layer autoregressive transformer with O(L • (N + N )) pause tokens. In the regime where N = poly(N ) and L = O(log N ), any positive results for bidirectional models likewise apply to autoregressive models.We exclusively consider graph reasoning tasks that apply to undirected and unweighted graphsG = (V , E) of bounded size, i.e. |V | + |E| = O(N )for some size parameter N . We define the tasks used for experimentation as follows:• Node count: Given graph G, compute |V |.• Edge count: Given graph G, compute |E|.• Edge existence: Given graph G and vertices u, v ∈ V , return 1 {(u, v) ∈ E}.• Node degree:Given graph G and vertex u ∈ V , return deg(u) = |(u, v) ∈ E|.• Connectivity: Given graph G and vertices u, v ∈ V , return 1 if there exists a path of edges between u and v and 0 otherwise.• Cycle check: Given graph G, return 1 if there exists a cycle of any length ≥ 3 and 0 otherwise.• Shortest path: Given graph G and vertices u, v ∈ V , return the smallest number of edges that forms a path between u and v if one exists and -1 otherwise.• Triangle counting: Given graph G, return the number of triangles in the graph: |{(u, v, w) : (u, v), (v, w), (u, w) ∈ E}|.These tasks are foundational to computer science and are solved by famous polynomial-time algorithms, such as Dijkstra's algorithm for shortest path and Kruskal's for spanning trees. Several of these tasks reap significant algorithmic benefits from parallel computing models, including graph connectivity, which can be evaluated in a logarithmic number of rounds by employing an "iterative merging" strategy [4] .The amenability of some of these tasks to parallel computing is the core principle underlying our theoretical results on transformer model capacity and the resulting contrasts with GNNs. For instance, the iterative merging algorithm for connectivity can be simulated by a logarithmic-depth transformer, but message-passing GNNs cannot do without a substantial width scaling (see Appendix D). Furthermore, this parallel computing algorithm is widely believed to be optimal, and a crystallization of this as Conjecture 13 is the bedrock of our transformer optimality conjectures.The multi-layer results of Appendix B are representation-agnostic; the bounds apply to any fixed encoding of vertices and edges as a transformer input sequence X ∈ R N ×d . The input representation for Appendix C must satisfy the more specified node/edge encoding scheme, which represents each vertex and edge as a single embedding, followed by a query embedding (with optional blank embeddings as needed). This encoding scheme is reflected by Figure 1 and closely resembles the graph instance encoding used for the experimental results 6 .Throughout the paper, we partition these and other graph reasoning tasks into three representational categories: retrieval, parallelizable, and search tasks. The retrieval category contains only four of the tasks used for experiments:• Retrieval tasks include node count, edge count, edge existence, and node degree.On the other hand, the other categories reflect two equivalence classes introduce by [60] :• Parallelizable tasks are defined to be L-complete and equivalent to connectivity in O(1) rounds of MPC. These tasks include connectivity, cycle check, planarity testing, minimum cut, bipartiteness testing, minimum spanning forest, connected components, one-cycle versus two-cycles (see Conjecture 13) , and # connected components. • Search tasks are defined to be NL-complete and equivalent to shortest path in O(1) rounds of MPC. These tasks include shortest path, strong connectivity (for directed graphs), all-pairs shortest path, median, diameter, radius, directed cycle detection, and st-reachability.Triangle counting does not appear in any of these classes and is separately analyzed in Section 3.4.In this appendix, we formalize and prove all results in Sections 3.1 and 3.2 that pertain to the parallelizable and search categories of graph reasoning tasks.The primary technical tool used to establish these results is an improved relationship between the MPC model of distributed communication of [39] and our theoretical model of a transformers (Appendix A.1). This result is presented informally as Theorem 1, and formally as Theorem 8.Because graph reasoning tasks are well studied in the MPC model of computation [e.g. 4, 60], this theorem enables the transfer of those positive results to transformer architectures. Similarly, negative results that pertain to the MPC model, including those conditioned on the well-known one-cycle versus two-cycle conjecture (Conjecture 13), imply negative results for transformers. Theorem 8 (Formal version of Theorem 1; transformers simulate MPC). For constants 0 < δ < δ < 1 and γ > 0, an R-round deterministic (γ, δ)-MPC protocol with n inputs can be simulated by a transformerf ∈ Transformer N ,N m,H,L with depth L = O(R), single heads H = 1, embedding dimension m = O(n δ ), context length N = n, and blank chain-of-thought tokens N = max(0, O(n 1+γ-δ ) -n).We formally introduce the MPC distributed computing model in Appendix B.1, along with the one-cycle versus two-cycle conjecture and a collection of positive results from [60] . In Appendix B.2, we formally present the task-specific graph reasoning results introduced in Sections 3.1 and 3.2 and prove them as implications of Theorem 8. We finally contextualize and prove Theorem 8 in Appendix B.3 by modifying the proof strategy of a similar result [71] and by showing that MPC protocols can be simulated by a weaker model of distributed computation.The massively parallel computation (MPC) model of [39] formalizes distributed computing frameworks such as MapReduce [19] as theoretical models that are amenable to rigorous analysis. MPC pertains to a regime where an input that consists of n "words" is distributed across a very large number of machines q (e.g. q ≈ n 0.95 ), each of which contains a bounded local memory s (e.g. s ≈ n 0.1 ) where computation on individual machines is inexpensive but communication between machines is costly. We use the definition of MPC of [4] , which quantifies the complexity of a protocol by the local memory s = O(n δ ), the global memory sq = O(n 1+γ ), and the number of communication rounds R. Definition 2. For global and local memory constants γ, δ > 0 and input size n, an R-round (γ, δ)-MPC protocol specifies a distributed computing protocol over q = Θ(n 1+γ-δ ) machines, each of which contains a local memory of size s = O(n δ ).• An input to the protocol, which is encoded as a length-n sequence of p = Θ(log n)-bit words, is distributed across the local memories of the first n/s machines. • In each of the R rounds, each machine computes an arbitrary function its local memory at the time, which specifies at most s words to be transmitted to other machines. • Messages are simultaneously transmitted (subject to the constraint that each machine sends and receives at most s words of information), and each machine's new local memory is set equal to the messages received.• After the final round, the output of the protocol is a concatenation of the local memories of the first n/s machines.We say that an MPC protocol computes some function f : Z n 2 p → Z n 2 p if for any X ∈ Z n 2 p encoded as input to the protocol, the output of the protocol is f (X).In this section, we introduce previously known results about the abilities of Massively Parallel Computation protocols to solve graph reasoning tasks. The novel results presented in the subsequent section are the primarily the immediate implications of these results and Theorem 8.MPC round equivalence for parallelizable and search tasks These results largely reflect the contributions of [60] , which establish a hierarchy of graph reasoning tasks that is reflected in our distinction between parallelizable and search tasks. They show that all parallelizable tasks are equivalent to connectivity in O(1) rounds of MPC and that all search tasks are likewise equivalent to shortest path. (See their Figure 1 .) Concretely, they prove the following for all graphs G = (V , E)with |V | + |E| = O(n).Theorem 9 (Theorem 4 of [60] ; round-equivalence of parallelizable tasks). If there exists an Rround (γ, δ)-MPC protocol for any parallelizable task-including graph connectivity, st-connectivity, cycle detection, formula evaluation, planarity testing, graph bipartiteness, connected components, minimum spanning forest, and minimum cut, one-cycle versus two-cycle testing-for some γ > 0 and δ ∈ (0, 1), then there exists an R -round (γ , δ)-MPC protocol for any other other parallelizable task where R = R + O(1) and γ = max(γ, 3). Theorem 10 (Theorem 5 of [60] ; round-equivalence of search tasks). If there exists an R-round (γ, δ)-MPC protocol for any search task-including st-reachability (for directed graphs), strong connectivitity, directed cycle detection, shortest path, all-pairs shortest path, diameter, radius, and median-for some γ > 0 and δ ∈ (0, 1), then there exists an R -round (γ , δ)-MPC protocol for any other other search task where R = R + O(1) and γ = max(γ, 2).The equivalance of Theorem 9 has more immediate implications for the round complexity of parallelizable tasks than Theorem 10 does for search tasks because the round complexity of graph connectivity is well-understood to be O(log n) and thought to be optimal. We first present a deterministic MPC positive result for graph connectivity. Theorem 11 (Theorem 6.2 of [16] ; log-round connectivity MPC algorithm). For any γ > 0 and δ ∈ (0, 1), there exists a deterministic O(log n)-round (γ, δ)-MPC protocol that solves graph connectivity on any graphG = (V , E) of size |V | + |E| = O(n).Hence, all parallelizable tasks can be solved with a logarithmic number of MPC rounds with arbitrarily small polynomial local memory. Corollary 12 (Log-round parallelizable MPC algorithms). For any γ > 0 and δ ∈ (0, 1) and any parallelizable task, there exists a deterministic O(log n)-round (γ , δ)-MPC protocol that solves the task on any graphG = (V , E) of size |V | + |E| = O(n) for γ = max(γ, 3).The optimality of these logarithmic-round protocols is suggested by a conjecture about the hardness of distinguishing between two graphs with n vertices and n edges, one of whose edges are arranged in a single cycle of length n and the other in two disjoint cycles of length n 2 . This is the well-known "one-cycle versus two-cycle conjecture," which is widely employed as a condition for distributed computing hardness [see e.g. 8, 69, 27]. Conjecture 13 (One-cycle versus two-cycle conjecture, see e.g. [27] ). For any γ > 0 and δ ∈ (0, 1), any (γ, δ)-MPC protocol that distinguishes a single length-n cycle from two disjoint length-n 2 cycles uses R = Ω(log n) rounds.Under this conjecture, Theorem 9 immediately implies the optimality of Corollary 12. Corollary 14 (Optimality of log-round parallelizable MPC algorithms). Conditional on Conjecture 13, for any γ > 0 and δ ∈ (0, 1), any (γ, δ)-MPC protocol that solves a parallelizable graph task on all graphs G = (V , E) of size|V | + |E| = O(n) uses R = Ω(log n) rounds.The round complexity of search tasks is less understood, and it is unknown if search tasks can be solved by O(log n)-round (γ, δ)-MPC protocols if δ ∈ (0, 1 2 ].MPC protocols for problems with bounded circuit size More general MPC constructions are known for problems that solved by bounded-size boolean circuits, which include both parallelizable and search tasks. The well-known NC i classes of Boolean circuits that take N inputs and have poly(n) gates and depth O(log i n) have been shown to be computable by bounded-round MapReduce-like computational protocols [25] and by MPC protocols in particular [60] .Theorem 15 (Theorem 1 of [60] ; log-round circuit MPC algorithms). For any problem in NC i+1 and any γ > 0 and δ ∈ ( 1 2 , 1), there exists a deterministic O(log i n)-round (γ, δ)-MPC protocol that solves the problem.Since L and NL are known to belong to NC 2 , the following corollary is an immediate consequence. Corollary 16 (Log-round parallelizable and search MPC algorithms with high local memory). For any parallelizable or search graph reasoning task and any γ > 0 and δ ∈ ( 1 2 , 1), there exists a deterministic O(log n)-round (γ, δ)-MPC protocol that solves the task on all graphsG = (V , E) of size |V | + |E| = O(N ).Note that these results pertain exclusively to the "large local memory regime," where each machine has memory at s = ω( √ n). Therefore, this does not guarantee the existence of a O(log n)-round MPC solution for any search task or for any parallelizable task with γ < 1.MPC protocol for triangle counting Finally, the triangle counting task can be solved in the MPC framework by utilizing a special case of a parallel algorithm for clique counting. These pertain to graphs with bounded arboricity α, a quantity that corresponds to the branching factor of a node that is bounded by the degree of the graph; these apply to arbitrary graphs by noting that α ≤ |V |. Theorem 17 (Theorem 1.5 of [11] ; loglog-round triangle counting MPC algorithm). For any k ≥ 3, δ ∈ (0, 1), and γ > 0, there exists an O(log log n)-round (γ, δ)-MPC protocol that computes the number of k-cliques in any graphG = (V , E) with |V | + |E| = O(n) and arboricity α = O(n γ/(k-2) ).We state formalized versions of the statements of Sections 3.1, 3.2 and 3.4 and prove them by invoking Theorem 8 jointly with the relationships between MPC and graph reasoning of Appendix B.1.1.For the duration of this section, the class of parallelizable tasks includes all of those that are deemed equivalent to graph connectivity in O(1) rounds of MPC by [60] , as stated in Theorem 9.We first present a statement that formalizes the existence of logarithmic-depth transformer constructions for solving parallelizable tasks. Theorem 18 (Formal version of Theorem 2; log-depth transformers compute parallelizable tasks). For any ∈ (0, 1) and any parallelizable task, there exists a transformer Proof. The first bullet is an immediate implication of Corollary 12 and Theorem 8 with γ = 3, δ = , and δ = . The second bullet follows from Corollary 16 and Theorem 8 with γ = δ = 2 and δ = .f ∈ Transformer N ,N m,H,L such that f (X) computes the task where X ∈ R N is some encoding of any graph G = (V , E) with |V | + |E| = O(N )We then establish that sub-logarithmic-depth solutions to any parallelizable task are impossible without having linear embedding dimension m or super-polynomial number of pause tokens N , under the assumption that the one-cycle versus two-cycle conjecture holds. Theorem 19 (Formal version of Theorem 3; log-depth optimality for parallelizable tasks). Conditional on Conjecture 13, for any ∈ (0, 1) and γ > 0 and any parallelizable task, if there exists a transformer f ∈ Transformer N ,N m,H,L that solves the task and has width mH = O(N ) and pause tokens N + N = O(N 1+γ ), then its depth satisfies L = Ω(log N ).Proof. The proof is a consequence of Corollary 14 and a result of [71] that proves the to simulate transformers with MPC protocols, an inversion of Theorem 8. We restate that result as follows.Theorem 20 (Theorem 3.4 of [71] ; MPC simulates transformers). Fix any transformer f ∈ Transformer N ,N m,H,L with width mH = O(N δ ) for some δ ∈ (0, 1) and total sequence length N + N = O(N 1+γ ) for some γ ≥ 0. Then, for any δ ∈ (δ, 1) and γ = 1 + 2γ + δ , there exists an O( L(1+γ) δ -δ )-round (γ , δ )-MPC protocol that simulates f .Consider a transformer f ∈ Transformer N ,N m,L,H that solves the task with width mH = O(N ) and total sequence length N + N = O(N 1+γ for some constant ∈ (0, 1) and γ > 1. Then, there exists an O ,γ (L)-round (1 + 2γ + √ , √ )-MPC protocol that solves the parallelizable task. If Conjecture 13 is true, then L = Ω(log N ).We present the main result of Section 3.2 and show an equivalence between the minimum depth transformer needed to solve search tasks in a width-efficient manner. As before, the class of searchable tasks includes tasks that are equivalent to shortest path in O( 1 Proof. As before, the proof is an immediate consequence of Corollary 16 and Theorem 8.While both search and parallelizable tasks are computable logarithmic depth of considerable width, the minimum depth transformer of width O(N ) for small that computes search tasks is unknown. Despite this deficit, we can still establish the representation similarity of all search tasks by showing that their minimum depths vary by at most a constant additive factor. Theorem 22 (Depth-equivalence of search tasks). Suppose for some ∈ (0, 1) and γ > 0 there exists a transformer f ∈ Transformer Proof. This statement is an immediate consequence of Theorem 10 and Theorem 8.We prove the existing of doubly-logarithmic-depth transformer that solves the triangle counting task giving a more general result that counts the number of k-cliques in any graph of bounded arboricity. N = O(α k-2 N 1-) if α = Ω(N /(k-2) ), 0 otherwise.that counts the number of k-cliques in all graphs G = (V , E) of arboricity α and size|V | + |E| = O(N ).Theorem 7 follows immediately from taking k = 3.Proof. This is the immediate implication of Theorem 8 and Theorem 23.Our principal theoretical result establishes that any MPC protocol with sublinear local memory can be simulated by a transformer with sublinear embedding dimension. Theorem 8 (Formal version of Theorem 1; transformers simulate MPC). For constants 0 < δ < δ < 1 and γ > 0, an R-round deterministic (γ, δ)-MPC protocol with n inputs can be simulated by a transformer f ∈ Transformer N ,N m,H,L with depth L = O(R), single heads H = 1, embedding dimension m = O(n δ ), context length N = n, and blank chain-of-thought tokensN = max(0, O(n 1+γ-δ ) -n).This offers an improvement on Theorem 3.1 of [71] , which only guarantees that MPC protocols with local memory s = O(n 1/4-) (or with δ < 1 4 ) can be simulated by transformers with sublinear embedding dimension. This distinction is significant because several positive results for the MPC protocol (e.g. the ability to solve all problems in L and NL in a logarithmic number of MPC rounds) require s = Ω(N 1/2 ) local memory, and hence could not be shown to be simulated by transformers of sublinear embedding dimension previously 7 .Including an allowance of N blank pause tokens permits the simulation of MPC protocol with γ ≥ δ, i.e. where number of machines q grows super-linearly with n. If γ < δ, then the protocol can be simulated without pause tokens (i.e. N = 0) for sufficiently large input sizes n.To prove Theorem 8, we define a restriction of the MPC computational model that disallows each machine from communicating with more than k other machines in each round of the protocol. Definition 3. For constants γ, δ, ρ > 0, an R-round (γ, δ, ρ)-MPC protocol on input sequences of length n is a (γ, δ)-MPC protocol (Definition 2) that obeys an additional constraint on the number of outgoing and incoming messages. Namely, for some capacity k = O(n ρ ), in each round, every machine can send its local memory to and receive information from at most distinct k machines. Theorem 8 is an immediate consequence of Proposition 24-which establishes that any (γ, δ)-MPC protocol can be simulated by a (γ, δ, ρ)-MPC protocol-and Corollary 25-which shows that any (γ, δ, ρ)-MPC protocol can be simulated by a transformer.Proposition 24 ((γ, δ, ρ)-MPC simulates (γ, δ)-MPC). For constants γ, δ > 0 and ρ ∈ (0, δ 2 ), if f can be computed by an R-round (γ, δ)-MPC protocol, then there exists a O( R(1+γ) 2 ρ 2)-round (γ, δ, ρ)-MPC protocol that computes f as well.Corollary 25 (Transformers simulate (γ, δ, ρ)-MPC). For constants δ ∈ (0, 1) and γ, ρ > 0, an R-round deterministic (γ, δ, ρ)-MPC protocol with n inputs can be simulated by a transformer f ∈ Transformer N ,N m,H,L with depthL = R + 1, heads H = 1, embedding dimension m = O(n δ+4ρ log n), context length N = n, and blank chain-of-thought tokens N = max(0, O(n 1+γ-δ ) -n).Proof of Theorem 8. Let ρ := min( δ 2 , δ -δ 4 )for some small constant (e.g. := min( δ 4 , δ -δ 8 )). By Proposition 24, we can simulate the target R-round (γ, δ)-MPC protocol with an R -round (γ, δ, ρ)-MPC protocol forR = O R(1 + γ 2 ) min((δ -δ) 2 , δ 2 ).We apply Corollary 25 to conclude that this latter protocol can be simulated by a transformer of depth L = R + 1 and embedding dimensionm = O(n δ+4ρ log n) = O(n δ ).We prove Proposition 24 in Appendix B.3.1 by simulating a single round of a standard MPC with multiple rounds of restricted MPC, where messages are sent to intermediate "neighborhoods"-which contain collections of machines with similar destinations-of increasing fine granularity. We prove Corollary 25 in Appendix B.3.2 by a minor adaptation of the proof of Theorem 3.1 of [71] .Fix an R-round (γ, δ)-MPC protocol π with input size n, q = Θ(n 1+γ-δ ) machines, and s = O(n δ ) local memory. To prove Proposition 24, it suffices to show that a single round of MPC communication can be simulated an O( (1+γ) 2 ρ 2 )-round (γ, δ, ρ)-MPC protocol. To formalize the communication procedure to simulate, we let Outbox = (Outbox 1 , . . . , Outbox q ) denote an encoding of the outgoing "message packets" from each source machine that obeys π's local memory constraints. Concretely,Outbox i = {(Msg, Src, Dst) : Src = i, Dst ∈ [q]} s.t. Msg∈Outboxi |Msg| ≤ s.Let Inbox = (Inbox 1 , . . . , Inbox q ) denote the same collection of message packets, organized by their destination machines.Inbox i = {(Msg, Src, Dst) ∈ Outbox Src : Dst = i} s.t. Msg∈Inboxi |Msg| ≤ s.It suffices to prove Lemma 26. Lemma 26 ((γ, δ, ρ)-MPC simulates one communication round of (γ, δ)-MPC). If ρ < δ 2 , there exists an O( (1+γ) 2 ρ 2 )-round (γ, δ, ρ)-MPC protocol that takes as input any Outbox and returns the corresponding Inbox.Proof. We define r = O( 1+γ ρ ) intermediate steps and prove that each of those can be simulated. The intuition is that each an intermediate step routes each packet (Msg, Src, Dst) to a machine that belongs to the same "neighborhood" as Dst. Each step maps each packet to a neighborhood of smaller radius than the step before, until all packets have been transmitted to their proper destination location.We define a tree of neighborhoods as follows. Fix some branching factor = Θ(n ρ/2 ) and number of intermediate steps r = log q log = O( 1+γ ρ ). For any step t = 0, . . . , r and neighborhood index j = 1, . . . , b t := q r-t , we define Nbhd t j = (j -1) r-t + 1, (j -1) r-t + 2, . . . , j • r-t ∩ [q] and observe that it satisfies the size constraint |Nbhd t j | ≤ r-t . We let Nbhd t (Dst) denote the unique neighborhood Nbhd t j satisfying Dst ∈ Nbhd t j . We say that Nbhd t j < Nbhd t j if j < j (and equivalently, for all i ∈ Nbhd t j and i ∈ Nbhd t j , i < i ). LetChildren(Nbhd t j ) = Nbhd t+1 (j-1) +1 , . . . , Nbhd t+1 j , Descendants τ (Nbhd t j ) = Nbhd τ (i) : i ∈ Nbhd t j , Parent(Nbhd t j ) = Nbhd t-1 j/ , Ancestor t (Nbhd τ j ) = Nbhd t (i) for i ∈ Nbhd τ j . for some τ ≥ t.Note that the following are true of neighborhoods.• The initial "step 0" neighborhood contains all machines (i.e. Nbhd 0 1 = [q]), and the final "step r" neighborhoods contain a single machine (i.e. Nbhd r j = {j} for all j ∈ [q]).• For any t < r and j ∈ [b t ], Nbhd t j is the disjoint union of all sets in Children(Nbhd t j ) and |Children(Nbhd t j )| ≤ .Step 01 Nbhd q machines per Nbhd Nbhd 0 1 Machine 1 Outbox 0 1 Machine 2 Outbox 0 2 Machine q Outbox 0 q Step 1 Nbhds q/ machines per Nbhd Nbhd 1 1 Machine 1 Outbox 1 1 Machine q/ Outbox 1 q/ Nbhd 1 Machine q Outbox 1 qStep 2 2 Nbhds q/ 2 machines per Nbhd • For any Dst ∈ [q], there exist unique sets Nbhd 0 (Dst), . . . , Nbhd r (Dst) that satisfyNbhd r (Dst) ⊂ • • • ⊂ Nbhd 0 (Dst)and Nbhd t-1 (Dst) = Parent(Nbhd t (Dst)).We define a collection of MPC machine states as "intermediate outboxes" Outbox t = (Outbox t 1 , . . . , Outbox t q ) for each step t to represent an assignment of message packets to machines in the same tth-level neighborhood as the packet destination. That is, we require that each Outbox t i satisfyEQUATIONWe say that Outbox t are valid intermediate outboxes for Outbox if:1. Outbox t satisfies Equation (1);2. there is a one-to-one mapping between packets in Outbox and Outbox t ; and 3. local memory constraints are maintained up to a factor of two8 Msg∈Outbox t i |Msg| ≤ 2s.Note that Outbox satisfies the conditions for Outbox 0 , and the only sequence of embeddings that satisfies the conditions for Outbox r is Inbox. An inductive argument that applies Lemma 27 r times completes the proof.Lemma 27 ((γ, δ, ρ)-MPC simulates one intermediate step). For any t ∈ {0, . . . , r -1} and ρ < δ 2 , there exists an O( 1+γ ρ )-round (γ, δ, ρ)-MPC protocol that takes as input any satisfactory Outbox t and returns some satisfactory Outbox t+1 .Proof. The protocol operates in two phases:1. The pre-computation phase, where relevant message size metadata is computed using O(r -t) rounds of communication.2. The message-passing phase, where all messages are propagated in r -t rounds of communication in order to convert Outbox t to Outbox t+1 .Since r = O( 1+γ ρ ), the bound on total number of rounds is satisfied. The algorithm maintains the invariant that all communication occurs within t-level neighborhoods Nbhd t j without any mixing between neighborhoods; this is possible because of the assumed validity of Outbox t , which implies that all messages whose packets appear in Nbhd t j of Outbox t have ultimate destinations in Nbhd t j . Concretely, if (Msg, Src, Dst) ∈ Outbox t i and i ∈ Nbhd t j , then Dst ∈ Nbhd t j . We first explain the routing strategy for the message-passing phase by describing an itinerary of machines that each message packet will be routed to and proving that this itinerary meets the conditions needed to be executed by an (r -t)-round (γ, δ, ρ)-MPC protocol. We then describe how the metadata necessary for the itinerary computations can be obtained during the pre-computation phase.Message-passing phase. We first introduce some packet notation to track all relevant metadata about any message in the tth intermediate step. Fix some particular input Outbox t .• Let P = (Msg, Src, Dst, Src t ) denote a packet that contains a message Msg and metadata concerning its "global" source Src and destination Dst (i.e. (Msg, Src, Dst) ∈ Outbox Src , Inbox Dst ) and its "local" source Src t from within Outbox t (i.e. (Msg, Src, Dst) ∈ Outbox t Src t ).• We write P ∈ Outbox t i if Src t = i and P ∈ Nbhd if P ∈ Outbox t i for some i ∈ Nbhd.• Let SrcNbhd t,τ (P) = Nbhd τ (Src t ) represent the neighborhood of size r-τ contains P (i.e. P ∈ SrcNbhd t,τ (P)) and DstNbhd t (P) = Nbhd t+1 (Dst) denote the neighborhood of size r-t-1 that contains the ultimate destination Dst. Because P ∈ Nbhd t j if and only if Dst ∈ Nbhd t j , it follows that DstNbhd t (P) ⊂ SrcNbhd t,t (P).• Let |P| = |Msg| be the total number of bits needed to encode the packet.• We establish a lexicographical ordering that depends first on Src t and next on Dst. That is, we say that P < P for some P = (Msg , Src , Dst , Src t ) if Src t < Src t , or if Src t = Src t and Dst < Dst.We develop a packet scoring function z t,τ (P), which in turn induces an itinerary function b t,τ (P) ∈ [q] that assigns an intermediate machine to hold packet P after r-τ communication steps. These functions are carefully chosen in order to ensure that the local memories of each individual machine are bounded by O(s) and that the number of machine each sends messages to and receives messages from is bounded by O( 2 ). Critically, we ensure that b t,τ (P) ∈ SrcNbhd t,τ (P); that is, we initially rearrange packets within solely within the smallest neighborhoods of Outbox t and gradually propagate packets more widely. That way, each packet P obeys a trajectory of the following form over r -t MPC rounds: b t,r (P) = Src t ∈ SrcNbhd t,r (P) =⇒ b t,r-1 (P) ∈ SrcNbhd t,r-1 (P) =⇒ . . . =⇒ b t,t+1 (P) ∈ SrcNbhd t,t+1 (P) =⇒ b t,t (P) ∈ DstNbhd t (P).To define these functions, we first define partial sums of message sizes in order to later determine an itinerary of machines that P will be routed to in between Src t and some destination machine in DstNbhd t (P). The first term, EqualDstSum t,τ (P), sums the size of all "lesser" packets that share a destination neighborhood DstNbhd t (P) and a τ th level input neighborhood SrcNbhd t,τ (P):EqualDstSum t,τ (P) = P ∈SrcNbhd t,τ (P) DstNbhd t (P )=DstNbhd t (P)P <PThe second term, LessDstSum t,τ (P), sums the size of all packets that share an input neighborhood but have a "smaller" destination neighborhood than P:LessDstSum t,τ (P) = LessDstSum t (SrcNbhd We now define the packet scoring and itinerary functions for any τ ∈ {t, . . . , r}: z t,τ (P) = 2s • min SrcNbhd t,τ (P) + LessDstSum t,τ (P) + EqualDstSum t,τ (P) τ ≥ t + 1, 2s • min DstNbhd t (P) + 2 • EqualDstSum t,τ (P) τ = t. b t,τ (P) = z t,τ (P) 2s .We prove a series of claims to establish that the packet scoring and itinerary functions are properly defined.Claim 28 (Itinerary range). For any τ ∈ {t, . . . , r}, the itinerary function satisfies b t,τ (P) ∈ SrcNbhd t,τ (P) τ ≥ t + 1 DstNbhd t (P) τ = t.As an immediate consequence, b t,r (P) = Src t for P = (Msg, Src, Dst, Src t ).Proof. We first bound the scoring function z t,τ . Note that LessDstSum t,τ (P) + EqualDstSum t,τ (P) ≤P ∈SrcNbhd t,τ (P) |P | -|P| ≤ |SrcNbhd t,τ (P)| • 2s -|P|.Therefore, for τ > t, z t,τ (P) ∈ 2s • min SrcNbhd t,τ (P), 2s Were it not true, there would exist at least one machine i ∈ DstNbhd t (P) that must receive more an s quantity of messages at the end of the entire round of the protocol π (i.e. Msg∈Inboxi |Msg| > s), which contradicts the MPC assumption.Claim 29 (Gaps between scores). If P 1 = P 2 and z t,τ (P 1 ) ≤ z t,τ (P 2 ), then z t,τ (P 1 ) + |P 1 | ≤ z t,τ (P 2 ).Proof. First, let τ > t. Consider the case where SrcNbhd t,τ (P 1 ) = SrcNbhd t,τ (P 2 ). By Claim 28 and our assumption that z t,τ (P 1 ) ≤ z t,τ (P 2 ), it must be the case that SrcNbhd t,τ (P 1 ) < SrcNbhd t,τ (P 2 ). Hence, we have the following by applying Equation (2). z t,τ (P 2 ) -z t,τ (P 1 )≥ 2s • (min SrcNbhd t,τ (P 2 ) -(min SrcNbhd t,τ (P 1 ) + |SrcNbhd t,τ (P1 )| -|P 1 |)) ≥ |P 1 |.Otherwise, if SrcNbhd t,τ (P 1 ) = SrcNbhd t,τ (P 2 ), then z t,τ (P 2 ) -z t,τ (P 1 ) = (LessDstSum t,τ (P 2 ) + EqualDstSum t,τ (P 2 )) -(LessDstSum t,τ (P 1 ) + EqualDstSum t,τ (P 1 ))= P ∈S2 |P | - P ∈S1 |P |,for some packet subsets S 1 , S 2 ⊂ SrcNbhd t,τ (P 1 ). By further inspecting the respective LessDstSum t,τ and EqualDstSum t,τ terms, we observe that S 1 ⊂ S 2 and P 1 ∈ S 2 \ S 1 . The claim immediately follows.The argument for the case τ = t is nearly identical.For any b ∈ N,P:b t,τ (P)=b |P| ≤ 2s τ ∈ {t, r} 3s τ ∈ {t + 1, . . . , r} .Proof. The case τ = r is an immediate consequence of the inductive assumption that Outbox t satisfies the desired intermediate properties.For all other cases, let {P 1 , . . . , P n } denote all packets with b t,τ (P i ) = b and let z t,τ (P 1 ) ≤ • • • ≤ z t,τ (P n ) without loss of generality. We use Claim 29, the assumption that all |P i | ≤ s, and the boundedness of z t,τ (P i ) from Claim 28 to conclude the proof.n i=1 |P i | ≤ n-1 i=1 (z t,τ (P i+1 ) -z t,τ (P i )) + |P n | ≤ z t,τ (P n ) -z t,τ (P 1 ) + s ≤ 2s τ = t, 3s τ > t.Claim 31 (Intra-class distance preservation). If P 1 and P 2 satisfy SrcNbhd t,τ +1 (P 1 ) = SrcNbhd t,τ +1 (P 2 ) and DstNbhd t (P 1 ) = DstNbhd t (P 2 ), then z t,τ (P 1 ) -z t,τ (P 2 ) = z t,τ +1 (P 1 ) -z t,τ +1 (P 2 ).Proof. Since SrcNbhd t,τ +1 (P 1 ) = SrcNbhd t,τ +1 (P 2 ), it follows that SrcNbhd t,τ (P 1 ) = SrcNbhd t,τ (P 2 ) and therefore, z t,τ (P 1 ) -z t,τ (P 2 ) = EqualDstSum t,τ (P 1 ) -EqualDstSum t,τ (P 2 )EQUATIONz t,τ +1 (P 1 ) -z t,τ +1 (P 2 ) = EqualDstSum t,τ +1 (P 1 ) -EqualDstSum t,τ +1 (P 2 )EQUATIONBecause P 1 , P 2 ∈ SrcNbhd t,τ +1 (P 1 ), the defined packet ordering implies that any P ∈ [P 1 , P 2 ) must satisfy P ∈ SrcNbhd t,τ +1 (P 1 ). Therefore, Equations ( 3) and ( 4) are equal and the claim holds.Claim 32 (Distinct recipients bound). For any b,| b t,τ (P) : b t,τ +1 (P) = b | ≤ 3 .Proof. Within each root neighborhood Nbhd τ j , there exist at most destination neighborhoods in DstNbhd t (P) for P ∈ Nbhd τ j . Fix some such DstNbhd and let P 1 , . . . , P n denote all packets with b t,τ +1 (P) = b and DstNbhd t (P i ) = DstNbhd. Without loss of generality, assume that z t,τ (P 1 ) ≤ • • • ≤ z t,τ (P n ). Because all such packets belong to the same machine in step r -τ -1 (i.e. b t,τ +1 (P i ) = b for all i ∈ [n]), they belong share the same source neighborhood of size r-τ -1 (i.e. SrcNbhd t,τ +1 (P i ) = SrcNbhd t,τ +1 (P 1 )). By Claim 31 and the definition of b t,τ , b t,τ (P i ) -b t,τ (P 1 ) ≤ 1 + 1 2s (z t,τ (P i ) -z t,τ (P 1 ))= 1 + 1 2s (z t,τ +1 (P i ) -z t,τ +1 (P 1 )) ≤ 2 + b t,τ +1 (P i ) -b t,τ +1 (P 1 ) = 2.Therefore, there are at most three possible values of b t,τ (P i ).The claim follows by considering each of the destination neighborhoods separately:b t,τ (P) : b t,τ +1 (P) = b = DstNbhd b t,τ (P) : b t,τ +1 (P) = b, DstNbhd t (P) = DstNbhd ≤ 3 .Claim 33 (Distinct senders bound). For any b,| b t,τ +1 (P) : b t,τ (P) = b | ≤ 3 2 .Proof. Within each Nbhd τ j , there exist at most 2 distinct pairs of destination neighborhoods DstNbhd t (P) and source neighborhoods Nbhd t,τ (P) for P ∈ Nbhd τ j . As before, we fix some DstNbhd and SrcNbhd and let P 1 , . . . , P n all satisfy b t,τ (P i ) = b, DstNbhd t (P i ) = DstNbhd, and SrcNbhd t,τ +1 = SrcNbhd. Using the same argument, we show thatb t,τ +1 (P i ) : i ∈ [n] ≤ 3.We conclude by considering all such pairs. As a result of Claims 30, 32, and 33, we conclude that each packet P = (Msg, Src, Dst, Src t ) can be equipped with some itinerary Src t = b t,r (P), b t,r-1 (P), . . . , b t,t+1 (P), b t,t (P) ∈ DstNbhd t (P) that properly translates an instances of Outbox t to Outbox t+1 and does so without ever requiring local memory more than 3s = O(N δ ) on any intermediate step or any machine to send or receive messages from more than 3 2 = O(N ρ ) other machines. This itinerary can be executed using an (r -t)-round (γ, δ, ρ)-MPC protocol.Pre-computation phase. It remains to show that each b t,τ can be computed for each packet. To do so, we prove that there exists an O(r -t)-round (γ, δ, ρ)-MPC protocol that ends with each machine i knowing EqualDstSum t,τ (P) and LessDstSum t,τ (P) for each P ∈ Outbox t i and τ ∈ {t, . . . , r}. We design an MPC protocol that uses the tree structure to propagate information about individual child neighborhoods to their parents and vice versa. We describe recursive relationships that elucidate how to compute the two salient quantities.First, we introduce a useful intermediate term. LetEqualDstSum t,τ (i, DstNbhd) = i ∈Nbhd τ (i) i <i P ∈Outbox t i DstNbhd t (P )=DstNbhd |P |,denote the sum of all packet that are contained by "lesser" machines that share source and destination neighborhoods. Note that EqualDstSum t,τ (P) can be computed for any P ∈ Outbox t i locally by machine i given prior knowledge of EqualDstSum t,τ (i, DstNbhd t (P)). Thus, the pre-computation phase need only compute the latter term.We also introduce a term that represents sum of the sizes of all packets that share source and destination neighborhoods:NbhdSum t (SrcNbhd, DstNbhd) = P ∈SrcNbhd DstNbhd t (P )=DstNbhd |P |.Now, we provide the recurrences for any τ < r (or for any SrcNbhd satisfying |SrcNbhd| > 1:EQUATION)EQUATIONWhen τ = r, the terms EqualDstSum t,τ (i, DstNbhd), NbhdSum t (Nbhd r (i), DstNbhd), and LessDstSum t (Nbhd r (i), DstNbhd) can be computed locally within machine i.We follow a tree-like communication pattern to compute all relevant sums. Each machine i ∈ [q] computes EqualDstSum t,τ (i, DstNbhd) : τ ≥ t, DstNbhd ∈ Children(Nbhd t (i))and LessDstSum t (Nbhd τ (i), DstNbhd) : τ ≥ t, DstNbhd ∈ Children(Nbhd t (i))by completing r -t propagate-up rounds, r -t aggregation rounds, and r -t propagate-down rounds.• The propagate-up rounds compute the neighborhood-wide message-size summations NbhdSum t (Nbhd τ (i), DstNbhd) and LessDstSum t (Nbhd τ (i), DstNbhd) in each machine i satisfying i = min Nbhd τ (i) for each τ and DstNbhd.• The aggregation rounds accumulate NbhdSum terms of the same level into specific EqualDstSum terms.• The propagate-down rounds iteratively compute and share the EqualDstSum and LessDstSum terms with all relevant machines.Propagate-up rounds: Fix some neighborhood Nbhd t j . After r -τ propagate-up rounds, the goal is to compute the terms NbhdSum t (SrcNbhd, DstNbhd) and LessDstSum t (SrcNbhd, DstNbhd) for each relevant destination neighborhood DstNbhd ∈ Children(Nbhd t j ) and source neighborhood SrcNbhd ∈ Descendants τ (Nbhd t j ) within a single machine in each source neighborhood, min SrcNbhd. We argue that this is possible inductively.Before performing any computation (that is, after "round 0"), each machine i individually computes NbhdSum t (Nbhd r (i), DstNbhd) and LessDstSum t (Nbhd r (i), DstNbhd) by aggregating the messages encoded in its own representation of Outbox t i .We assume that the procedure works as specified for r -τ rounds of communication. Fix some SrcNbhd τ -1 ∈ Descendants τ -1 (Nbhd t j ). Then, for every SrcNbhd τ ∈ ChildrenSrcNbhd τ -1 , the quantities {NbhdSum t (SrcNbhd τ , DstNbhd) : DstNbhd ∈ Children(Nbhd t j )} ∪ {LessDstSum t (SrcNbhd τ , DstNbhd) : DstNbhd ∈ Children(Nbhd t j )} have already been computed and stored in min SrcNbhd τ . By the recurrence relations of Equations ( 5) and ( 6), NbhdSum t (SrcNbhd τ -1 , DstNbhd) and LessDstSum t (SrcNbhd τ -1 , DstNbhd) are functions of those quantities. Thus, it suffices to have each machine min SrcNbhd τ machine transmit its relevant terms to min SrcNbhd τ -1 . A round of MPC communication that transmits such messages involves each machine sending most one message of size and receiving at most messages, each of size O( ).Inductively, we ensure that all neighborhood sums are computed after r -t propagate-up rounds. Because each machine handles at most distinct messages having total size O( 2) per MPC round, this protocol does not violate the bounded message size and bounded distinct message constraints (so long as 2 s), which can be guaranteed for sufficiently large n, so long as = O(n ρ/2 ).Aggregation rounds: After the completion of the aggregation rounds, each machine i computes terms of the form EqualDstSum t,τ (min Nbhd τ +1 (i), DstNbhd) : DstNbhd ∈ Children(Nbhd t j ) from relevant NbhdSum t terms if i = min Nbhd τ +1 (i). By the recurrence, it is sufficient for machine i to following 2 distinct terms NbhdSum t (SrcNbhd, DstNbhd) : SrcNbhd ∈ Children(Nbhd τ (i)), DstNbhd ∈ Children(Nbhd t j ) . Since all machines i already knows such terms for SrcNbhd = Nbhd τ +1 (i), it can obtain the remaining NbhdSum t terms by simultaneously sharing information with its "cousin machines:" min SrcNbhd, for all SrcNbhd ∈ Children(Nbhd τ (i)). This can be handled by a single round of communication where each "(τ + 1)th-level neighborhood representative" machine forwards its sums sums to up to other first representatives, for a total messaging cost of O( 2 ).We use r -t separate rounds to repeat this process for each τ ≥ t.It remains to compute each EqualDstSum t,τ (i, •) and LessDstSum t (Nbhd τ (i), •) term at each machine i. The relevant LessDstSum t terms have already been computed by each respective min Nbhd τ (i) machine and can be propagated to machine i by using r -t rounds of tree-propagation through intermediate min Nbhd τ (i) machines.The same is possible for EqualDstSum t,τ terms, although the individual terms need to be added in order to follow the recurrence. We propagate the terms in the same way as the LessDstSum t terms, but we take special care to carry out the extra additions. This can be accomplished simultaneously to the other propagate-down rounds. This protocol involves each first-child node sharing at most distinct messages, each of size at most O((r -t) ). As before, every node sends and receives at most O((r -t) 2 ) s words.After these 3(r -t) rounds have elapsed, each machine i computes b t,τ (P) for each P ∈ Outbox t i . Using this itinerary, the machines routes tuples of the form (P, b t,r (P), . . . , b t,t (P))to the respective machine b t,τ (P) in round r -τ . Due to the arguments presented at the start of the section, this procedure terminates with each (Msg, Src, Dst) tuple being held by some machine i such that the resulting Outbox t+1 i is valid, and the procedure involves at most O(r -t) = O( 1+γ ρ ) rounds of (γ, δ, ρ)-MPC computation.Corollary 25 (Transformers simulate (γ, δ, ρ)-MPC). For constants δ ∈ (0, 1) and γ, ρ > 0, an R-round deterministic (γ, δ, ρ)-MPC protocol with n inputs can be simulated by a transformer f ∈ Transformer N ,N m,H,L with depth L = R + 1, heads H = 1, embedding dimension m = O(n δ+4ρ log n), context length N = n, and blank chain-of-thought tokens N = max(0, O(n 1+γ-δ ) -n).The proof of Corollary 25 involves an adaptation to the proof of Theorem 3.1 of [71] . To avoid restating the proof in its entirety, we provide a brief outline of the proof of Theorem 3.1 and explain which modification is necessary. Theorem 3.1 is a consequence of Lemmas B.4, B.5, and B.6 of [71] , which establish that there exist single-layer transformers that simulate the initialization, a round of computation and communication, and the output formatting of any fixed (γ, δ)-MPC protocol. The input and output steps of (γ, δ), and (γ, δ, ρ)-MPC protocols are identical, only Lemma B.5 needs to be examined.To simulate a single round of an MPC protocol with a transformer, all local computations are simulated in the element-wise multi-layer perceptron (MLP) units, and all communication is handled in a single multi-headed self-attention layer (Lemma B.7) Since (γ, δ, ρ)-MPC protocols add no restrictions related to local computation, the former can be simulated in exactly the same manner with identical MLPs, and it remains to analyze the construction of Lemma B.7. We restate Lemma B.7 and provide an replacement lemma that suffices to prove Corollary 25. Lemma 34 (Lemma B.7 of [71] ; multi-headed attention simulates MPC communication). For any R-round MPC protocol with local memory s and q machines and any round r ∈ [R -1], there exists a single-layer transformer f ∈ Transformer q,0 m,H,1 with H = O(log log q) and m = O(s 4 log q), which, given as input a length-q encoding of each machine's outgoing messages in round r, returns an encoding of each machine's incoming messages in round r + 1. Lemma 35 (Single-headed attention simulates bounded-message MPC communication). For any R-round MPC protocol with local memory s, q machines, and a k-machine communication limit and any round r ∈ [R -1], there exists a single-layer single-headed transformer f ∈ Transformer q,0 m,H,1 with H = 1 and m = O(k 4 s log q), which, given as input a length-q encoding of each machine's outgoing messages in round r, returns an encoding of each machine's incoming messages in round r + 1.Lemma 35 is an immediate consequence of Lemma 3.2 of [71] , their main technical result, which already applies to the regime with limits on the number of machines in communication.By replacing Lemma 34 with Lemma 35, applying the remainder of the proof of Theorem 3.1 of [71] , and letting k = O(n ρ ), the proof of Corollary 25 is complete.This appendix presents the results of Section 3.3, which separates the collection of graph reasoning tasks into those retrieval tasks that can be efficiently solved by single-layer parameter-efficient transformers-including node count, edge count, edge existence, and node degree-and those parallelizable or search tasks that require deeper constructions-including connectivity, shortest path, cycle check, and triangle count. Taken together, these results establish that the single-layer transformers of the Depth1 regime are capable of solving simple aggregation-based tasks, but that their known limitations in capacity as communication protocols of [70] apply to non-trivial graph reasoning tasks.We specific a particular node/edge encoding of an input graph G = (V , E) and a graph reasoning task using a consistent encoding scheme that closely resembles the encoding used in our graph reasoning experiments and those of [42] . This encoding is distinguished by the fact that each node and vertex of the graph G is represented by exactly one token, rather than the pair of tokens utilized in our experiments. This choice ensures that any trivial pre-processing of graph inputs (e.g. using a positional embedding to associate each edge token pair) need not count towards the single-layer transformer model. Definition 4. The node/edge encoding of a graph G = (V , E) with V ⊆ [n] and |V | + |E| ≤ N -1 and a graph reasoning task P is a sequenceX = X(G, P ) = (x 1 , . . . , x N ) ∈ R N ×dwhere d = 5 and eachx i = (x 1 i , x 2 i , isVertex i , isEdge i , isTask i ) ∈ {0, .. . , n} 2 × {0, 1} 3 satisfies the following conditions:• For each v ∈ V , there exists exactly one i ∈ [N -1] with x i = (v, 0, 1, 0, 0).• For each (u, v) ∈ E, there exists exactly i ∈ [N -1] with x i = (u, v, 0, 1, 0).• The token x N encodes a particular instance of the task P , by encoding isTask N = 1 with an optional edge or node encoding. That is, for tasks without arguments (such as triangle count), x N = (0, 0, 0, 0, 1). For tasks with a single node argument v ∈ [n] (such as node degree), x N = (v, 0, 1, 0, 1). For tasks with a pair of node arguments u, v ∈ [n] (such as shortest path and connectivity), x N = (u, v, 0, 1, 1).• All other tokens satisfy x i = (0, 0, 0, 0, 0).We say that a single-layer transformer f ∈ Transformer N m,H,1 solves task P on graph G if the output corresponding to the task description f (X(G, P )) N encodes the output of the task. Since f is a single-layer transformer, we can write this output asEQUATIONfor element-wise multi-layer perceptronsφ : R d → R m , ψ : R m → R broadcasted across each input (i.e. φ(X) = (φ(x 1 ), . . . , φ(x N )) ∈ R N ×m ) and weight matrices Q 1 , . . . , Q H , K 1 , . . . , K H , V 1 , . . . , V H ∈ R m×m .Throughout, we assume that all parameters in the transformer model and intermediate numerical quantities can be written using O(log N )-bit floating point numbers. This assumption can be satisfied for the positive results of Appendix C.1 and is necessary to obtain the negative results of Appendix C.2.We permit the element-wise MLPs φ and ψ to be arbitrary functions for the negative results, while restricting them to be MLPs that can be approximated using bounded-size multi-layer ReLU networks for the positive results. While we do not make these ReLU networks explicit, we restrict ourselves to simple operations that can be computed using linear transformations and the application of smooth univariate functions.Finally, we acknowledge that the negative results in are largely superseded by those of [55] , which establishes that L-complete languages (including graph connectivity and cycle check) cannot be efficiently solved by constant-depth transformers, let alone single-layer transformers. We include these bounds anyway to mark a contrast with our positive results; draw further connections to the communication complexity lens on transformers; and exhibit simple task instances (G, P ) that require greater depth, including constant diameter and constant degree graphs.Theorem 36 (Formal version of Theorem 5; Depth1 computes retrieval tasks). Fix any graph reasoning task among node count, edge count, edge existence, and node degree and any graph size N . Then, there exists a single-layer single-headed transformer f ∈ Transformer N m,1,1 with embedding dimension m = O(log N ) that solves the task on all graphs G = (V , E) of size |V | + |E| ≤ N -1 formatted as node/edge embedding sequences.Proof. We prove that a single head of self-attention with input and output MLPs can solve these retrieval and aggregation tasks in a parameter-efficient manner by first carefully designing a universal input MLP φ : R d → R m for some m = O(log N ) to produce embeddings that encode useful graph properties. Then, we define task-specific query, key, and value matrices Q, K, V :∈ R m×m and output MLPs ψ : R m → R that produce the correct answers. While we do not explicitly account for finite-precision computations, all of the operations utilized can be carefully implemented to respect O(log N )-bit floating-point numerical representations using the technical approaches of [70, 71] .Shared sinusoidal embedding MLP. We denote the embedding output of the input MLP asφ(x i ) = (isTask i , isVertex i , isEdge i , φ (x i )) ∈ R mfor some φ (x i ) : R d → R 2m for some m = O(log N ) and m = 2m + 3. For some fixed a 1 , . . . , a m ∈ [0, 1] to be determined, letφ (x i ) =    η(x 1 i ) if isVertex i = 1, ξ(x 1 i , x 2 i ) if isEdge i = 1, 0 otherwise,where η is a sinusoidal embedding MLP for nodes withEQUATIONand ξ is an edge embedding satisfyingξ(u, v) = m m + η(u) T η(v) (η(u) + η(v)).We first show that the node embeddings are approximately orthogonal. By employing standard trigonometric identities, we obtainη(u) T η(v) = m j=1 cos(2πa j (u -v)),and note that η(v)2 2 = m . We use a standard concentration argument to prove that |η(u) T η(v)| m if u = v with high probability.Claim 37 (Near-orthogonality of embeddings η). There exist coefficients a 1 , . . . , a m ∈ [0, 1] that comprise the embedding η :[n] → R m of Equation (8) such that η(u) T η(v) ≤ 2 m log n, if u = v.Proof. We employ the probabilistic method. Consider m iid random variables a 1 , . . . , a m ∼ Unif([0, 1]) and let η represent the respective node embedding. Fix some arbitrary u, v ∈ [n] with u = v and note thatη(u) T η(v) = m j=1 cos(2πa j (u -v)). For any j ∈ [m ], the integrality of u -v implies that E aj [cos(2πa j (u -v))] = 0.Hoeffding's inequality provides the following bound:Pr η(u) T η(v) ≥ 2 m log n ≤ exp - 4m log n 2m ≤ 1 n 2 .By applying a union bound to all n 2 choices of u and v, we have the following:Pr ∀u, v ∈ [n], u = v : η(u) T η(v) ≥ 2 m log n ≤ n(n -1) 2n 2 < 1.Hence, there exists a satisfactory set of coefficients a 1 , . . . , a m .For some η satisfying Claim 37, letχ = max u,v∈[n],u =v |η(u) T η(v)| ≤ 2 √ m log n.By taking m = O(log n) be sufficiently large, we guarantee that χ ≤ m c for any constant c ≥ 2. We then bound all relevant inner products between vertex and edge embeddings for sufficently large m (and sufficiently small χ). We assume throughout that u, u , v, v are distinct and note that ξ(u, v) = ξ(v, u) (and omit symmetric inequalities).EQUATIONEQUATIONEQUATIONξ(u, v)EQUATIONEQUATIONEQUATIONTherefore, we conclude the following bounds:EQUATIONEQUATIONWe now apply the above bounds to prove that each task can be solved by a single-headed transformer with weights Q, K, V ∈ R m×m , output MLP ψ : R m → R, and shared input MLP φ discussed previously.Node count task. If P encodes the node count task, we specify weights matrices Q, K, V in order to ensure thatQ T φ(x N ) = m e 1 9 ; K T φ(x i ) = (isVertex i + isTask i ) • e 1 ; and V T φ(x i ) = isTask i • e 1 10 .Then, the following is true of exponentiated key/query inner products and scalings products of value vectors:exp(φ(x N ) T QK T φ(x i )) = e m if isVertex i = 1 or i = N , 1 otherwise. exp(φ(x N ) T QK T φ(x i ))V φ(x i ) = e m • e 1 if i = N , 0 otherwise.If such a transformer f exists, then the following is true for some φ, ψ, and Q, K, V :DISJ(a, b) = ψ H h=1 softmax φ(x N ) T Q h K T h φ(X) φ(X)V h = ψ H h=1 Z h,A exp(L h,A ) + Z h,B exp(L h,B ) + Z h,[N ]\(A∪B) exp(L h,[N ]\(A∪B) ) exp(L h,A ) + exp(L h,B ) + exp(L h,[N ]\(A∪B) ) ,for partial softmax and normalization terms11 defined as follows for S ⊂ [N ] and h ∈ [H]:Z h,S = i∈S exp(φ(x N ) T Q h K T h φ(x i ))V h φ(x i ) i∈S exp(φ(x N ) T Q h K T h φ(x i )) ∈ R m , L h,S = log i∈S exp(φ(x N ) T Q h K T h φ(x i )) ∈ R + .The definition of input instances X implies that Alice can compute Z h,A and L h,A as a function of her input a; Bob can similarly compute Z h,B and L h,B from b; andZ h,[N ]\(A∪B) , L h,[N ]\(A∪B), and all implementation details of f are known by all players. Therefore, Bob can compute DISJ(a, b) by an O(mH log N )-round protocol where Alice sends him (Z h,A , L h,A ) bit-by-bit.It remains to apply Lemma 39 to each graph reasoning task by defining graph instance encodings X that encode DISJ(a, b) in the solution to the task for some r = Θ(N ).Proof of Theorem 38. For each task, we provide a pair of "hard instances:" one with constant degree and one with constant diameter, in order to obey different notions of graph simplicity. This implies that the following transformer inputX ∈ R N ×d for N = |V | + |S * | + |A| + |B| + 1is a valid node/edge encoding such that inputs X A is a function of a, X B is a function of b, andX [N ]\(A∪B) is constant:• For i ∈ V , x i = (i, 0, 1, 0, 0) encodes a fixed vertex.• For i ∈ S * , x i = (u i , v i , 0, 1, 0) encodes a fixed edge.• For i ∈ A, x i represents edge (u i , v i ) if it exists:x i = (u i , v i , 0, 1, 0) if (u i , v i ) ∈ E A (a), (0, 0, 0, 0, 0) otherwise.• For i ∈ B, x i represents edge (u i , v i ) if it exists:x i = (u i , v i , 0, 1, 0) if (u i , v i ) ∈ E B (b),(0, 0, 0, 0, 0) otherwise.• x N = (u, v, 0, 1, 1) encodes the task token for some fixed (u, v) ∈ V 2 .Constant-diameter instance: We define a graph G of diameter at most 8 that encodes an disjointness instance a, b ∈ {0, 1} r in an instance of connectivity.• Let |V | = 3r+2, and let nodes 1 and 3r+2 denote the "source" and "sink" node respectively. That is, x N = (1, 3r + 2, 0, 1, 1).• Edges between the source node 1 and nodes {2, . . . , r + 1} and between the end node 3r + 2 and {2r + 2, . . . , 3r + 1} always are included. That is,E * = {(1, i) : i ∈ {2, . . . , r + 1}} ∪ {(3r + 2, i) : i ∈ {2r + 2, . . . , 3r + 1}} . • Alice's input is encoded as edges (i + 1, i + r + 1) for i ∈ [r]. That is, E A (a) = {(i + 1, i + r + 1) : a i = 1} ⊂ ĒA = {(i + 1, i + r + 1) : i ∈ [r]} .• Bob's inputs are similarly encoded as (i + r + 1, i + 2r):E B (b) = {(i + r + 1, i + 2r + 1) : b i = 1} ⊂ ĒB = {(i + r + 1, i + 2r + 1) : i ∈ [r]} .We visualize this construction of G in Figure 5 .There exists a path between node 1 and node 3r + 2 if and only if there exists some i ∈ [r] such that (i + 1, i + r + 1), (i + r + 1, i + 2r + 1) ∈ E, which corresponds to a If there exists a transformer f solves shortest path on graphs of the form G , then there exists a minor modification f that solves graph connectivity on graph G.Cycle check task. We again modify the graph connectivity constructions. We produce G by adding a single edge to G between the source node 1 and the sink node 3r + 2, which ensures that G has a cycle if and only if G is connected between the source and sink nodes. Therefore, a transformer f can only solve check check if there exists a transformer f that solves connectivity.Our experiments in Section 4 highlight the differences in graph reasoning abilities between vanilla transformers with a naive input graph tokenization and graph neural networks (GNNs). These distinctions can be understood as the consequences of model capacity or inductive bias between transformers and GNNs. This appendix contrasts the novel analysis of the capacities of vanilla transformers in Section 3 with previously established limitations on GNNs. We present two theoretical tools for deriving negative results on GNN capabilities: CONGEST distributed computing model and the Weisfeiler-Leman isomorphism test (WL-test). We discuss the results implied by these frameworks and contrast them with transformer capabilities and limitations.The bidirectional relationship between transformers and the massively parallel computation (MPC) distributed computing model of [71] was partially inspired by a similar analogy between GNNs and the CONGEST model by [51] .The MPC and CONGEST distributed computing protocols differ in their models of how messages are passed between machines. While MPC protocols permit any machine to send a message to any other machine subject to capacity constraints, CONGEST protocols operate on a graph topology that restricts machines to send messages exclusively to and from neighbors. As a consequence, two nodes in a CONGEST graph that are separated by a path of length p cannot share information with one another without Ω(p) rounds of communication; no similar notion of "long-range communication" exists for MPC.All message-passing GNNs where each node initially knows only its own features can be simulated by a CONGEST protocol whose rounds scales linearly in the depth of the GNN [51] . This reduction implies a lower bound on solving several parallelizable and search tasks discussed in Appendix A.2.Theorem 40. Any graph neural network f with width (message size) m and depth L that computes any of the following tasks on n-node graphs has the following size lower bounds:• Subgraph connectivity, minimum spanning forest, minumum cut, shortest path:L √ m = Ω( √ n). • Cycle detection, diameter computation: Lm = Ω(n).If L = O(log N ), then for all tasks, m = Ω(n).In contrast, the quantitative bounds in Section 3 establish sharp trade-offs between transformers and GNNs for parallelizable tasks and suggest a possible equivalence for search tasks.All parallelizable tasks-including (subgraph) connectivity, minimum spanning forest, minimum cut, and cycle detection-can be solved by transformers of depth L = O(log n) and width m = O(n ) for any constant ∈ (0, 1) due to Theorem 2. In contrast, Theorem 40 requires that a similar-depth GNNs have width m = Ω(n), and a GNN of comparable width requires depth L = Ω(n 1-).On the other hand, search tasks, such as shortest path and diamter, are only guaranteed to be solvable by transformers of depth O(log n) and width O(n 1+ ) (for graphs with |E| = n 2 ) by Theorem 4. This statement compares to the GNN negative results of Theorem 40.A relationship between GNNs and the Weisfeiler-Leman heuristic graph isomorphism test [83] (WL test) further establishes representational limitations of message-passing GNNs. This connection and the rich literature surrounding it is presented in greater detail by [59] .The 1-WL test is a permutation-invariant test for predicting whether two candidate graphs are isomorphic that works by first labeling each node with the empty set ∅ and then repeatedly replacing each label with a multiset of its neighbors' labels. A hierarchy of WL test variants exists where the k-WL test maintains a label for each k-tuple of vertices. The failure models of these heuristic solutions are well-understood; critically, the 1-WL test cannot distinguish between connected and disconnected graphs.The abilities of message-passing GNNs without unique node identifiers to determine whether two graphs are isomorphic are limited by the graphs distinguishable by the 1-WL test [84, 59] . As an immediate consequence, such GNNs cannot solve graph connectivity at all, unlike transformers, which can do so with a logarithmic-depth parameter-efficient representation. The relationship is bidirectional; message-passing GNNs (and transformers as well) admit an efficient approximation of the 1-WL test.The effectiveness of these bounds is tempered by the assumption that no node includes identifying features, which is easily overcome by standard GNN models. The analogy is further limited by the fact that graph embeddings of transformers must have some (possibly arbitrary) node identifier as input in order to tokenize a graph using the node/edge encoding without losing the ability to associate each node with its incident edges. However, the juxtaposition of the 1-WL and CONGEST-based limitations on the abilities of GNNs to solve connectivity-based tasks suggests a fundamental gap in capabilities between models that is apparent in multiple theoretical lenses.We evaluate our model on the diverse graph reasoning tasks presented in GraphQA [24] . We used the public code of the dataset available at https://github.com/google-research/ google-research/tree/master/graphqa. The code to generate the datasets is licensed under the Apache License, Version 2.0. The tasks in the dataset range in difficulty and encompass the following categories:• Graph-level: node counting (counting the number of nodes in a graph), edge counting (counting the number of edges in a graph), cycle check (determining whether a graph contains a cycle), and triangle counting (counting the number of triangles in a graph). • Node-level: node degree (calculating the degree of a given node in a graph).To rigorously evaluate the performance of transformers on graph reasoning tasks, we compare them against three established categories of baselines:1. Prompting-based methods. These methods provide the LLM with a textual descriptions of the graph and question within the prompt. We consider the following variations and copy the results from the original papers:• ZERO-SHOT. In this approach, the model is given a task description and immediately asked to produce the desired output. No additional examples or demonstrations are provided. • FEW-SHOT. This approach provides the model with a few examples of the task and their desired outputs [12] . Unlike traditional training, these examples are included directly in the prompt, allowing the model to learn and adapt during the inference. • COT. Chain-of-thought (CoT) prompting [82] provides examples each showing step-by-step reasoning, teaching the LLM to generate its own thought processes for tackling new tasks. • ZERO-COT. Zero-shot CoT [45] builds upon Chain-of-Thought (CoT) prompting by eliminating the need for training examples. The LLM generates its own step-by-step reasoning process using a simple trigger phrase like "Let's think step by step". • COT-BAG. BAG prompting [80] extends COT to improve the performance of LLMs on graphrelated tasks by appending "Let's construct a graph with the nodes and edges first" to the prompt. 2. Graph-based methods. These models are specifically designed to process graphs as input and are trained task-specific. They leverage the connections between nodes to learn patterns and make predictions, making them ideal for tasks where a graph is involved. We use GCN [44] , MPNN [28] , and GIN [84] from this category. GraphToken [63] is a GNN-based model that processes the graph and feed the output of the GNN as soft-tokens to an LLM. We consider both GNN models with and without identity tokenizations, as the former is known to be theoretically limited by WL tests, while the latter poses a "fairer" comparison with the positional encodings of transformers.Larger Transformers Excel at Solving Search Tasks. As discussed in Theorem 4, transformers are effective for search tasks, albeit requiring a larger number of parameters compared to retrieval tasks. This is empirically evident in the comparison between Transformer-1K and Transformer-1K (pretrained). It's worth noting that the pretrained transformer used here has 11 billion parameters, a significant increase from the 1 million parameters in Transformer-1K. To develop a more comprehensive understanding of graph reasoning tasks learnability by small transformers, we train a variety of transformers for 1,000,000 steps on each task on a range of sample sizes. In Figure 8 , we demonstrate how the model performance improves as a function of sample complexity. By doing so, we witness the relative hardness of each task in terms of the marginal benefit of new samples.• Edge count and node count are "easy" retrieval tasks that can be solved perfectly with as few as 100 samples. • Edge existence attains near-perfect train and test classification accuracy as the number of training samples approaches 100,000. • Connectivity, shortest path, and node degree demonstrate a sharp improvement in evaluation error as a function of the sample size. These models perfectly fit the training set in most sample size regimes, but yield a closer correspondence between training and testing error when trained on 100,000 samples. • Cycle check and triangle count have persistent gaps between training and testing error and overfit even in the large sample setting.While we lack computational resources to train all models multiple times to obtain error bars, we repeated the full experiments on 60M-parameter transformers with 1000 and 100,000 training samples on each task with five different random seeds in order to estimate the standard deviation of the resulting task accuracy and displayed those results in Table 5 . With the exception of the node degree experiments trained on 100,000 samples (which included a single far-outlier), all tasks and sample regimes had no more than two percentage points of standard deviation. Critically, this implies the robustness of the superiority of trained transformers over GNNs and prompting methods on "intrinsically global" tasks, such as graph connectivity.NeurIPS Paper ChecklistJustification: We reviewed the guidelines and found no relevant violations to our work. Since the experimental datasets are synthetically generated, privacy concerns are moot.Guidelines:• The answer NA means that the authors have not reviewed the NeurIPS Code of Ethics.• If the authors answer No, they should explain the special circumstances that require a deviation from the Code of Ethics. • The authors should make sure to preserve anonymity (e.g., if there is a special consideration due to laws or regulations in their jurisdiction).MPC is a theoretical model of the MapReduce computational paradigm that distributed computation among a large number of machines with restricted local memory size and communication bandwidth. We formally introduce the MPC model in Appendix B.1.The arboricity is the minimum number of spanning forests needed to cover the graph, which grows at most linearly with the degree of the graph.See Appendix A.2 for a discussion of prior work on theoretical relationships between GNNs and both the Weisfeiler-Leman graph isomorphism test[84] and the CONGEST distributed computing model and their implication that GNNs cannot solve connectivity in a parameter-efficient manner.If N = 0, we denote the family as Transformer N m,H,L .The empirical encoding scheme uses two tokens-not one-to encode each edge and has fixed size N . For all graphs whose encodings do not require all N tokens, the remaining tokens are blank placeholders that precede the query tokens.For this theoretical model of the transformer to be non-vacuous, the transformer must have embedding dimension m = o(N d). Without this, any function over X ∈ R N ×d could be solved by a single-layer transformer that concatenates all inputs into a single vector in an attention unit and passes that as input to an MLP that solves the problem.For the sake of simplicity, we assume that the encoding Msg also contains all relevant metadata about the packet Src and Dst. That is, we only track the message size |Msg|.Note that Q T φ(xN ) is the only relevant query embedding to the output f (X)N ; see Equation(7).While we do not specify the entries of Q, K, V , they are clearly linear transformations.These terms are designed in order to facilitate computation with log(N )-bit floating-point numbers. Note that each Z h,S is a convex combination of value vectors V T h φ(xi), which means that Z h,S requires no more bits of precision to accurately approximate than V T h φ(xi). Similarly, each L h,S is within an O(log N ) additive factor of maxi∈S φ(xN) T Q h K T h φ(xi).Finally, the output of the softmax term for head h is a convex combination of Z h,A , Z h,B , and Z h,[N ]\(A∪B) , which makes accurate computation of each output possible without requiring greater precision. 


Decision: This paper studies the reasoning capabilities of transformers by examining their expressiveness in graph algorithms. Theoretically, the authors investigate the depth, width, and number of extra tokens required for algorithm execution and give a representational hierarchy of graph reasoning tasks. In particular, the authors demonstrate that logarithmic depth is both sufficient and necessary to solve parallelizable graph tasks. Moreover, they conduct some experiments to verify their theoretical findings.

The reviewers found the paper to be technically sound and impactful, with a recommendation for acceptance after addressing some weaknesses and concerns. This work will contribute to the understanding of transformer reasoning capabilities over graph structure.

Reviews: review: paper_summary: paper_summary: This paper studies the reasoning capabilities of transformers by characterizing their representational power to execute graph algorithms. Theoretically, the authors employ a general transformer model previously studied by Sanford et al. (2024), which assumes that the local MLPs can represent arbitrary functions and thus may have unbounded parameters. Using this transformer model, the authors investigate depth, width, and number of extra tokens required for algorithm execution. This leads to a representational hierarchy of graph reasoning tasks. In particular, by relating the transformer model to the MPC distributed computing model, the authors show that logarithmic depth is both sufficient and necessary to solve parallelizable graph tasks. Empirically, the authors carry out well-designed experiments to demonstrate their theoretical results.
strength_weakness: strength_weakness: - As the authors mentioned at the end of the paper, the assumption of unbounded-size MLPs provides strong results. At the same time, this is an apparent gap between theory and practice. I think that making such assumption is fine. Just raising this point as a limitation of the current theoretical framework.
- The graphs used in the experiments are super small (5 to 20 nodes) compared to the size of transformers (60M and 11B). Since, theoretically, the required depth and width are sublinear with respect to the input size, this empirical setting creates a huge gap between theory and practice. It would be nice if the authors carry out additional experiments on larger graphs, or limit the number of parameters in the transformers to a few thousands.
questions: questions: - Have you tried experiments on much larger graphs? There is a huge gap in the parameter count of transformers and the size of graphs used in the current experiments.
- A related work [1] studies execution of graph algorithms using a looped transformer architecture. There, the authors prove that a transformer layer with constant depth and width can simulate a single algorithmic step of a graph algorithm for any input graph size. Consequently, by looping the same layer repeatedly, the resulting transformer model (having constant parameter count) can execute several graph algorithms. The authors should discuss the difference between their theoretical framework and that considered in [1]. Because it seems that the looping mechanism might help the transformer model to gain more efficiency in terms of parameter count.

[1] Simulation of Graph Algorithms with Looped Transformers. Artur Back de Luca, Kimon Fountoulakis. ICML 2024.
limitations: limitations: The authors should explicitly discuss about the limitations due to the assumption on local MLPs can represent arbitrary functions. For example, would this be a potential reason for the huge gap between the input sequence length (size of graph) and the transformer size (parameter count) in the experiments? The authors should comment on how likely will the assumption lead to a theory-practice gap, and possible future avenues to close this gap.
paper_summary: paper_summary: In this work, the authors propose a new representational hierarchy for standard transformers in terms of computing algorithms over graphs. To this end, the authors relate transformers to the massively parallel computing model (MPC), thus establishing the connection to several graph algorithms. The empirical study validates the theoretical results. In particular, the authors compare transformers to graph neural networks (GNNs), as well as training small transformers from scratch, fine-tuning large-scale pre-trained language models and LLM prompting.
strength_weakness: strength_weakness: - There is an ambiguity in the empirical results in 4.1 and 4.2. I searched the experimental details in the main paper as well as Appendix E.3 and believe that the authors use standard GNN baselines without added positional encodings (also see my question to confirm this). However, note that the authors use transformers with a tokenization following TokenGT (https://arxiv.org/abs/2207.02505), which leverages positional encodings (in particular, node identifiers). Now, the authors for example say in L290-291 that GNNs do not have the sufficient representational capacity to compute graph connectivity. At the same time, the authors attribute the positive results in 4.2. to the inductive bias of GNNs (e.g., L319). I think these two claims should be distinguished. GNNs with node identifiers are universal (see e.g., Abboud et al. 2020, https://arxiv.org/abs/2010.01179) but arguably still possess the inductive bias mentioned in L319, namely that they exclusively aggregate information via the 1-hop neighborhood. Further, it is known in the graph learning community that GNNs with added positional encodings perform much stronger on long-range tasks; see Tönshoff et al. 2023, https://arxiv.org/abs/2309.00367). I suggest to compare to both GNNs with node identifiers as well as without and to clearly distinguish claims about expressivity from those of inductive bias.
- The authors state that standard deviation is not provided due to high runtime costs. However, I would appreciate if standard deviation could be provided at least for the smaller models, that is, the GNN baselines as well as the 60M transformer to obtain an understanding of the variance of the presented results.
questions: questions: - Do I understand correctly that the graph data is provided to the LM-based models  as text, whereas the 60M transformer and the GNN baselines receive the graph information in terms of a custom tokenization (in the case of the transformer) or encoding (in the case of the GNN)?
- Do I understand correctly that the GNNs are not trained with node identifiers but the 60M transformer is (following TokenGT)?
limitations: limitations: The limitations were adequately addressed.
paper_summary: paper_summary: This paper investigates the algorithmic reasoning capabilities of transformers on graph problems and introduces a novel hierarchy that categorizes tasks into solvable classes under different scaling regimes of transformers. In addition, the authors perform experiments on GraphQA to validate their theoretical analysis.
strength_weakness: strength_weakness: 1. **Limited Generalizability**: The theoretical results are based on specific assumptions, parameter scaling regimes, and tasks, which might not be directly related to all real-world scenarios or practical applications.
2. **Lack of Guidance for Practice**: Beyond the insight that deeper and wider transformers have greater capacity, what guidance can this paper provide to practitioners?
3. **Some Impractical Settings**: The settings of blank tokens appended to the input sequence are not related to the practical scenarios.
4. **Need for Further Empirical Evaluation**: The experimental results of this paper are only performed on the GraphQA benchmark. More experimental results are needed to validate the theoretical results on real-world tasks.
questions: questions: See the Weaknesses section.
limitations: limitations: Authors write about limitations fairly.

Comments: comment: I'd like to thank the authors for their detailed responses. My questions have been addressed. I'm more convinced that this is a good paper with clear contributions. I will increase my confidence score and maintain the current supportive score (7).
I thank the authors for their rebuttal and for the additional empirical results. Regarding standard deviation, I suggest to repeat experiments for multiple random seeds where ever feasible. Other than that, my concerns are addressed.