---
title: 'Spark-Attn: Adaptive Block-Sparse Attention'
url: https://www.emergentmind.com/topics/spark-attn
type: topic
---

# Spark-Attn: Adaptive Block-Sparse Attention

Spark-Attn is a training-free adaptive block-sparse attention method for long-video diffusion transformers. Introduced in “Spark-H3: Adaptive Block Sparse Attention for Video Diffusion Models” [2611.24256], it replaces dense self-attention only during inference by combining attention-preference-aware token reorganization with calibrated compression of unselected key–value blocks. Its two principal components are **Spark-Reblock**, which recursively forms regular tiles whose tokens have similar attention preferences, and **Spark-Reweight**, which represents unselected tiles with attention-weighted key–value summaries and a logit bias that calibrates their contribution to the global softmax normalization. The method is instantiated in MiniMax-H3 as Spark-H3 and is evaluated on long-video diffusion models without modifying model parameters, LoRAs, or denoising schedules.

## 1. Computational setting and design objectives

For a video containing $N$ tokens, one attention head forms query, key, and value matrices

$$
Q,K,V\in\mathbb{R}^{N\times d},
$$

where $d$ is the head dimension. The dense score matrix is

$$
S=\frac{QK^\top}{\sqrt d}\in\mathbb{R}^{N\times N},
$$

and dense attention has token complexity $O(N^2d)$. FlashAttention reduces memory traffic and improves on-chip execution, but it still evaluates the dense all-pairs query–key interaction. Consequently, increasing frame count, spatial resolution, or both substantially increases video diffusion latency.

For query $q_i$, key $k_j$, and value $v_j$, Spark-Attn expresses attention through numerator and denominator accumulation:

$$
\bigl(n(q_i),z(q_i)\bigr)
=
\sum_{j=1}^{N}
e^{s(q_i,k_j)}(v_j,1),
$$

where

$$
s(q_i,k_j)=\frac{q_i^\top k_j}{\sqrt d}.
$$

The normalized output is

$$
o(q_i)=\frac{n(q_i)}{z(q_i)}.
$$

This formulation permits exact and approximate block contributions to be accumulated under one shared normalization. It is central to Spark-Attn because unselected blocks are not simply discarded: their estimated numerators and masses continue to affect the output and the normalization of selected exact tokens.

Conventional block-sparse attention partitions tokens according to fixed spatial, temporal, or raster-order layouts. For a query tile $I$ and key–value tile $J$, it computes a routing score from mean queries and mean keys,

$$
r_{IJ}
=
\frac{\bar q_I^\top\bar k_J}{\sqrt d},
$$

and evaluates the highest-scoring fraction of tiles exactly. If $\rho$ denotes exact-block density, the exact branch evaluates approximately $\rho N^2$ token interactions, while the overall dominant interaction term is approximately $O(\rho N^2d)$, in addition to routing, reblocking, compression, and compressed-query costs.

Spark-Attn addresses two limitations of this baseline:

- **Preference mismatch**: fixed tiles can contain tokens with dissimilar attention preferences, causing mean queries or keys to be poor routing representatives.
- **Compression bias**: replacing a key–value tile with uniformly averaged representations generally underestimates its attention mass because exponentiation is nonlinear.

The method therefore separates the problem into token organization and unselected-block approximation. Spark-Reblock addresses preference mismatch, whereas Spark-Reweight addresses compression bias.

## 2. Spark-Reblock: preference-aware regular tiling

Spark-Reblock recursively partitions tokens according to their induced attention preferences rather than their raw feature-space proximity or original spatial order. For a query $q$, the normalized interaction vector is

$$
u_Q(q)=\frac{Kq}{\lVert Kq\rVert_2}.
$$

Two queries are considered similar when they induce similar score patterns over the current key set. The corresponding preference distance is

$$
d_Q(q,q')
=
1-u_Q(q)^\top u_Q(q')
=
1-\cos\bigl(M_K^{1/2}q,M_K^{1/2}q'\bigr),
$$

where

$$
M_K=\frac{K^\top K}{N}.
$$

A symmetric key distance is defined using

$$
M_Q=\frac{Q^\top Q}{N}.
$$

In practice, Spark-Reblock estimates the relevant second-moment matrix $\widehat M$ from sampled tokens and reuses it during partition construction, avoiding formation of the dense attention matrix.

For each current token group $G$, tokens are transformed as

$$
z_x=\widehat M^{1/2}x.
$$

The algorithm chooses two local landmark-derived representatives, $\mu_{G,-}$ and $\mu_{G,+}$, and assigns each token a split margin

$$
\Delta_G(x)
=
\cos(z_x,\mu_{G,+})
-
\cos(z_x,\mu_{G,-}).
$$

Tokens are sorted by $(\Delta_G(x),x)$ and divided into prescribed child groups. Recursion terminates when a group reaches the target tile size $b_\star$. Thus, the leaves are uniformly sized tiles, subject to boundary handling when the sequence is not exactly divisible by the tile size.

The recursive construction preserves regular block shapes while adapting token grouping to attention preference. This distinction is important for GPU execution: arbitrary clustering can improve semantic coherence but produce irregular memory layouts, whereas Spark-Reblock maintains fixed-capacity leaves suitable for block-oriented kernels.

Spark-H3 uses 32 landmarks, two refinement updates per split, and 64 tokens per tile. To reduce construction cost, it batches four binary partitioning levels at once. A landmark tree creates 15 split directions for 16 child groups, after which a batched matrix product evaluates split scores and rank cutoffs form the child partitions and token permutation. With fixed feature dimension and landmark budget, the construction complexity is $O(N\log N)$.

The standard Spark-H3 configuration partitions using keys and applies the resulting permutation to $Q$, $K$, and $V$. The output is restored to the original query order after attention. A variant, Spark-H3$^\dagger$, separately partitions queries and key–value tokens using the query and key preference distances. This can improve alignment slightly but incurs additional construction complexity and modestly higher latency.

After reblocking, query and key–value tiles are routed using

$$
r_{IJ}
=
\frac{\bar q_I^\top\bar k_J}{\sqrt d}.
$$

For each query tile $I$, the router selects approximately $\rho M$ of the $M$ key–value tiles. Selected tiles are computed with token-level precision; unselected tiles are processed by Spark-Reweight.

## 3. Spark-Reweight: calibrated representation of unselected blocks

Uniform averaging of an unselected key–value tile introduces a systematic mass error. For a key tile $J$, the standard mean-key approximation estimates its mass as

$$
\widehat m_J(q)
\approx
b_{kv}e^{s(q,\bar k_J)},
$$

with estimated log-mass

$$
\widehat\ell_J(q)
=
s(q,\bar k_J)+\log b_{kv}.
$$

The exact log-mass is

$$
\ell_J(q)
=
\log\sum_{j\in J}e^{s(q,k_j)}.
$$

Jensen’s inequality gives

$$
\ell_J(q)
-
\bigl(\log b_{kv}+s(q,\bar k_J)\bigr)
\ge 0.
$$

Therefore, mean pooling generally underestimates the contribution of a compressed tile.

Spark-Reweight uses the global mean query

$$
\bar q=\frac{1}{N}\sum_{i=1}^{N}q_i
$$

as an anchor. For tile $J$, define

$$
\mathbf e_J(\bar q)
=
\exp\left(\frac{\mathcal T_J^K\bar q}{\sqrt d}\right),
$$

and its exact anchor mass

$$
m_J(\bar q)
=
\mathbf 1^\top\mathbf e_J(\bar q).
$$

The normalized anchor weights are

$$
\mathbf w_J(\bar q)
=
\frac{\mathbf e_J(\bar q)}{m_J(\bar q)}.
$$

Using these weights, Spark-Reweight constructs attention-weighted representatives:

$$
\widetilde k_J
=
(\mathcal T_J^K)^\top\mathbf w_J(\bar q),
$$

and

$$
\widetilde v_J
=
(\mathcal T_J^V)^\top\mathbf w_J(\bar q).
$$

These differ from ordinary means because keys and values that receive greater attention under the anchor query contribute more strongly to the representatives.

A scalar logit bias calibrates the total mass:

$$
\beta_J
=
\log m_J(\bar q)
-
s(\bar q,\widetilde k_J).
$$

For an unselected tile, Spark-Reweight approximates its mass and numerator as

$$
\widehat m_J(q)
=
e^{s(q,\widetilde k_J)+\beta_J},
$$

and

$$
\widehat n_J(q)
=
\widehat m_J(q)\widetilde v_J.
$$

The compressed tile is therefore represented by

$$
(\widetilde k_J,\widetilde v_J,\beta_J).
$$

The method has a first-order Taylor interpretation. Let

$$
\ell_J(q)=\log m_J(q).
$$

Its gradient at the anchor is

$$
\nabla\ell_J(\bar q)
=
\frac{\widetilde k_J}{\sqrt d}.
$$

The first-order expansion is

$$
T_{\bar q}\ell_J(q)
=
\ell_J(\bar q)
+
(q-\bar q)^\top\nabla\ell_J(\bar q)
=
s(q,\widetilde k_J)+\beta_J.
$$

Consequently, the approximation is exact at the anchor in the sense that

$$
\widehat m_J(\bar q)=m_J(\bar q),
$$

and, because $\widetilde v_J$ is the anchor-normalized value aggregate,

$$
\widehat n_J(\bar q)=n_J(\bar q).
$$

Away from $\bar q$, Spark-Reweight is a first-order approximation. Its accuracy depends on how representative the global mean query is for the queries being processed and on the nonlinearity of the tile’s log-sum-exp function.

## 4. Integrated inference procedure

Spark-Attn is applied independently for each attention head and denoising step. The procedure begins with current projections $Q$, $K$, and $V$. A preference metric is estimated from sampled tokens, and Spark-Reblock produces fixed-size preference-aware tiles.

The tile means $\bar q_I$ and $\bar k_J$ are then computed, and routing scores

$$
r_{IJ}
=
\frac{\bar q_I^\top\bar k_J}{\sqrt d}
$$

are used to select an exact tile set $\mathcal S_I$ for each query tile. Exact blocks satisfy $J\in\mathcal S_I$ and are evaluated using the full token-level score matrix. For query $q_i$, the exact contribution from tile $J$ is

$$
(n_J(q_i),m_J(q_i))
=
\sum_{j\in J}
e^{s(q_i,k_j)}(v_j,1).
$$

For unselected tiles, Spark-Reweight supplies $\widehat n_J(q_i)$ and $\widehat m_J(q_i)$. The complete output is

$$
\widehat o(q_i)
=
\frac{
\sum_{J\in\mathcal S_I}n_J(q_i)
+
\sum_{J\notin\mathcal S_I}\widehat n_J(q_i)
}{
\sum_{J\in\mathcal S_I}m_J(q_i)
+
\sum_{J\notin\mathcal S_I}\widehat m_J(q_i)
}.
$$

Selected tiles are masked out of the compressed branch so that no tile is double-counted. Exact and compressed branches contribute to the same denominator. Consequently, an unselected tile can alter the normalized weights assigned to exact keys, even though its internal token-level interactions are not evaluated.

The principal control parameter is exact density $\rho$. A smaller $\rho$ increases speedup but places greater reliance on compressed tile representations. A larger $\rho$ improves fidelity while reducing acceleration. The overall speed is not exactly $1/\rho$ because reblocking, routing, compression, permutations, kernel launches, and compressed-query evaluation remain part of the computation.

Spark-Attn is inference-only. It does not modify model parameters, LoRAs, or denoising schedules, and does not require model retraining. The reported experiments use dense warm-up steps before sparse attention, allowing early denoising structure to form before applying aggressive sparsification.

## 5. Experimental results

### MiniMax-H3

The primary evaluation uses MiniMax-H3 to generate 14.4-second videos at $1344\times768$ resolution with 345 frames and 20 denoising steps. The first four denoising steps are dense, and quality is measured relative to dense outputs.

| Method | Density | DiT latency | Speedup | PSNR |
|---|---:|---:|---:|---:|
| Dense | 100% | 4061.8 s | $1.00\times$ | $\infty$ |
| PISA | 10% | 1643.4 s | $2.47\times$ | 20.20 dB |
| Sol-H3 | approximately 20.8% | 1781.9 s | $2.28\times$ | 21.26 dB |
| Spark-H3 | 10% | 1629.6 s | $2.49\times$ | 24.81 dB |
| Spark-H3 | 20% | 1796.1 s | $2.26\times$ | 26.76 dB |
| Spark-H3$^\dagger$ | 20% | 1818.0 s | $2.23\times$ | 26.89 dB |

At 10% density, Spark-H3 achieves the highest reported speedup and a PSNR of 24.81 dB. At 20% density, PSNR increases to 26.76 dB while the DiT speedup remains $2.26\times$. Spark-H3$^\dagger$ reaches 26.89 dB but is slightly slower.

The dense baseline has SSIM $1.00$, LPIPS $0$, and VBench $84.38$. Spark-H3 at 20% density reaches SSIM $0.86$, LPIPS $0.09$, and VBench $84.50$. Spark-H3$^\dagger$ reaches SSIM $0.87$, LPIPS $0.08$, and VBench $84.56$.

### LTX-2.5

The second evaluation uses LTX-2.5 for 10-second videos at $3840\times2176$. The reported sparse-attention latency covers the second stage of the generation process.

| Method | Density | Latency | Speedup | PSNR |
|---|---:|---:|---:|---:|
| Dense | 100% | 1223.6 s | $1.00\times$ | $\infty$ |
| PISA | 10% | 313.4 s | $3.90\times$ | 29.20 dB |
| Sol-Attn | approximately 18.5% | 385.7 s | $3.17\times$ | 24.72 dB |
| Spark-Attn | 10% | 312.0 s | $3.92\times$ | 30.84 dB |
| Spark-Attn | 20% | 415.1 s | $2.95\times$ | 32.68 dB |
| Spark-Attn | 50% | 736.9 s | $1.66\times$ | 36.79 dB |
| Spark-Attn$^\dagger$ | 50% | 737.8 s | $1.66\times$ | 35.16 dB |

At 10% density, Spark-Attn matches PISA’s latency while improving PSNR by 1.64 dB. Increasing density produces the expected quality–efficiency trade-off: 20% density yields 32.68 dB PSNR at $2.95\times$ speedup, while 50% density yields 36.79 dB at $1.66\times$ speedup.

### MiniMax-H3-Turbo

Spark-H3 is also evaluated on MiniMax-H3-Turbo, an eight-step distilled LoRA, using 14.4-second videos at $1344\times768$. The first two steps are dense.

| Method | Density | Speedup | PSNR |
|---|---:|---:|---:|
| Spark-H3 | 10% | $2.27\times$ | 24.80 dB |
| Spark-H3 | 20% | $2.08\times$ | 26.48 dB |
| Spark-H3$^\dagger$ | 20% | $2.07\times$ | 26.65 dB |

These results indicate that Spark-Attn can be applied to a few-step distilled model without retraining the adapted model.

## 6. Ablations, limitations, and significance

### Spark-Reblock ablation

At 10% exact-block density, removing Spark-Reblock reduces attention-mass recall from $79.69\pm0.91\%$ to $61.36\pm2.71\%$ and PSNR from 24.81 dB to 20.30 dB. At 20% density, recall falls from $88.63\pm0.61\%$ to $74.05\pm2.12\%$, while PSNR falls from 26.76 dB to 21.65 dB.

Thus, Spark-Reblock increases recall by 18.33 percentage points at 10% density and 14.58 points at 20% density. It improves PSNR by 4.51 dB and 5.11 dB at the respective densities. The method at 10% density with reblocking outperforms fixed grouping at 20% density in the reported comparison.

### Spark-Reweight ablation

At 20% density, the effect of Spark-Reweight is:

| Reblock | Reweight | Log-mass MAE | PSNR |
|---|---|---:|---:|
| No | No | 3.38 | 21.24 dB |
| No | Yes | 2.52 | 21.65 dB |
| Yes | No | 1.39 | 26.24 dB |
| Yes | Yes | 1.16 | 26.76 dB |

Spark-Reweight reduces log-mass error both with and without reblocking. Its benefit is larger after Spark-Reblock has produced more coherent tiles.

### Principal limitations

Spark-Attn remains an approximation to dense attention. Its accuracy is limited by several factors:

- **Anchor dependence**: Spark-Reweight is first-order accurate at the global mean query. Queries far from that anchor can incur larger mass errors.
- **Residual tile heterogeneity**: Spark-Reblock reduces preference variation but cannot eliminate it.
- **Routing error**: tile-mean routing can still misrank blocks when tiles remain multimodal.
- **Construction overhead**: recursive partitioning, landmark processing, rank selection, and permutations reduce the benefit at shorter sequence lengths.
- **Warm-up dependence**: the reported results use dense initial denoising steps; a fully sparse procedure could have different fidelity and speed characteristics.
- **Hyperparameter sensitivity**: tile size, landmark count, refinement updates, exact density, and partitioning strategy affect quality and latency.
- **Hardware dependence**: nominal block sparsity does not guarantee proportional wall-clock acceleration; performance depends on block-sparse kernels and scheduling.
- **Quality metric scope**: the principal measurements compare sparse outputs with dense outputs using PSNR, SSIM, LPIPS, and VBench. These establish approximation fidelity but do not constitute a guarantee of identical generated distributions or semantic quality across all prompts.

Spark-Attn’s central contribution is the joint treatment of **where attention blocks are formed** and **how unselected blocks are represented**. Spark-Reblock aligns regular GPU tiles with attention preferences, while Spark-Reweight preserves compressed-block mass through an attention-weighted representative and a calibrated logit bias. The resulting method retains exact computation for a small fraction of blocks and approximates the remainder under a common softmax normalization. In the reported long-video settings, this yields $2.49\times$ DiT speedup at 10% exact-block density with 24.81 dB PSNR on MiniMax-H3, and 26.76 dB PSNR at 20% density with $2.26\times$ speedup.

Source: https://www.emergentmind.com/topics/spark-attn