Skip to main content
QUICK REVIEW

[论文解读] Quantum Transformer: Accelerating model inference via quantum linear algebra

Naixu Guo, Yu Zhan|arXiv (Cornell University)|Feb 26, 2024
Optical Network TechnologiesEngineering被引用 3
一句话总结

本文提出了一种利用量子线性代数实现Transformer推理加速的量子电路框架,支持自注意力、残差连接、层归一化及前馈网络的高效块编码。该框架实现近似最优的电路深度与对数尺度的量子比特使用,潜在地在特定参数范围内实现量子加速,例如自注意力计算的查询复杂度为$\tilde{O}(d^{3/2}\sqrt{N})$。

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.

研究动机与目标

  • 开发一种容错量子计算框架,用于加速基于Transformer的大规模语言模型的推理。
  • 解决将经典Transformer组件——自注意力、归一化与前馈网络——转化为量子子程序的挑战,采用块编码与量子信号处理技术。
  • 识别在何种条件下量子优势可能在Transformer推理中显现,尤其关注查询复杂度与电路深度。
  • 实现从预训练权重矩阵出发的单标记预测任务的端到端量子电路构建。

提出的方法

  • 本文使用块编码将预训练的权重矩阵(查询、键、值)表示为量子电路,实现在量子态上的酉操作。
  • 提出一种新颖的量子子程序,通过Hadamard积实现softmax函数的逐元素应用,对注意力计算至关重要。
  • 应用量子奇异值变换(QSVT)实现激活函数(如前馈网络中的GELU)的多项式逼近。
  • 通过受控旋转与幅度放大技术实现残差连接与层归一化,保持量子态结构。
  • 该框架确保在序列长度$N$与嵌入维度$d$上实现对数尺度的量子比特使用,且电路深度针对目标精度达到近似最优。
  • 输出为一个块编码的量子态,表示完整的Transformer输出,从中可通过测量提取预测的标记索引。

实验结果

研究问题

  • RQ1能否利用量子线性代数技术构建一个包含所有关键组件的端到端量子电路,用于Transformer推理?
  • RQ2使用块编码与QSVT实现逐元素softmax的自注意力计算,其量子复杂度是多少?
  • RQ3在何种输入假设与参数范围内,量子优势可能在Transformer推理中显现?
  • RQ4如何在不破坏量子优势的前提下,高效实现量子电路中的残差连接与归一化层?
  • RQ5该框架能否在不引入指数级开销的前提下,扩展至更深的多层架构?

主要发现

  • 本文在注意力计算中实现了$\widetilde{\mathcal{O}}(d^{3/2}\sqrt{N})$的查询复杂度,在某些参数范围内优于经典方法。
  • 自注意力、残差连接、层归一化及基于GELU的前馈网络的量子子程序均实现了在$N$与$d$上对数尺度的量子比特使用。
  • 电路深度针对目标精度达到近似最优,得益于多项式逼近与块编码技术。
  • 在归一化因子(如$Z_j$、$\alpha_s$)分别以$\Omega(N)$、$O(\sqrt{N})$与$O(\sqrt{d})$量级增长的参数范围内,识别出潜在的量子优势。
  • 该框架输出一个表示完整Transformer输出的块编码量子态,可通过测量从中提取预测的标记索引。
  • 研究指出,若在量子数据上训练或使用经典阴影技术,可能实现可扩展的多层扩展,但该问题仍为开放挑战。

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。