Skip to main content
QUICK REVIEW

[Paper Review] Quantum Transformer: Accelerating model inference via quantum linear algebra

Naixu Guo, Yu Zhan|arXiv (Cornell University)|Feb 26, 2024
Optical Network TechnologiesEngineering3 citations
TL;DR

This paper proposes a quantum circuit framework for accelerating Transformer inference using quantum linear algebra, enabling efficient block-encoding of self-attention, residual connections, layer normalization, and feed-forward networks. It achieves near-optimal circuit depth and logarithmic qubit scaling, with potential quantum speedups in specific regimes, such as $ tilde{O}(d^{3/2} sqrt{N})$ query complexity for attention computation.

ABSTRACT

Powerful generative artificial intelligence from large language models (LLMs) harnesses extensive computational resources for inference. In this work, we investigate the transformer architecture, a key component of these models, under the lens of fault-tolerant quantum computing. We develop quantum subroutines to construct the building blocks in the transformer, including the self-attention, residual connection with layer normalization, and feed-forward network. As an important subroutine, we show how to efficiently implement the Hadamard product and element-wise functions of matrices on quantum computers. Our algorithm prepares an amplitude encoding of the transformer output, which can be measured for prediction or use in the next layer. We find that the matrix norm of the input sequence plays a dominant role in the quantum complexity. With numerical experiments on open-source LLMs, including for bio-informatics applications, we demonstrate the potential of a quantum speedup for transformer inference in practical regimes.

Motivation & Objective

  • To develop a fault-tolerant quantum computing framework for accelerating inference in Transformer-based large language models.
  • To address the challenge of scaling classical Transformer components—self-attention, normalization, and feed-forward networks—into quantum subroutines using block-encoding and quantum signal processing.
  • To identify conditions under which quantum advantage may emerge in Transformer inference, particularly in terms of query complexity and circuit depth.
  • To enable end-to-end quantum circuit construction for a single-token prediction task, starting from pretrained weight matrices.

Proposed method

  • The paper uses block-encoding to represent pretrained weight matrices (query, key, value) as quantum circuits, enabling unitary operations on quantum states.
  • It introduces a novel quantum subroutine for applying the softmax function element-wise via the Hadamard product, crucial for attention computation.
  • Quantum singular value transformation (QSVT) is applied to implement polynomial approximations of activation functions, such as GELU in the feed-forward network.
  • Residual connections and layer normalization are implemented using controlled rotations and amplitude amplification, preserving quantum state structure.
  • The framework ensures logarithmic qubit usage in sequence length $N$ and embedding dimension $d$, with circuit depth near-optimal for target accuracy.
  • The output is a block-encoded quantum state representing the full transformer output, from which the predicted token index can be measured.

Experimental results

Research questions

  • RQ1Can quantum linear algebra techniques be used to construct an end-to-end quantum circuit for Transformer inference with all key components?
  • RQ2What is the quantum complexity of implementing self-attention with element-wise softmax using block-encoding and QSVT?
  • RQ3Under what input assumptions and parameter regimes can a quantum advantage emerge for Transformer inference?
  • RQ4How can residual connections and normalization layers be efficiently implemented in a quantum circuit without destroying quantum advantage?
  • RQ5Can the framework be extended to deeper multi-layer architectures without exponential overhead?

Key findings

  • The paper achieves a query complexity of $\widetilde{\mathcal{O}}(d^{3/2}\sqrt{N})$ for the attention computation, which is sub-classical in certain regimes.
  • The quantum subroutines for self-attention, residual connection, layer normalization, and GELU-based feed-forward networks are constructed with logarithmic qubit usage in $N$ and $d$.
  • The circuit depth is near-optimal for the desired accuracy, leveraging polynomial approximation and block-encoding techniques.
  • A potential quantum advantage is identified in regimes where the normalization factors (e.g., $Z_j$, $\alpha_s$) scale as $\Omega(N)$, $O(\sqrt{N})$, and $O(\sqrt{d})$, respectively.
  • The framework outputs a block-encoded quantum state representing the full transformer output, from which the predicted token index can be extracted via measurement.
  • The work highlights that training on quantum data or using classical shadows may enable scalable multi-layer extension, though this remains an open challenge.

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.