Skip to content
Binay Dalai

2025 · research · published at IEEE NMITCON

QAOA transformer

A quantum circuit on four qubits, drawn over four rows: many single-qubit rotations and two-qubit gates, ending in a measurement of every qubit.
The figures of the paper, one after another, starting with the circuit that ran on the Kyoto processor. © 2025 IEEE.

I used QAOA, a quantum optimization algorithm, to optimize the weights of a transformer model.

We trained a small transformer, turned its weights into a graph, and ran QAOA on a four-node version of that graph on IBM’s Kyoto quantum computer.

One layer of QAOA, its two angles turning

q₀ |0⟩q₁ |0⟩q₂ |0⟩HHHRZ−π/2RZ−π/2RZ−π/2RXπ/2RXπ/2RXπ/2

γ = 1.57 β = 0.79

Expected cut: 0.00 of 2

γ sets the cost turn and β the mixing turn. As they change, so does the chance of each result.

The graph is three nodes, each joined to the other two. A cut splits the nodes into two groups; at most 2 of the 3 edges can cross it.

|000⟩0.500|001⟩0.000|010⟩0.000|011⟩0.000|100⟩0.000|101⟩0.000|110⟩0.000|111⟩0.500γβ

Lighter is a larger expected cut. The dot is where the two angles are.

One layer of QAOA on a graph of three nodes, drawn as a circuit on three qubit wires. Its two angles change along a loop. An exact simulator gives the chance of each measurement result as bars and the expected number of edges cut, and a surface shows that number for every pair of angles, with a dot where the angles are. It plays by itself and repeats. Press Space, or press on it, to pause or play; the arrow keys step it by hand.

Fig. 1. One layer of QAOA on a three-node graph, with its cost surface. An exact simulation in your browser.
How this works

Each line is a qubit. A gate changes the state of the qubits it touches.

The bars show how likely each result is if you measured now. The simulator multiplies the gates out exactly; nothing is sampled.

This is one layer of QAOA on a three-node graph. Its two angles are the two numbers the algorithm tunes. Here they move along a loop, and the surface shows the cost for every pair of angles.

Demo1 of 7

  1. The whole study on one line: set up and train a small transformer, write its weights as the edges of a graph, run QAOA on that graph on IBM’s Kyoto quantum computer, and take the result back to the model.

  2. The circuit that ran, after Qiskit rewrote it into the gates the Kyoto processor has. Four qubits, one for each node of the graph.

  3. The transformer’s own training: training loss and validation loss over a hundred epochs. Both drift down, and the swings get smaller.

  4. The optimizer’s loss at each iteration of the QAOA run. It swings widely at first and settles as the circuit’s parameters are tuned.

  5. The graph problem as the quantum computer receives it: a sum of Pauli terms. Each bar is one term, and its height is the size of that term’s coefficient.

  6. How often each four-bit answer came back. Each answer is one way to split the four nodes into two groups, and the taller bars are the splits the circuit favored.

  7. The same results ordered by the value of the objective, drawn as a cumulative distribution. It shows how the measured answers are spread across objective values.

A flow chart of seven boxes: initialize the transformer, train it, extract its weights as a graph’s edge list, apply the QAOA circuit, run it on IBM Kyoto through Qiskit, analyze the result, and apply the optimized parameters to the transformer.
Click the screen to see a step larger, held still, and to go back and forward. A step’s name shows that step.The seven figures of B. Dalai, N. K. Jadav and S. Tanwar, “Quantum-Assisted Optimization for Transformer Models: Insights and Implications,” NMITCON 2025. © 2025 IEEE.

The figures of the QAOA paper, one at a time

1 of 7. The pipeline

The whole study on one line: set up and train a small transformer, write its weights as the edges of a graph, run QAOA on that graph on IBM’s Kyoto quantum computer, and take the result back to the model. The seven figures of B. Dalai, N. K. Jadav and S. Tanwar, “Quantum-Assisted Optimization for Transformer Models: Insights and Implications,” NMITCON 2025. © 2025 IEEE.

Venue

Published at IEEE NMITCON, 2025.

Problem

Training a transformer is a search through a very large space of parameters. QAOA is a quantum algorithm built for optimization problems. This project studies what happens when QAOA does part of that search.

Approach
  1. We set up a small transformer of the design Google researchers published in 2017, with six layers and eight attention heads, and trained it for a hundred epochs.
  2. We took its trained weights out as the edges of a graph: two nodes and a weight each.
  3. On a four-node graph we posed MaxCut: split the nodes into two groups so that the edges between the groups weigh as much as possible. QAOA searches for that split with a quantum circuit whose angles a classical optimizer tunes.
  4. The circuit ran on IBM’s Kyoto quantum computer, through Qiskit.
  5. We looked at how the optimization converged, which terms of the problem carried the most weight, and how the measured states were distributed.
My role

First author. Student researcher at Nirma University, summer 2024.

Stack
  • PyTorch
  • Qiskit
  • QAOA
Scope and limits

It is an exploratory study on a four-node test case. It does not show a quantum speedup, and this site gives no performance number for it.