Skip to main content
QUICK REVIEW

[Paper Review] Looped Transformers as Programmable Computers

Angeliki Giannou, Shashank Rajput|arXiv (Cornell University)|Jan 30, 2023
Parallel Computing and Optimization TechniquesComputer Science3 citations
TL;DR

This paper demonstrates that a shallow, 13-layer Transformer can function as a universal computer by looping its output back into its input, using hardcoded attention mechanisms to emulate programmatic constructs like conditionals, function calls, and loops. It successfully implements a full backpropagation algorithm in-context, proving that even small Transformers can execute complex, general-purpose programs through structured attention design.

ABSTRACT

We present a framework for using transformer networks as universal computers by programming them with specific weights and placing them in a loop. Our input sequence acts as a punchcard, consisting of instructions and memory for data read/writes. We demonstrate that a constant number of encoder layers can emulate basic computing blocks, including embedding edit operations, non-linear functions, function calls, program counters, and conditional branches. Using these building blocks, we emulate a small instruction-set computer. This allows us to map iterative algorithms to programs that can be executed by a looped, 13-layer transformer. We show how this transformer, instructed by its input, can emulate a basic calculator, a basic linear algebra library, and in-context learning algorithms that employ backpropagation. Our work highlights the versatility of the attention mechanism, and demonstrates that even shallow transformers can execute full-fledged, general-purpose programs.

Motivation & Objective

  • To explore whether Transformers can act as universal computers without requiring deep architectures or fine-tuning.
  • To investigate how attention mechanisms can be engineered to emulate fundamental computing primitives such as conditionals, loops, and function calls.
  • To demonstrate that a constant-depth Transformer can execute iterative algorithms by looping its output back into its input.
  • To show that in-context learning in large models may rely on similar internal subroutines, suggesting a programmable mechanism via attention.
  • To provide a framework for compiling high-level programs into attention-weighted sequences executable by a looped Transformer.

Proposed method

  • The model uses a looped architecture where the output sequence is fed back as input, enabling persistent state and iterative computation.
  • Specific attention weights are engineered to emulate a one-instruction set computer (OISC) using the SUBLEQ instruction: subtract memory A from B, and branch if result ≤ 0.
  • The input sequence is structured as a punchcard with instructions, data memory, and pointers (e.g., program counter, data pointers).
  • Lexicographic operations and non-linear functions are implemented via attention patterns that simulate memory reads/writes and conditional logic.
  • Function calls and program counters are emulated using pointer manipulation and attention routing to specific memory locations.
  • The model executes iterative algorithms such as backpropagation by looping over data points and epochs, with counters managed via attention-based arithmetic.

Experimental results

Research questions

  • RQ1Can a shallow Transformer with a fixed number of layers emulate a universal computer using only attention mechanisms?
  • RQ2How can attention be structured to simulate fundamental programming constructs like conditionals, loops, and function calls?
  • RQ3Can iterative algorithms such as backpropagation be encoded and executed in-context using only attention weights and input sequence design?
  • RQ4What is the computational cost of emulating deep network training in a looped Transformer, and how does it scale with network depth?
  • RQ5To what extent can the mechanics of attention mimic traditional computer architecture components like registers and memory?

Key findings

  • A 13-layer Transformer with a single loop can emulate a full backpropagation algorithm for a single-layer neural network, executing all steps via attention-based computation.
  • The model successfully emulates a basic calculator and a linear algebra library using attention to perform arithmetic and matrix operations.
  • The number of required attention cycles scales linearly with the depth of the neural network being trained, indicating a direct computational cost proportional to model depth.
  • The framework demonstrates that even shallow Transformers can execute complex, general-purpose programs through careful attention weight engineering.
  • The results suggest that large language models like GPT-3 may internally use similar attention-based subroutines to perform in-context learning, treating natural language as executable code.
  • The approach reveals that attention mechanisms can be systematically programmed to emulate Turing-complete computation, challenging assumptions about the need for depth or parameter count.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.