2024 Vision Hybrid Q-C

Quantum Vision Transformers

El Amine Cherrat, Iordanis Kerenidis, Natansh Mathur, Jonas Landman, Martin Strahm, Yun Yvonna Li
Quantum (journal) · 2024 · arXiv:2209.08167

Contents

  1. Overview & Motivation
  2. The RBS Gate
  3. Orthogonal Quantum Layers
  4. Model Architecture
  5. Quantum-Enhanced Attention
  6. Data Encoding Strategies
  7. Complexity & Advantage
  8. Experimental Results
  9. Open Bottlenecks

1. Overview & Motivation

Classical Vision Transformers (ViT) achieve state-of-the-art image recognition, but their linear projection layers require $O(d^2)$ parameters per layer (where $d$ is the embedding dimension). The Quantum Vision Transformer (QViT) proposes replacing these costly linear layers with orthogonal quantum layers built from Reconfigurable Beam Splitter (RBS) gates, reducing the parameter count to $O(n)$ for an $n$-qubit circuit while implementing a $2^n \times 2^n$ orthogonal transformation.

Core idea: A parameterised quantum circuit on $n$ qubits encodes an orthogonal matrix of size $2^n \times 2^n$. This is used as a drop-in replacement for the $W_Q$, $W_K$, $W_V$, and MLP projection matrices in ViT.

The architecture is hybrid: image patching, positional encoding, and the classification head remain classical, while the projection matrices inside each Transformer block are quantum.

2. The Reconfigurable Beam Splitter (RBS) Gate

The foundational quantum primitive is the RBS gate, a two-qubit gate that performs a parameterised beam-splitter operation in the $\{|01\rangle, |10\rangle\}$ subspace:

$$U_{\text{RBS}}(\theta) = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos\theta & -\sin\theta & 0 \\ 0 & \sin\theta & \cos\theta & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}$$
Eq. (1) — RBS gate in the $\{|00\rangle, |01\rangle, |10\rangle, |11\rangle\}$ basis

The RBS gate acts as a controlled rotation: it only mixes $|01\rangle$ and $|10\rangle$ states, leaving $|00\rangle$ and $|11\rangle$ unchanged. This corresponds to a Givens rotation in the single-excitation subspace:

$$U_{\text{RBS}}(\theta): \begin{cases} |01\rangle \mapsto \cos\theta\,|01\rangle - \sin\theta\,|10\rangle \\ |10\rangle \mapsto \sin\theta\,|01\rangle + \cos\theta\,|10\rangle \end{cases}$$

Why RBS gates?

Key properties that make RBS ideal for this purpose:

1. Particle-number preserving: RBS conserves the number of excitations, keeping the circuit within the single-excitation subspace — exponentially more efficient for encoding classical vectors.

2. Orthogonal transformations: A pyramid of RBS gates implements an arbitrary $n \times n$ orthogonal matrix via the QR decomposition (Givens rotations).

3. Hardware efficient: Implementable as a simple parameterised rotation between adjacent physical qubits with no ancilla.

Circuit representation

  q₀ ──[RBS(θ₀₁)]──[RBS(θ₀₂)]────────── ...
           │              │
  q₁ ──[RBS(θ₀₁)]──[RBS(θ₁₂)]──[RBS(θ₁₃)]── ...
                         │              │
  q₂ ──────────────[RBS(θ₁₂)]──[RBS(θ₂₃)]── ...
                                        │
  q₃ ──────────────────────────[RBS(θ₂₃)]── ...

  Pyramid depth: ⌊n/2⌋ layers → implements O(n) ∈ SO(2ⁿ)
  Parameters: n(n-1)/2 for n-dimensional orthogonal matrix

3. Orthogonal Quantum Layers

Consider $n$ qubits prepared in a computational basis state encoding a classical vector $\mathbf{x} \in \mathbb{R}^n$ via amplitude encoding in the single-excitation subspace:

$$|\mathbf{x}\rangle = \sum_{i=1}^{n} x_i |e_i\rangle \quad \text{where } |e_i\rangle = |0\cdots 0\underbrace{1}_{i}\, 0\cdots 0\rangle$$
Eq. (2) — Amplitude encoding in single-excitation subspace

A pyramid of RBS gates with parameters $\boldsymbol{\theta}$ implements the unitary $U(\boldsymbol{\theta})$, which in the single-excitation subspace corresponds to an orthogonal matrix $O(\boldsymbol{\theta}) \in O(n)$:

$$U(\boldsymbol{\theta})\,|\mathbf{x}\rangle = |O(\boldsymbol{\theta})\,\mathbf{x}\rangle$$
Eq. (3) — Quantum orthogonal layer action

The full orthogonal layer (including bias) is:

$$\mathbf{y} = O(\boldsymbol{\theta})\,\mathbf{x} + \mathbf{b}$$

Comparison with Classical Linear Layer

Property Classical Linear ($W \in \mathbb{R}^{d\times d}$) Quantum Orthogonal (RBS pyramid)
Parameters $O(d^2)$ $O(n) = O(\log_2 d)$
Expressivity Full $\mathbb{R}^{d\times d}$ Orthogonal subgroup $O(d)$
Inference cost $O(d^2)$ $O(n^2) = O(\log^2 d)$ circuit depth
Gradient Standard backprop Parameter-shift rule

4. Model Architecture

The QViT replaces linear projection matrices inside each Transformer block with quantum orthogonal layers:

INPUT IMAGE (H×W×C)
       │
       ▼
 ┌─────────────────────────────────┐
 │   Patch Embedding (Classical)   │
 │   Split into N patches → d-dim  │
 └──────────────┬──────────────────┘
                │
       ▼ [N+1 tokens]
 ┌─────────────────────────────────┐
 │  + CLS token  + Pos. Embedding  │  (Classical)
 └──────────────┬──────────────────┘
                │
    ┌───────────┴──────────────┐
    │  Transformer Block × L    │
    │                           │
    │  ┌─────────────────────┐  │
    │  │  Layer Norm         │  │  (Classical)
    │  └──────────┬──────────┘  │
    │             │              │
    │  ┌──────────▼──────────┐  │
    │  │  Quantum Multi-Head │  │
    │  │  Self-Attention      │  │
    │  │                     │  │
    │  │  Q = U_Q(θ_Q)·x    │  │  ← Quantum Orthogonal Layer
    │  │  K = U_K(θ_K)·x    │  │  ← Quantum Orthogonal Layer
    │  │  V = U_V(θ_V)·x    │  │  ← Quantum Orthogonal Layer
    │  │                     │  │
    │  │  Attn = softmax(QKᵀ/√d)·V  │  (Classical computation)
    │  └──────────┬──────────┘  │
    │             │              │
    │  ┌──────────▼──────────┐  │
    │  │  + Residual         │  │  (Classical)
    │  └──────────┬──────────┘  │
    │             │              │
    │  ┌──────────▼──────────┐  │
    │  │  Layer Norm         │  │  (Classical)
    │  └──────────┬──────────┘  │
    │             │              │
    │  ┌──────────▼──────────┐  │
    │  │  Quantum MLP        │  │
    │  │  U_1(θ₁)·x + b₁     │  │  ← Quantum Orthogonal Layer
    │  │  ReLU               │  │
    │  │  U_2(θ₂)·x + b₂     │  │  ← Quantum Orthogonal Layer
    │  └──────────┬──────────┘  │
    │             │              │
    │  ┌──────────▼──────────┐  │
    │  │  + Residual         │  │
    │  └─────────────────────┘  │
    └───────────┬──────────────┘
                │
       ▼ [CLS token]
 ┌─────────────────────────────────┐
 │  Classification Head (Classical) │
 │  Linear → Softmax               │
 └─────────────────────────────────┘
       │
       ▼
  Class Probabilities

Quantum Circuit for Q/K/V Projection

Classical input vector x ∈ ℝⁿ
       │
       ▼  (Amplitude encoding into single-excitation basis)
|ψ_x⟩ = Σᵢ xᵢ|eᵢ⟩
       │
       ▼  (RBS pyramid with parameters θ)
 q₀: ──●──────●────────── ...
       │      │
 q₁: ─[θ₀₁]──●──────●── ...
              │      │
 q₂: ────────[θ₁₂]──●── ...
                     │
 q₃: ───────────────[θ₂₃]── ...

       ▼  (Measure all qubits → probability amplitudes)
       │
O(θ)·x  (orthogonal projection of x)

5. Quantum-Enhanced Attention

The standard multi-head self-attention computes:

$$\text{Attention}(Q, K, V) = \text{softmax}\!\left(\frac{QK^\top}{\sqrt{d_k}}\right)V$$
Eq. (4) — Classical scaled dot-product attention

In QViT, the projection matrices are replaced by quantum orthogonal layers:

$$Q = O_Q(\boldsymbol{\theta}_Q)\,X, \quad K = O_K(\boldsymbol{\theta}_K)\,X, \quad V = O_V(\boldsymbol{\theta}_V)\,X$$
Eq. (5) — Quantum projection layers; $O_*(\boldsymbol{\theta})$ is the orthogonal map from the RBS circuit

The attention computation itself remains classical — only the projections are quantum. This is a hybrid approach where quantum hardware handles the high-dimensional linear algebra while classical hardware performs the non-linear operations.

Multi-Head Configuration

For $h$ heads with dimension $d_k = d/h$ each:

$$\text{MHA}(X) = \text{Concat}(\text{head}_1, \ldots, \text{head}_h)\,O_O(\boldsymbol{\theta}_O)$$ $$\text{head}_i = \text{Attention}(O_{Q,i}X,\ O_{K,i}X,\ O_{V,i}X)$$
Eq. (6) — Multi-head quantum attention

6. Data Encoding Strategies

Classical data must be loaded into quantum states. QViT uses amplitude encoding in the single-excitation subspace:

$$\text{Enc}(\mathbf{x}) = \frac{\mathbf{x}}{\|\mathbf{x}\|} \mapsto |\psi_\mathbf{x}\rangle = \sum_{i=1}^{n} \frac{x_i}{\|\mathbf{x}\|}\,|e_i\rangle$$
Eq. (7) — Single-excitation amplitude encoding ($n$ qubits encode $n$-dim vector)
Encoding bottleneck: Amplitude encoding requires $O(n)$ gates per vector preparation for single-excitation states (efficient!), but general amplitude encoding requires $O(2^n)$ gates. QViT specifically exploits the single-excitation subspace to avoid this exponential cost.

Comparison of encoding strategies

Strategy Qubits for $d$-dim Circuit Depth Use case
Basis encoding $d$ qubits $O(1)$ Binary/integer data
Single-excitation (QViT) $d$ qubits $O(d)$ Real-valued unit vectors
Amplitude encoding $\log_2 d$ qubits $O(d)$ Compact representation
FRQI (images) $1 + \log_2(HW)$ qubits $O(HW)$ Pixel-level image encoding

7. Complexity & Quantum Advantage

$$\underbrace{O(d^2)}_{\text{Classical params per layer}} \quad\longrightarrow\quad \underbrace{O(n) = O(\log_2 d)}_{\text{Quantum params (RBS angles)}}$$
Eq. (8) — Parameter reduction for $d = 2^n$

The circuit depth for computing the orthogonal projection is:

$$D_{\text{circ}} = O(n^2) = O(\log^2 d)$$
Eq. (9) — RBS pyramid depth for full $n \times n$ orthogonal transformation
Provable advantage regime: When $d \gg n$ (large embedding dimensions), the quantum projection layer computes in $O(\text{poly}(\log d))$ depth vs. $O(d^2)$ classical. This advantage is realised only with efficient state preparation and readout — e.g., via QRAM.

Gradient via Parameter-Shift Rule

Training uses the quantum parameter-shift rule to compute exact gradients:

$$\frac{\partial \mathcal{L}}{\partial \theta_k} = \frac{1}{2}\left[\mathcal{L}\!\left(\theta_k + \frac{\pi}{2}\right) - \mathcal{L}\!\left(\theta_k - \frac{\pi}{2}\right)\right]$$
Eq. (10) — Parameter-shift rule for RBS angle gradients

8. Experimental Results

Benchmarks (simulation):
· CIFAR-10: QViT achieves ~85% top-1 accuracy vs. ViT baseline ~87% with significantly fewer parameters
· MNIST / Fashion-MNIST: Near-classical accuracy (98%+) with $4\times$ parameter reduction
· Model compression: QViT-Small (quantum projections) matches ViT-Base classification with $\sim$60% fewer parameters

Ablation: Quantum vs. Classical projection

Key finding: the orthogonality constraint (inherent to quantum layers) acts as a regulariser, providing some accuracy improvement in low-data regimes. The primary benefit is parameter efficiency rather than outright accuracy gain.

9. Open Bottlenecks

1. State preparation overhead: Loading classical data into quantum amplitude states requires $O(d)$ gates — this can dominate the circuit cost and negate advantage.
2. Measurement collapse: Extracting the full output vector $O(\theta)\mathbf{x}$ requires $O(d)$ measurements (one per amplitude component). Tomography is expensive.
3. Hardware noise: Current NISQ devices have $T_2$ coherence times that limit circuit depth. The RBS pyramid at scale requires $O(n^2)$ depth — challenging beyond $n \approx 20$ on today's hardware.
4. Classical simulation: For small $d$ (current experiments), classical simulation of the quantum circuit is trivially efficient — no quantum speedup realised until fault-tolerant hardware scales.
5. Orthogonality restriction: RBS layers implement orthogonal (not general linear) transformations. This restricts expressivity — mitigated by depth, but not proven sufficient for all tasks.
Open research directions: (i) QRAM-accelerated amplitude loading for real quantum speedup; (ii) combining QViT with quantum error correction for fault-tolerant inference; (iii) hybrid QViT where only the computationally expensive attention heads use quantum layers; (iv) theoretical analysis of expressivity vs. classical ViT.

Related Papers