Manuscript Offprint

arXiv:2610.01554

QK-Wanda: Coupling Queries and Keys for Unstructured Pruning

Ivan Ilin, Peter Richtárik

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

WANDA (Sun et al., 2024) prunes large language models by scoring weights independently within each linear projection, although queries and keys interact through dot products. We introduce QK-WANDA, which scores query and key weights by their individual deletion costs under an unmasked pre-RoPE reconstruction objective. It augments Wanda scores with information from the opposite projection—keys for query weights, and queries for key weights—allowing both projections to share a pruning budget. Its closed-form scores require no gradients or weight updates; full pruning takes 1.3% longer than Wanda on A100 and 3.1% longer on H200 with the calibration used in our main experiments. We evaluate QK-only pruning across 15 models from TinyLlama, Llama 2, Llama 3, and Qwen2.5, spanning 0.5B–72B parameters. Relative to Wanda, QK-WANDA reduces QK reconstruction error by an average of 60% at 50% sparsity and 45% at 80%. Downstream gains depend on the model. At 80% sparsity on Llama 2 70B, WikiText-2 and C4 perplexity decrease by 20.3% and 13.5%, while mean zero-shot accuracy rises by 5.94 percentage points. Qwen2.5-72B also improves, but Llama-3.1-70B has substantially higher perplexity despite lower reconstruction error. These results show both the promise of coupled pruning criteria and the limits of local reconstruction as a predictor of model quality.

1 INTRODUCTION

Large language models (LLMs) perform well across language understanding, generation, and reasoning tasks, but storing and running their billions of parameters remains expensive (Touvron et al., 2023; Grattafori et al., 2024; Qwen et al., 2024). Model compression addresses this cost. Quantization reduces the bits per weight; pruning sets selected weights to zero. Both seek to preserve predictive quality. We focus on unstructured pruning (Hoefler et al., 2021).

WANDA selects weights using their magnitudes and calibration activations, without updating retained weights (Sun et al., 2024). We focus on this mask-only setting, rather than methods that also compensate for pruning errors, such as SPARSEGPT and THANOS (Frantar & Alistarh, 2023; Ilin & Richtárik, 2025). Our question is whether accounting for query–key interactions can improve these scalar pruning decisions.

Wanda measures each deletion through its effect on an individual projection. In attention, however, a query perturbation changes dot products according to the keys it interacts with, and vice versa (Vaswani et al., 2017). QK-WANDA therefore scores deletions using a common reconstruction objective for all query-key products (Equation (6)). The resulting query and key scores measure changes to the same objective, allowing a fixed pruning budget to be allocated across rows and between the two projections.

QK-Wanda changes only how query and key weights are scored, so this paper focuses on pruning query and key weights. Unless stated otherwise, all other weights stay dense and sparsity refers to the query and key weights alone. Across our checkpoints, these weights make up 6–17% of the linear-layer weights in a transformer block and 4–16% of all parameters (Appendix E.4). The remaining projections can still be pruned with Wanda; Section 4.5 evaluates this broader pruning scope.

References (100)

  • GQA: Training generalized multi-query transformer models from multi-head checkpoints
  • SliceGPT: Compress large language models by deleting rows and columns
  • SparseLLM: Towards global pruning of pre-trained language models
  • BoolQ: Exploring the surprising difficulty of natural yes/no questions
  • Think you have Solved Question Answering? Try ARC, the AI2 Reasoning Challenge
  • Extreme compression of large language models via additive quantization
  • EleutherAI. EleutherAI lm-evaluation-harness v0.4.12. Zenodo, 2026. URL https://doi.org/10.5281/zenodo.20122284. (opens the publisher in a new tab)
  • SparseGPT: Massive language models can be accurately pruned in one-shot
  • Optimal brain compression: A framework for accurate post-training quantization and pruning (opens arXiv in a new tab)
  • GPTQ: Accurate post-training quantization for generative pre-trained transformers
  • The Llama 3 Herd of Models
  • Second order derivatives for network pruning: Optimal Brain Surgeon
  • Data-independent module-aware pruning for hierarchical vision transformers
  • Sparsity in deep learning: Pruning and growth for efficient inference and training in neural networks
  • FASP: Fast and accurate structured pruning of large language models (opens arXiv in a new tab)
  • Thanos: A block-wise pruning algorithm for efficient large language model compression (opens arXiv in a new tab)
  • Beware of calibration data for pruning large language models (opens arXiv in a new tab)
  • SparseLoRA: Accelerating LLM fine-tuning with contextual sparsity
  • Towards next-level post-training quantization of hyper-scale transformers
  • BoA: Attention-aware post-training quantization without backpropagation
  • Optimal brain damage
  • Beyond linear approximations: A novel pruning approach for attention matrix
  • Preserving deep representations in one-shot pruning: A hessian-free second-order optimization framework
  • LLM-Pruner: On the structural pruning of large language models (opens arXiv in a new tab)
  • PV-Tuning: Beyond straight-through estimation for extreme LLM compression
  • HIGGS: Pushing the limits of large language model quantization via the linearity theorem
  • Association for Computational Linguistics, 2025 (opens the publisher in a new tab)
  • CLOVER: Cross-layer orthogonal vectors pruning
  • Pointer Sentinel Mixture Models
  • Can a suit of armor conduct electricity? a new dataset for open book question answering
  • Qwen2.5 Technical Report
  • Exploring the limits of transfer learning with a unified text-to-text transformer
  • WinoGrande: An adversarial winograd schema challenge at scale
  • SNP: Structured neuron-level pruning to preserve attention scores
  • RoFormer: Enhanced transformer with rotary position embedding (opens the publisher in a new tab)
  • A simple and effective pruning approach for large language models
  • Llama 2: Open Foundation and Fine-Tuned Chat Models
  • QTIP: Quantization with trellises and incoherence processing
  • Attention is All you Need
  • GLUE: A multi-task benchmark and analysis platform for natural language understanding
  • $A^{3}$: An analytical low-rank approximation framework for attention
  • RAP: KV-cache compression via RoPE-aligned pruning (opens arXiv in a new tab)
  • ThinK: Thinner key cache by query-driven pruning
  • Wanda++: Pruning large language models via regional gradients (opens the publisher in a new tab)
  • Symmetric pruning of large language models (opens arXiv in a new tab)
  • Outlier weighed layerwise sparsity (OWL): A missing secret sauce for pruning LLMs to high sparsity
  • HellaSwag: Can a machine really finish your sentence? In Proceedings of ACL, 2019
  • CORP: Closed-form one-shot representation-preserving structured pruning for transformers (opens arXiv in a new tab)
  • TinyLlama: An open-source small language model (opens arXiv in a new tab)
  • Plug-and-play: An efficient post-training pruning method for large language models
  • Derivations fix one block; $h, g$ index its heads and $s$ its input sequences
  • Sections B.2 and B.3 give the full formulas, proofs, and a two-token example
  • All heads have common width $m$
  • For $h \in \mathcal{H}_g$, define the $T_s \times T_s$ matrices
  • The entry $B_{tu}^{(h,s)}$ sums the products of matching coordinates of query token $t$ and key token $u$, following the unscaled convention in Section 3.1
  • We sum squared changes over allowed token pairs and heads, then average sequences
  • The bias cancels when taking the difference of the two affine projections
  • For the causal mask, only $u \leq t$ remains in the inner sum, yielding Equation (14)
  • Heads outside $H_g$ do not change
  • For the causal mask, valid query positions satisfy $t \geq u$, giving Equation (15)
  • The evaluated runner uses fixed-length unpadded windows with ordinary causal attention; the mathematical statement does not imply implementation support for every mask layout
  • Suppress the sequence/head labels
  • Delete $W_{11}^{Q} = 2$, the weight from input feature 1 to query coordinate 1
  • This example makes explicit what the mask, squared norm, and prefix sum each contribute
  • The notation $[i, t]$ selects the entry at row i, column t:
  • Each resulting interaction matrix has shape $m \times d$
  • The formulas report unscaled deletion costs; this common factor preserves their ranking under separate or shared budgets
  • The operation $\text{vec}(M)$ stacks columns in order; $\otimes$ denotes the Kronecker product
  • Each coefficient matrix is positive semidefinite: $v^\top G v \geq 0$ for every vector $v$, because it represents a sum of squared dot-product changes
  • Summing scalar scores retains only its diagonal terms
  • This structural match does not by itself establish a downstream advantage over the unmasked objective
  • Both use the same single-weight deletion principle as the main text
  • Here we extend Equation (7) to independent calibration sequences using the head notation of Section 3.2
  • The scores reduce to
  • Let $R_t^{(s)} \in \mathbb{R}^{m \times m}$ be the model's fixed rotary position map for token $t$ in sequence $s$
  • Use $C_{tu}^2 = C_{tu}$, and substitute the preceding identity to obtain Equation (37) exactly
  • Squaring each valid entry and summing over those heads gives Equation (38)
  • Their squared reconstruction loss is therefore $\mathcal{L}_R/m$; this common factor leaves the single-deletion ranking unchanged
  • Their off-diagonal entries retain products between the two coordinates
  • Write its rotation angle as $\theta$, with $c_{\theta} = \cos \theta$ and $s_{\theta} = \sin \theta$
  • Its two rotated diagonal entries are
  • Both variants used separate whole-matrix budgets, one-shot masks, and identical calibration inputs for each seed
  • PPL is the mean and sample standard deviation over three calibration seeds
  • Post-RoPE QK and block-output errors use the pooled squared-error ratio in Equation (51)
  • We distinguish pruning calibration from the reconstruction diagnostic and downstream evaluation so that their results can be interpreted under the appropriate input and aggregation rules
  • Each base sample is a contiguous 2048-token window from one document
  • Splitting these windows into length-64 segments gives 8192 independent calibration sequences
  • Every tested length T divides 2048, so all segmentations retain exactly the same tokens and use 524,288/T independent sequences
  • C4 evaluation used the first 1100 documents of en/c 4-validation.00000-of-00008.json.gz, joined by spaces and truncated to at most $256 \times 2048$ tokens
  • The comparisons include row-wise WANDA, QK-WANDA with separate and shared budgets, and the labeled scoring variants in the result tables
  • We used scaled dot-product attention throughout
  • These documents were disjoint from the C4 perplexity subset and the calibration training split
  • Within each block, we summed squared errors and dense reference energies over these indices, including all query heads that share a key head under GQA, then divided
  • It isolates each block's QK reconstruction on dense inputs; it does not include error propagated from previously pruned blocks
  • All reference errors are positive at these sparsities
  • Here $Z_{\ell}^{(h,s)}$ adds the block index to the post-RoPE products in Equation (36)
  • QK counts include only projection weights; biases remain dense
  • Subsequent H200 jobs used Python 3.12.3
  • Pruning statistics are accumulated in FP32
  • Our row-wise Wanda implementation removed $\lceil \rho d \rceil$ weights per output row of width $d$; the matched row-wise QK-Wanda-M control used the same convention

Couldn't load all references. Reload the page to try again.