---
title: 'Spiking QKFormer: Hierarchical Spiking Transformer'
url: https://www.emergentmind.com/topics/spiking-qkformer
type: topic
---

# Spiking QKFormer: Hierarchical Spiking Transformer

Searching arXiv for the primary and closely related papers to ground the article in current literature.
Spiking QKFormer denotes the QKFormer family of hierarchical spiking transformers introduced in "QKFormer: Hierarchical Spiking Transformer using Q-K Attention" [2403.16552]. It was proposed to address two coupled constraints in directly trained spiking transformers: the mismatch between conventional self-attention and spike-based computation, and the memory cost of quadratic-token attention under temporal unfolding. The architecture combines a spike-form Q-K attention mechanism with linear complexity, a hierarchical multi-stage backbone that produces multi-scale spiking representations, and a patch embedding module with a deformed shortcut tailored to residual learning across resolution changes. In its reported high-resolution ImageNet-1K setting, QKFormer reached 85.65% top-1 and 97.74% top-5 accuracy with 64.96M parameters, which the authors described as the first time directly trained SNNs exceeded 85% top-1 on ImageNet-1K [2403.16552].

## 1. Concept and research context

QKFormer emerged from a specific limitation of earlier spiking transformers. Directly trained SNNs offered low latency and high energy efficiency, but training remained difficult because of non-differentiable spikes, gradient instability, and the space cost of unfolding in time. In spiking transformers, these difficulties were compounded by spiking self-attention variants that still retained the quadratic token dependence of conventional attention. QKFormer therefore repositioned the attention module itself as the bottleneck: instead of adapting full QKV attention to spikes, it proposed a Q-K-centric mechanism that models token or channel importance through binary vectors and avoids explicit $QK^\top V$ computation [2403.16552].

This placement is important within the spiking-transformer lineage. The original paper contrasts QKFormer with Spikformer, Spikingformer, SDSA, STSA, and CML, arguing that prior directly trained spiking transformers were largely single-scale and therefore poorly matched to hierarchical, multi-resolution processing. Later work preserved that characterization. TP-Spikformer described QKFormer as a "feature pyramid-based" spiking transformer with spike-based $Q$ and $K$ attention and stagewise changes in token count and spatial resolution, distinguishing it from "feature-map invariant" baselines such as Spikformer and SDT-V1 [2603.00527].

Subsequent literature generalized the term beyond the exact 2024 architecture. The 2025 A$^2$OS$^2$A paper explicitly described its addition-only spiking attention core as realizing a "spiking QKFormer" in the sense of a spike-friendly QK interaction and attention path. This suggests that, in later usage, "Spiking QKFormer" may denote both the specific hierarchical model of Zhou et al. and a broader class of Q-K-centric spiking attention designs [2503.00226].

## 2. Hierarchical architecture and patch embedding

QKFormer is organized as a three-stage hierarchical spiking transformer. For static RGB images, the input has shape $(T_0 \times H \times W \times n)$ with $T_0 = 1$ and $n = 3$; for event-based datasets, the same form is used with $T_0 = T$ and $n = 2$. Time is explicit in spiking neuron layers, whereas Conv and Linear layers merge time with batch. This permits standard tensor operators to coexist with explicit temporal spike dynamics [2403.16552].

The model uses patch embedding with a deformed shortcut, denoted PEDS in the original paper. For Stage 2 and Stage 3, the activation-before-addition form is
$$
\mathbf{Y}=\mathcal{F}\left(\mathbf{X},\{W_i\}\right) + \mathrm{SN}(W_d \mathbf{X}),
$$
where $\mathcal{F}$ is implemented as either
$$
\{\text{Conv2D} \rightarrow \text{BN} \rightarrow \text{MaxPooling} \rightarrow \text{SN} \rightarrow \text{Conv2D} \rightarrow \text{BN} \rightarrow \text{SN}\}
$$
or
$$
\{\text{Conv2D} \rightarrow \text{BN} \rightarrow \text{SN} \rightarrow \text{Conv2D} \rightarrow \text{BN} \rightarrow \text{MaxPooling} \rightarrow \text{SN}\},
$$
and $W_d$ is a 1×1 convolution with stride $>1$ that matches both the new spatial resolution and the new channel dimension. A pre-activation alternative,
$$
\mathbf{Y} = \mathrm{SN}\big(\mathcal{G}\left(\mathbf{X},\{W_j\}\right) + W_d \mathbf{X}\big),
$$
is also discussed, but the main QKFormer configuration uses the activation-before-addition residual form [2403.16552].

Stage 1 prepends spike encoding,
$$
\mathbf{X}_{\text{spike}} = \mathrm{SN}(\mathrm{BN}(\text{Conv2D}(\mathbf{X}))).
$$
The hierarchy then proceeds through Stage 1 with 4×4 patches and stride 4, Stage 2 with 2×2 downsampling, and Stage 3 with another 2×2 downsampling. In the main ImageNet configuration HST-10-768, the stages contain $[1,2,7]$ QKFormer blocks, and the maximum embedding dimension is 768 in Stage 3. For 224×224 input, the token grids are $56 \times 56$, $28 \times 28$, and $14 \times 14$ across the three stages [2403.16552].

The structural role of PEDS is more than a patch tokenizer. In conventional ViT-style patch embedding, a single projection changes resolution without an explicit residual path. QKFormer instead treats patch embedding as a residual downsampling operator. TP-Spikformer later referred to each hierarchical stage as containing a "Spiking Patch Embedding with Deformed Shortcut (SPEDS)" module and a QKFormer block, reflecting how central this component became to the model's identity [2603.00527].

## 3. Spike-form Q-K attention

The defining mechanism of QKFormer is spike-form Q-K attention. Given spike-form input $X \in \mathbb{R}^{T \times N \times D}$, the query and key streams are
$$
Q = \mathrm{SN}_Q\left(\mathrm{BN}(X W_Q)\right), \qquad
K = \mathrm{SN}_K\left(\mathrm{BN}(X W_K)\right),
$$
with binary outputs
$$
Q, K \in \{0,1\}^{T \times N \times D}.
$$
Unlike standard attention, there is no value projection inside the attention core. The resulting mechanism is not a low-precision approximation of softmax attention; it is a different operator that uses $Q$ to generate a binary importance vector and applies that vector to $K$ [2403.16552].

QKFormer defines two variants. In Q-K Token Attention (QKTA), token importance is computed by summing $Q$ across channels and passing the result through a spiking neuron:
$$
A_t = \mathrm{SN}\Big(\sum_{i=0}^{D} Q_{i,j}\Big), \qquad X' = A_t \otimes K.
$$
Here $A_t \in \{0,1\}^{N \times 1}$ is a spike-form token-importance vector, and $\otimes$ denotes broadcast Hadamard masking along the channel dimension. In Q-K Channel Attention (QKCA), the same principle is applied across tokens:
$$
A_c = \mathrm{SN}\Big(\sum_{j=0}^{N} Q_{i,j}\Big), \qquad X' = A_c \otimes K.
$$
The masked representation is then post-processed by
$$
X'' = \mathrm{SN}\left(\mathrm{BN}(\mathrm{Linear}(X'))\right).
$$
Experiments in the original paper use QKTA by default, although QKCA and mixed QKTA/QKCA settings were also studied [2403.16552].

The original paper reports the following complexity comparison:

| Method | Time complexity | Space |
|---|---:|---:|
| VSA | $O(N^2 D)$ | $O(N^2 + ND)$ |
| SSA | $O(N^2 D)$ | $O(N^2 + ND)$ |
| SDSA | $O(ND)$ | $O(ND)$ |
| QKTA | $O(D)$ | $O(N)$ |
| QKCA | $O(N)$ | $O(D)$ |

Within the paper's formulation, the essential distinction is that QKTA and QKCA avoid explicit $QK^\top$ formation and replace dense attention maps with binary importance vectors. The authors argue that this linear-complexity structure is what makes hierarchical spiking transformers feasible under direct training, because token counts are large in early stages and temporal unfolding amplifies memory cost [2403.16552].

The broader research direction did not stop at binary Q-K masking. "Spiking Transformer: Introducing Accurate Addition-Only Spiking Self-Attention for Transformer" reformulated a spiking QK-style core by using binary $Q$, ReLU $K$, and ternary $V$, with
$$
Q = \mathcal{SN}^b_Q(\mathrm{BN}(XW_Q)),\quad
K = \mathrm{ReLU}_K(\mathrm{BN}(XW_K)),\quad
V = \mathcal{SN}^t_V(\mathrm{BN}(XW_V)),
$$
and
$$
\text{A}^2\text{OS}^2\text{A}(Q,K,V)=\mathcal{SN}\big(QK^\top V\big).
$$
That work removes softmax and scaling, while preserving addition-only realization through spike-gated accumulation and ternary sign operations. It explicitly presents this as a "spiking QKFormer" core, indicating a later shift from binary-mask Q-K attention toward richer hybrid Q-K/V formulations [2503.00226].

## 4. Spiking dynamics, block structure, and direct training

Each QKFormer block follows a transformer-like residual organization. If $X_{l-1} \in \mathbb{R}^{T \times N \times D}$ is the block input, then
$$
X_l' = \operatorname{QKTA}(X_{l-1}) + X_{l-1},
$$
followed by a spiking MLP:
$$
X_l = \operatorname{SMLP}(X_l') + X_l'.
$$
The SMLP is described as a spike-form MLP, typically Linear → BN → SN → Linear → BN → SN. Attention thus updates token relations first, after which the SMLP performs channel mixing under residual control [2403.16552].

The neuron model is a standard Leaky Integrate-and-Fire unit:
$$
H[t] = V[t-1] + \frac{1}{\tau}\left(X[t] - (V[t-1] - V_{\text{reset}})\right),
$$
$$
S[t] = \Theta(H[t] - V_{th}),
$$
$$
V[t] = H[t](1 - S[t]) + V_{\text{reset}} S[t].
$$
Here $X[t]$ is the input current, $H[t]$ is the pre-spike membrane potential, $S[t] \in \{0,1\}$ is the emitted spike, and $V[t]$ is reset to $V_{\text{reset}}$ when firing occurs. The model uses explicit time steps in spiking layers but treats non-spiking layers by merging time with batch [2403.16552].

Training is direct rather than conversion-based. To address the non-differentiability of the Heaviside spike function, the paper uses a sigmoid surrogate
$$
\sigma(x)=\frac{1}{1+e^{-\alpha x}}, \qquad \alpha = 4.
$$
Backpropagation replaces the derivative of $\Theta(\cdot)$ with that of the smooth surrogate. On ImageNet-1K, the reported training setup uses AdamW, a base learning rate of $6 \times 10^{-4}$ scaled by BatchSize/256, an effective batch size of 512 via gradient accumulation across 8 V100 GPUs, and 200 epochs with RandAugment, random erasing, and stochastic depth. CIFAR10/100 uses 400 epochs and batch size 64. The common time-step setting for static vision is $T=4$, while neuromorphic datasets use $T=10$ or $T=16$ [2403.16552].

A later theory paper treated QKFormer as an explicit instantiation of spiking self-attention with LIF neurons and spike-rate encoding. In that formulation, query and key spike tensors are
$$
\mathbf{S}^Q = \text{SN}(\mathbf{S}^X \mathbf{W}^Q), \qquad
\mathbf{S}^K = \text{SN}(\mathbf{S}^X \mathbf{W}^K),
$$
and the attention scores are approximated by spike coincidence:
$$
\mathbf{A} = \frac{1}{T}\sum_{t=1}^T \mathbf{S}^Q_t (\mathbf{S}^K_t)^\top.
$$
This later reinterpretation places QKFormer inside a more general LIF-based spiking-attention theory rather than treating it as an isolated architecture [2604.15769].

## 5. Empirical performance

The original QKFormer paper reports strong gains on static and event-based benchmarks. On CIFAR10, HST-4-384 achieves 96.18% with 6.74M parameters and $T=4$; on CIFAR100, the same model reaches 81.15%, compared with 78.21% for Spikformer-4-384 and 80.02% for CML-Spikformer-4-384. On ImageNet-1K, HST-10-384 reaches 78.80%, HST-10-512 reaches 82.04%, and HST-10-768 reaches 81.69% at $T=1$, 84.22% at $T=4$ and 224×224, 85.25% at $T=4$ and 288×288, and 85.65% top-1 with 97.74% top-5 at $T=4$ and 384×384. The principal comparison in the paper is that Spikformer-8-768 obtains 74.81% with 66.34M parameters, whereas QKFormer-HST-10-768 obtains 85.65% with 64.96M parameters [2403.16552].

On neuromorphic datasets, QKFormer also performs strongly with smaller models. HST-2-256, with 1.50M parameters, reaches 98.3/98.6% on DVS128 Gesture at $T=10/16$ and 83.8/84.0% on CIFAR10-DVS at $T=10/16$. These results exceed the corresponding Spikformer-2-256 numbers of 96.9/98.3% on DVS128 Gesture and 78.9/80.9% on CIFAR10-DVS, while using fewer parameters [2403.16552].

Ablation studies clarify how the gains are distributed. Replacing Spikformer's Spiking Patch Splitting with PEDS increases CIFAR100 accuracy from 78.21% to 80.26% and CIFAR10-DVS from 80.9% to 82.2%. Time-step ablation on CIFAR100 reports 78.51% at $T=1$, 80.08% at $T=2$, 81.15% at $T=4$, and 81.30% at $T=6$, indicating that most of the improvement is realized by $T=4$. The paper also reports ImageNet firing rates inside QKTA blocks, for example Stage 1 values of 0.0432 for $Q$, 0.1784 for $K$, 0.3477 for $A_t$, 0.0832 for $X'$, and 0.1478 for $X''$, which the authors use to argue for sparsity and energy efficiency [2403.16552].

Later work reused QKFormer as a benchmark and, in some cases, reported slightly different headline numbers under altered evaluation protocols. "Closing the Theory-Practice Gap in Spiking Transformers via Effective Dimension" reports QKFormer-4-256 at 94.8% ± 0.2 on CIFAR-10 and 78.9% ± 0.3 on CIFAR-100, QKFormer-4-384 at 95.2% ± 0.2 and 80.1% ± 0.3, and an ImageNet-1K result of 85.7% with 0.40 mJ per inference on Loihi-class 14nm assumptions, corresponding to 44× energy efficiency relative to ViT-B/16 at 17.6 mJ. The same paper states more generally that spiking transformers, including QKFormer, achieve 38–57× energy efficiency on neuromorphic hardware [2604.15769].

## 6. Compression, pruning, and deployment variants

Because QKFormer is hierarchical and feature-variant, token pruning affects it differently from sequence-invariant spiking transformers. TP-Spikformer argues that direct token dropping is incompatible with QKFormer because each stage includes a Spiking Patch Embedding with Deformed Shortcut module containing structure-sensitive convolution and pooling operations, and because these stages reduce the number of tokens by a 2×2 patch size before each stage. Removing tokens outright breaks the square-grid structure required by subsequent convolutions and downsampling [2603.00527].

TP-Spikformer therefore introduces a block-level early stopping strategy rather than token deletion. For each block and time step, feature maps $X_t^{\ell-1} \in \mathbb{R}^{H \times W \times D}$ are scored by IRToP, a spatiotemporal information-retaining criterion. The spatial score is
$$
S_{\text{score}}(X^{\ell-1}_{t,h,w}) =
1 - \frac{ X^{\ell-1}_{t,h,w} \cdot Y^{\ell-1}_{t,h,w} }
{ \|X^{\ell-1}_{t,h,w}\|_2\, \|Y^{\ell-1}_{t,h,w}\|_2 },
$$
with $Y^{\ell-1}_{t,h,w}$ the local-window mean, while the temporal score is
$$
T_{\text{score}}(X^{\ell-1}_{t,h,w}) =
\begin{cases}
\|X^{\ell-1}_{t,h,w} - X^{\ell-1}_{t-1,h,w}\|_1, & t>1,\\[4pt]
\|X^{\ell-1}_{t,h,w}\|_1, & t=1.
\end{cases}
$$
The combined criterion is
$$
\mathrm{IRToP}(X^{\ell-1}_{t,h,w}) = \hat{S}_{t,h,w} + \hat{T}_{t,h,w}.
$$
Top-$K$ informative tokens are processed through SSA and MLP, while uninformative tokens are early-stopped and then reassembled into the original $H \times W$ grid [2603.00527].

On ImageNet-1K, TP-Spikformer reports QKFormer-10-768 at $T=4$ and $N_{\text{avg}}=1.0$ with 15.08 G block operations, 32.12 mJ power, and 85.56% top-1 accuracy. With $N_{\text{avg}}=0.72$, the numbers become 10.7 G, 28.18 mJ, and 84.45%; with $N_{\text{avg}}=0.65$, 9.61 G, 27.19 mJ, and 84.32%; and with $N_{\text{avg}}=0.53$, 7.97 G, 25.71 mJ, and 82.53%. The same study reports training-time reductions on a single 4090, from 22.80 GB memory and 8.78 h/epoch at $N_{\text{avg}}=1.0$ to 18.40 GB and 5.93 h/epoch at $N_{\text{avg}}=0.50$ [2603.00527].

This deployment literature also reveals a structural property of QKFormer. In the zero-finetuning ablation at $N_{\text{avg}}=0.65$, "Random + Drop" fails for QKFormer, whereas "Random + IR-Arc" yields 74.45%, "Spatial-only + IR-Arc" 58.93%, "Temporal-only + IR-Arc" 79.69%, and "IRToP + IR-Arc" 81.16%. That pattern indicates that temporal scoring is particularly important for QKFormer and that preserving hierarchical spatial structure is non-negotiable under pruning [2603.00527].

## 7. Critiques, reinterpretations, and future directions

A recurrent explanation for the gap between spiking transformers and conventional ANNs has been that binary sparse activation transmission causes information loss. "Spiking Transformers Need High Frequency Information" challenges that framing. It argues that the more fundamental issue is that spiking neurons preferentially propagate low-frequency information, so high-frequency components such as edges, textures, and local details are rapidly attenuated. In its signal-analysis treatment, the membrane dynamics of LIF neurons form a first-order IIR low-pass filter, and this low-pass term compounds across depth [2505.18608].

That critique has direct implications for spiking QK attention. The same paper states that spiking self-attention inherits this low-pass bias because $Q$, $K$, and $V$ are generated via LIF plus linear layers, and the SSA output is again passed through LIF. It therefore argues that the QK mechanism itself does not inherently restore lost high-frequency information. On CIFAR-100, replacing Avg-Pooling token mixing with Max-Pooling raises top-1 accuracy from 76.73% to 79.12%, and the proposed Max-Former reaches 82.65% on CIFAR-100 and 82.39% on ImageNet, outperforming reported QKFormer* baselines in that study. This suggests that high-performance spiking QKFormer variants may need explicit frequency-preserving front ends or local high-frequency mixers rather than relying on Q-K attention alone [2505.18608].

A second reinterpretation is theoretical rather than spectral. "Closing the Theory-Practice Gap in Spiking Transformers via Effective Dimension" presents the first comprehensive expressivity theory for spiking self-attention and uses QKFormer as a primary validation architecture. The paper states that spiking attention with LIF neurons is a universal approximator of continuous permutation-equivariant functions, derives a softmax normalization circuit via lateral inhibition with proven $O(1/\sqrt{T})$ convergence, and gives a spike-count lower bound of $\Omega(L_f^2 nd/\varepsilon^2)$. Its key practical claim is that measured effective dimensions, reported as $d_{\text{eff}}=47$--$89$ for CIFAR/ImageNet, explain why $T=4$ timesteps suffice despite worst-case predictions of $T \ge 10{,}000$. In that framework, QKFormer operates within 2–3× of the theoretical spike-efficiency frontier [2604.15769].

The architectural design space has also broadened. A$^2$OS$^2$A proposes binary $Q$, full-precision non-negative ReLU $K$, and ternary $V \in \{-1,0,1\}$, removing softmax and scaling while preserving non-multiplicative computation. It reports 78.66% on ImageNet-1K for Spiking Transformer-10-512 and presents its core as an accurate addition-only spiking QK module. A plausible implication is that later work increasingly treats "Spiking QKFormer" as a family of Q-K-centric spike-attention strategies rather than a single binary-mask architecture [2503.00226].

Across these later analyses, two points recur. First, QKFormer established that hierarchical spiking transformers can match or exceed strong ANN backbones on vision benchmarks under direct training. Second, its successors and critics have shifted the central design question from whether attention can be made spike-compatible to how Q-K-centric attention should be encoded, normalized, pruned, and spectrally balanced in order to preserve both spike efficiency and representational richness [2403.16552].

Source: https://www.emergentmind.com/topics/spiking-qkformer