Learning Semi-Structured Sparsity for LLMs via Shared and Context-Aware Hypernetwork

Lu Sun, Jun SakumaICLR 2026

TL;DR

HyperPrune is a resource-efficient framework that uses a shared, lightweight "hypernetwork" to generate optimal $n:m$ pruning masks for Large Language Models (LLMs). By bridging the gap between fast-but-simple heuristics and slow-but-accurate optimization, it achieves state-of-the-art accuracy on models as large as LLaMA-70B using just a single A100 GPU.

The Challenge of LLM Pruning

Deploying LLMs is notoriously expensive due to their massive memory and computational footprints. To solve this, researchers use pruning—removing unnecessary weights. The industry is increasingly moving toward $n:m$ semi-structured sparsity (e.g., 2:4 sparsity, where 2 out of every 4 consecutive weights are zero). This specific pattern is "hardware-friendly" because modern NVIDIA GPUs (like the A100 and H100) can leverage it to double computational throughput.

However, finding the perfect mask for billions of parameters is challenging. Current methods generally fall into two camps:

  1. One-shot Heuristics (e.g., Wanda, SparseGPT): These are fast but rely on simple rules (like "remove the smallest weights"). They often suffer significant accuracy drops at high sparsity levels.
  2. Optimization-based Methods (e.g., MaskLLM): These treat mask selection as a learning problem. While accurate, they are computationally "heavy," often requiring thousands of GPU hours and massive memory to store mask parameters for every single layer.

The authors tackle this accuracy-efficiency trade-off, seeking a way to optimize masks without needing a supercomputer.

The HyperPrune Methodology

The core innovation of this paper is HyperPrune, which eliminates the need to store and learn individual masks for every layer. Instead, it utilizes a single, shared Hypernetwork.

HyperPrune Architecture
  • Shared Hypernetwork ($h_\theta$): Instead of learning a billion-parameter mask, HyperPrune learns a small neural network that generates the masks. Crucially, this hypernetwork is shared across all layers of the LLM, drastically reducing the number of parameters to be optimized.
  • Context-Aware Embeddings: To help the shared hypernetwork distinguish between different parts of the LLM, it is provided with "context." This includes layer embeddings (indicating the depth of the layer) and component embeddings (indicating whether the target is a Query, Key, or Feed-Forward matrix).
  • Continual Pruning & Regularization: As the model prunes layer-by-layer, it uses a regularization term to ensure the hypernetwork doesn't "forget" how to prune earlier layers effectively. Furthermore, HyperPrune employs Feature Outlier Regularization to protect the weights connected to high-magnitude "outlier" activations, which are critical for LLM performance.
Differentiable Mask Generation
  • Differentiable Masking: Since selecting a mask is a discrete "yes/no" decision (which isn't naturally differentiable), the framework uses the Gumbel-Softmax trick. This translates discrete mask sets into probabilities, allowing the hypernetwork to be trained using standard gradient descent based on layer-wise loss.

Datasets and Evaluation

The authors evaluated HyperPrune on the LLaMA-2 family (7B, 13B, and 70B parameters) and the newer LLaMA-3 8B.

  • Calibration: The hypernetwork was trained using 128 sequences from the C4 dataset.
  • Evaluation: Performance was measured using Wikitext-2 for perplexity (how well the model predicts the next word) and the EleutherAI LM Harness—a suite of seven zero-shot reasoning tasks (including BoolQ, RTE, and HellaSwag) to test real-world capabilities.

Key Insights

  • Structural Regularity: The success of a shared hypernetwork suggests that LLM layers, despite their different roles, share underlying structural patterns in how they can be pruned.
  • The Information Theory Link: The authors provide a theoretical proof showing that minimizing the "reconstruction error" of a layer (a common pruning goal) is mathematically equivalent to maximizing the Mutual Information between the original dense model and the new sparse one.
  • Efficiency is Scalability: By offloading weights and only training a tiny hypernetwork, HyperPrune can prune a 70B model on a single 80GB A100. This democratizes high-end LLM optimization for researchers without massive server farms.

Key Results

  • Superior Accuracy: On LLaMA-2 7B, HyperPrune achieved a mean zero-shot accuracy of 53.76%, outperforming both SparseGPT (51.00%) and the optimization-based MaskPro (52.81%).
  • Massive Speedup: Compared to previous optimization methods like MaskLLM, HyperPrune reduces training costs by nearly an order of magnitude. It requires only 7–15 GPU hours for 7B/13B models.
  • Hardware Gains: The 2:4 sparse patterns generated by HyperPrune translated to actual hardware speedups of 1.55x to 1.65x in matrix multiplication kernels on an A100 GPU.
  • Data Efficiency: The model scales beautifully with more data; even with only 32 calibration samples, it remains highly competitive.

Limitations and Future Work

  • Domain Sensitivity: Like most pruning methods, HyperPrune relies on calibration data. If the calibration data (C4) is very different from the deployment data, performance might dip.
  • Hypernetwork Capacity: There is a trade-off between how "lightweight" the hypernetwork is and its ability to generalize across 80+ layers in a 70B model.
  • Future Directions: The authors suggest combining HyperPrune with quantization (reducing bit-precision) or low-rank adaptation (LoRA) to push LLM compression even further.

Summary updated

BibTeX
@inproceedings{sun2026learning,
  author = {Lu Sun and Jun Sakuma},
  title = {{Learning Semi-Structured Sparsity for LLMs via Shared and Context-Aware Hypernetwork}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=lqjQs2lVNm},
}
Figure