Quantum Transformer: Accelerating model inference via quantum linear algebra

Naixu Guo, Zhan Yu, Matthew Choi, Yizhan Han, Aman Agrawal +3 more
2/26/2024
quant-phcs.AIcs.CL

No official code found. Best implementation: Naixu-Guo/Quantum-Transformer (1 star, MIT, last commit 2025-06-16).

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.

View on arXivView PDF

Code Implementations(1)

MIT

Data and code for paper Quantum Transformer: Accelerating model inference via quantum linear algebra

10Shell, PythonJun 16, 20251 years agoMIT

Similar Papers

Cite this paper

@article{guo2024quantum,
  title  = {Quantum Transformer: Accelerating model inference via quantum linear algebra},
  author = {Naixu Guo and Zhan Yu and Matthew Choi and Yizhan Han and Aman Agrawal and Kouhei Nakaji and Alán Aspuru-Guzik and Patrick Rebentrost},
  year   = {2024},
  eprint = {2402.16714},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2402.16714v3}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2402.16714.svg)](https://codeofpaper.com/paper/2402.16714)

Discussion