Introduction
We address one-shot pruning of a pretrained language model to the 2:4 pattern: in every consecutive group of four input channels for an output row, two weights must be removed. The mask is fixed after one calibration pass, while the surviving weights may be corrected and optional computation may be placed beside the sparse core. The design problem is therefore functional as well as combinatorial: a locally attractive mask can create errors that later layers amplify, and a correction that improves a calibration loss can still fail to preserve the model's output distribution.
Published work explores several parts of this space, from simple pruning and post-training criteria to one-shot reconstruction and optimization. Other references study block-wise compression and semistructured factorization. These approaches motivate using calibration statistics and reconstruction, but they leave a practical choice for this task: how to make the mask robust when the calibration second moment is poorly conditioned, and how to repair the cascade of already-pruned activations without adding a dense side path.
We propose RBR. First, we select the mask with a damped inverse second moment and apply sequential OBS-style compensation. Next, we fit all surviving weights in a decoder block together, using the dense block output as the target while feeding the block the activations produced by the pruned prefix. Finally, for a tail of blocks, we optimize the dense-versus-pruned next-token KL divergence jointly. The code keeps the mask fixed throughout these reconstructions and returns only the sparse core.
Method
Robust 2:4 mask selection
For a linear layer with weight matrix and calibration second moment , we first work in float precision. Zero-activity input channels are given a unit diagonal in and their weights are zeroed. We then add an isotropic term
The code forms an upper Cholesky factor of the inverse, so that . At the start of each consecutive group of prune_m channels and for each output row, it scores column by
and selects the prune_n smallest scores. The task supplies the 2:4 choice, so this is a row-wise comparison of the two least costly removals in each four-channel group. After choosing a mask entry, let be the current column with the selected entries set to zero, , and . Within the current block, we update the remaining columns by
This makes the mask and the compensation part of the same sequential decision. If the factorization fails or produces a non-finite factor, the implementation falls back to an activation-weighted magnitude metric and returns masked weights without the OBS correction.
class LayerPruner:
"""Block-reconstructed 2:4 pruning with an output-level refinement of the tail.
1. Per linear layer: OBS-style sequential mask selection and weight
compensation on a ROBUSTIFIED second moment H + lam * mean(diag H) * I.
The calibration windows under-represent the input directions met at
test time; the isotropic term stands for them, and the mask (the one
thing the later stages cannot repair) is chosen under it. lam is 30
times the customary numerical damping. The mask is final.
2. Per decoder block: the surviving weights of all the block's linears are
fitted jointly so that the pruned block, fed the ALREADY-PRUNED model's
activations, reproduces what the DENSE model's block outputs on the
dense activations (so the block also repairs upstream drift). The fit
is deliberately gentle (small steps): beyond a point, moving the kept
weights further from their dense values buys calibration fit only.
3. Tail: a hidden-state error only matters through what the rest of the
network does with it, and for the last blocks "the rest" is the output
head. Once the last blocks are fitted as in (2), their surviving weights
are refined together on the divergence between the dense model's and
the pruned model's next-token distributions (same calibration windows). def _obs_prune(self, W, H, cfg):
sparsity = cfg["sparsity"]
prune_n, prune_m = cfg["prune_n"], cfg["prune_m"]
W = W.clone().float()
H = H.clone().float()
rows, columns = W.shape
dev = W.device
dead = torch.diag(H) == 0
H[dead, dead] = 1
W[:, dead] = 0
damp = self.percdamp * torch.mean(torch.diag(H))
diag = torch.arange(columns, device=dev)
H[diag, diag] += damp
Hinv = None
for _ in range(8):
try:
L = torch.linalg.cholesky(H)
Hinv = torch.linalg.cholesky(torch.cholesky_inverse(L), upper=True)
break
except Exception:
H[diag, diag] += damp
damp = damp * 2
if Hinv is None or not bool(torch.isfinite(Hinv).all()):
metric = torch.abs(W) * torch.sqrt(torch.diag(H).reshape((1, -1)))
mask = select_by_metric(metric, sparsity, prune_n, prune_m, per_output_row=True)
return mask, W.masked_fill(mask, 0.0) mask = torch.zeros_like(W, dtype=torch.bool)
for i1 in range(0, columns, self.blocksize):
i2 = min(i1 + self.blocksize, columns)
count = i2 - i1
W1 = W[:, i1:i2].clone()
Q1 = torch.zeros_like(W1)
Err1 = torch.zeros_like(W1)
Hinv1 = Hinv[i1:i2, i1:i2]
if prune_n == 0:
tmp = W1 ** 2 / (torch.diag(Hinv1).reshape((1, -1))) ** 2
flat = tmp.flatten()
k = min(int(flat.numel() * sparsity), flat.numel())
flat_mask = torch.zeros_like(flat, dtype=torch.bool)
if k > 0:
flat_mask[torch.argsort(flat, stable=True)[:k]] = True
mask1 = flat_mask.reshape(tmp.shape)
else:
mask1 = torch.zeros_like(W1) == 1
for i in range(count):
w = W1[:, i]
d = Hinv1[i, i]
if prune_n != 0 and i % prune_m == 0:
tmp = W1[:, i:(i + prune_m)] ** 2 \
/ (torch.diag(Hinv1)[i:(i + prune_m)].reshape((1, -1))) ** 2
mask1.scatter_(1, i + torch.topk(tmp, prune_n, dim=1, largest=False)[1], True)
q = w.clone()
q[mask1[:, i]] = 0
Q1[:, i] = q
err1 = (w - q) / d
W1[:, i:] -= err1.unsqueeze(1).matmul(Hinv1[i, i:].unsqueeze(0))
Err1[:, i] = err1
W[:, i1:i2] = Q1
mask[:, i1:i2] = mask1.bool()
W[:, i2:] -= Err1.matmul(Hinv[i1:i2, i2:])
W = W.masked_fill(mask, 0.0)
if not bool(torch.isfinite(W).all()):
W = torch.nan_to_num(W, nan=0.0, posinf=0.0, neginf=0.0)
return mask, WJoint reconstruction of a decoder block
The mask is final, but the surviving values are not. For every prunable linear in a block, we retain the robust mask and its compensated weights. We then fit all those weights jointly, zeroing masked gradients so only surviving entries update. The input is the activation stream from the already-pruned prefix; the target is the output of the dense block on the dense stream. The normalized objective is
Here is the number of calibration windows.
The code uses Adam with a per-layer step proportional to the root-mean-square of the kept starting weights, ft_lr = 5e-3, batches of ft_bs = 4, and at most ft_epochs = 16 passes. The learning rate decays linearly over the schedule. Gradients at masked positions are set to zero after backpropagation, and the mask is applied again before returning. A fit is accepted only when its final loss is a number, all returned weights are finite, and the loss is no larger than its initial value; otherwise the compensated starting weights are restored.
def eval_loss():
tot = 0.0
for b in range(0, N, bs):
out = blk(X[b:b + bs].float(), **kw)[0].float()
tot += float(((out - Y[b:b + bs].float()) ** 2).mean()) * out.shape[0]
return tot / N / ynorm
loss0 = eval_loss()
spe = (N + bs - 1) // bs
epochs = int(self.ft_epochs)
total = epochs * spe
step = 0
ep = 0
while ep < epochs:
te = time.time()
perm = torch.randperm(N, generator=gen)
for b in range(0, N, bs):
idx = perm[b:b + bs].to(dev)
f = max(1.0 - step / total, 0.0)
for g in opt.param_groups:
g["lr"] = g["base"] * f
with torch.enable_grad():
out = forward(X[idx].float())
loss = ((out - Y[idx].float()) ** 2).mean() / ynorm
opt.zero_grad(set_to_none=True)
loss.backward()
for n in names:
lin[n].weight.grad.masked_fill_(masks[n], 0.0)
opt.step()
step += 1
ep += 1
if ep == 1:
# safety cap: shorten the schedule if a block would take too long
fit = int(self.ft_max_seconds / max(time.time() - te, 1e-6))
if fit < epochs:
epochs = max(1, fit)
total = epochs * spe
for n in names:
lin[n].weight.requires_grad_(False)
lin[n].weight.data.masked_fill_(masks[n], 0.0)Output-level refinement of the tail
The optional prepare hook copies the output head and a tail of dense decoder blocks to CPU. The tail size is the rounded tail_frac = 0.5 share of the decoder depth, reduced when the available-memory estimate cannot hold it. When processing reaches the first tail block, RBR solves the tail in one pass. Each later tail block is reconstructed against the dense stream, while the student stream is advanced through the fitted preceding tail blocks.
After those block fits, the student and teacher are compared through the copied head. With and denoting student and dense logits, the output objective is
For the keep-or-reject check, the code averages this quantity over the first min(N,16) windows.
All surviving weights in the tail are optimized jointly with kd_lr = 3e-4, kd_epochs = 4, and kd_bs = 4; masked gradients remain zero. The refinement is kept only if the KL is a number, all refined weights are finite, and the KL does not increase. The fitted tail weights are cached and reused as later blocks are processed. If tail setup or fitting raises an exception, the code clears the cache and falls back to per-block reconstruction; when the dense stream is unavailable, it uses the robust mask stage. If refinement is rejected, it keeps the fitted block weights.
# ---- tail stage ---------------------------------------------------------
def _solve_tail(self, block, cfgs, ctx):
import time
t0 = time.time()
dev = ctx.device
names = list(ctx.names)
l0, L = int(ctx.index), int(ctx.n_blocks)
kw = self._f32(dict(ctx.kwargs))
X0 = ctx.inputs.to(dev)
X, D = X0, ctx.dense_inputs.to(dev)
N = X.shape[0]
bs = max(1, min(int(self.ft_bs), N))
blocks, masks, fitted = [], [], []
for j in range(l0, L):
if j == l0:
work, dense_j, stats = block, ctx.dense_block, ctx.stats
else:
dense_j = self._tail_dense[j].to(dev)
work = copy.deepcopy(dense_j)
stats = ctx.collect(work, x=X, names=names)
Y = self._dense_out(dense_j, D, ctx.kwargs)
m_j, w_j = self._solve_block(work, names, stats, cfgs, X, Y, kw, ctx.seed, j)
del stats
blocks.append(work)
masks.append(m_j)
fitted.append(w_j)
if j + 1 < L:
Xn = torch.empty_like(X)
for b in range(0, N, bs):
Xn[b:b + bs] = work(X[b:b + bs].float(), **kw)[0].to(Xn.dtype)
X = Xn
if j != l0:
self._tail_dense[j] = None
del dense_j
D = Y
torch.cuda.empty_cache() if torch.cuda.is_available() else None params, pmask, groups = [], [], []
for blk, m_j in zip(blocks, masks):
for n in names:
w = blk.get_submodule(n).weight
w.requires_grad_(True)
kept = float((~m_j[n]).sum().clamp_min(1))
step = self.kd_lr * max(float(w.data.pow(2).sum().div(kept).sqrt()), 1e-12)
groups.append({"params": [w], "lr": step, "base": step})
params.append(w)
pmask.append(m_j[n])
n_eval = min(N, 16)
kl0 = eval_kl(n_eval)
opt = torch.optim.Adam(groups, betas=(0.9, 0.999), eps=1e-10)
gen = torch.Generator().manual_seed(1000003 * int(ctx.seed) + 7919)
kbs = max(1, min(int(self.kd_bs), N))
total = int(self.kd_epochs) * ((N + kbs - 1) // kbs)
step = 0
for ep in range(int(self.kd_epochs)):
perm = torch.randperm(N, generator=gen).tolist()
for b in range(0, N, kbs):
sel = perm[b:b + kbs]
f = max(1.0 - step / total, 0.0)
for g in opt.param_groups:
g["lr"] = g["base"] * f
opt.zero_grad(set_to_none=True)
with torch.enable_grad():
for j in sel:
(kl_of(j) / len(sel)).backward()
for w, m in zip(params, pmask):
w.grad.masked_fill_(m, 0.0)
opt.step()
step += 1
opt.zero_grad(set_to_none=True)The final return path provides masks and sparse-core weights only. It does not return a permutation, block-diagonal pre/post factors, or a low-rank branch. Thus every correction acts on values that remain in the 2:4 core, and the sparse-core structure is preserved.
Results
| Method | ① | ② | ③ | ④ | ⑤ | ⑥ | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| WikiText-2 perplexity ↓ | C4 perplexity ↓ | 2:4 speedup kept ↑ | Zero-shot accuracy, 7 tasks ↑ | 2:4 speedup kept ↑ | MMLU accuracy ↑ | GSM8K accuracy ↑ | 2:4 speedup kept ↑ | WikiText-2 perplexity ↓ | C4 perplexity ↓ | 2:4 speedup kept ↑ | Zero-shot accuracy, 7 tasks ↑ | 2:4 speedup kept ↑ | MMLU accuracy ↑ | GSM8K accuracy ↑ | 2:4 speedup kept ↑ | |
| Claude Fable 5.2 | 10.45 | 14.85 | 1.000 | 56.65 | 1.000 | 47.37 | 10.31 | 1.000 | 9.352 | 14.68 | 1.000 | 58.41 | 1.000 | 58.00 | 31.92 | 1.000 |
| Wanda | 23.16 | 34.70 | 1.000 | 46.48 | 1.000 | 29.03 | 2.426 | 1.000 | 13.81 | 21.52 | 1.000 | 54.48 | 1.000 | 54.09 | 24.49 | 1.000 |
| RIA | 22.37 | 32.89 | 1.000 | 47.04 | 1.000 | 28.66 | 2.047 | 1.000 | 13.31 | 21.51 | 1.000 | 53.83 | 1.000 | 56.32 | 24.18 | 1.000 |
| SparseGPT | 16.11 | 22.23 | 1.000 | 52.41 | 1.000 | 36.21 | 4.700 | 1.000 | 11.93 | 17.87 | 1.000 | 55.28 | 1.000 | 53.72 | 35.48 | 1.000 |
| ALPS | 14.43 | 19.27 | 1.000 | 53.10 | 1.000 | 39.18 | 5.989 | 1.000 | 10.90 | 16.29 | 1.000 | 57.81 | 1.000 | 55.02 | 31.77 | 1.000 |
| SparseSwaps | 20.02 | 27.84 | 1.000 | 50.19 | 1.000 | 29.65 | 3.260 | 1.000 | 14.77 | 21.84 | 1.000 | 55.12 | 1.000 | 50.05 | 28.05 | 1.000 |
| Thanos | 16.11 | 22.47 | 1.000 | 51.24 | 1.000 | 31.63 | 4.094 | 1.000 | 12.26 | 18.22 | 1.000 | 55.98 | 1.000 | 52.73 | 29.04 | 1.000 |
| Wisp | 21.34 | 31.14 | 1.000 | 47.27 | 1.000 | 30.23 | 2.350 | 1.000 | 13.61 | 20.95 | 1.000 | 52.95 | 1.000 | 54.71 | 22.59 | 1.000 |
| Whisper | 14.31 | 19.32 | 1.000 | 54.13 | 1.000 | 36.11 | 3.942 | 1.000 | 11.44 | 17.21 | 1.000 | 55.67 | 1.000 | 54.11 | 33.51 | 1.000 |
| GBLM-Pruner | 22.58 | 34.38 | 1.000 | 47.07 | 1.000 | 28.17 | 2.350 | 1.000 | 13.82 | 21.58 | 1.000 | 54.77 | 1.000 | 54.04 | 23.20 | 1.000 |
| Pruner-Zero | 22.87 | 34.99 | 1.000 | 47.53 | 1.000 | 28.06 | 1.820 | 1.000 | 12.98 | 20.74 | 1.000 | 54.85 | 1.000 | 53.37 | 16.38 | 1.000 |
| Wanda++ RGS | 24.09 | 35.84 | 1.000 | 46.66 | 1.000 | 28.78 | 2.123 | 1.000 | 14.52 | 23.13 | 1.000 | 54.70 | 1.000 | 53.06 | 26.08 | 1.000 |
| FISTAPruner | 16.00 | 20.74 | 1.000 | 50.45 | 1.000 | 35.93 | 5.914 | 1.000 | 12.15 | 17.70 | 1.000 | 54.44 | 1.000 | 50.82 | 26.38 | 1.000 |
| ARMOR | 11.31 | 17.13 | 0.751 | 56.03 | 0.751 | 46.40 | 7.582 | 0.751 | 9.956 | 15.88 | 0.816 | 60.36 | 0.816 | 66.46 | 47.76 | 0.816 |
| NoWag-P | 23.36 | 34.99 | 1.000 | 47.84 | 1.000 | 27.55 | 1.971 | 1.000 | 13.89 | 22.16 | 1.000 | 53.78 | 1.000 | 54.21 | 25.63 | 1.000 |
| SparseLLM | 15.68 | 21.60 | 1.000 | 52.19 | 1.000 | 34.17 | 4.246 | 1.000 | 12.40 | 18.24 | 1.000 | 54.84 | 1.000 | 51.92 | 34.19 | 1.000 |
| Wanda++ | 15.50 | 22.51 | 1.000 | 49.34 | 1.000 | 34.42 | 3.412 | 1.000 | 13.92 | 21.63 | 1.000 | 53.87 | 1.000 | 53.93 | 25.78 | 1.000 |
- ① Llama-3.1-8B · 2:4 · WikiText-2 + C4 perplexity
- ② Llama-3.1-8B · 2:4 · 7-task zero-shot
- ③ Llama-3.1-8B · 2:4 · MMLU + GSM8K
- ④ Qwen3-8B-Base · 2:4 · WikiText-2 + C4 perplexity
- ⑤ Qwen3-8B-Base · 2:4 · 7-task zero-shot
- ⑥ Qwen3-8B-Base · 2:4 · MMLU + GSM8K
On Llama-3.1-8B · 2:4 · WikiText-2 + C4 perplexity, RBR's ppl is 10.45 versus ARMOR at 11.31; lower is better, so RBR is ahead of ARMOR and ahead of the best published value 11.31 from ARMOR [11]. Its ppl_c4 is 14.85, below ARMOR's 17.13, so it is ahead of ARMOR and ahead of the best value 17.13 from ARMOR [11]. Its speed_keep is 1.000, above ARMOR's 0.751 and tied with the best published value 1.000 from Wanda [1] because higher is better.
On Llama-3.1-8B · 2:4 · 7-task zero-shot, RBR's zs_acc is 56.65, above ARMOR's 56.03, so it is ahead of ARMOR and ahead of the best published value 56.03 from ARMOR [11] because higher is better. Its speed_keep is 1.000, above ARMOR's 0.751 and tied with the best value 1.000 from Wanda [1].
On Llama-3.1-8B · 2:4 · MMLU + GSM8K, RBR's mmlu is 47.37, above ARMOR's 46.40, so it is ahead of ARMOR and ahead of the best published value 46.40 from ARMOR [11]. Its gsm8k is 10.31, likewise above ARMOR's 7.582 and ahead of the best value 7.582 from ARMOR [11]. Its speed_keep is 1.000, above ARMOR's 0.751 and tied with the best value 1.000 from Wanda [1].
On Qwen3-8B · 2:4 · WikiText-2 + C4 perplexity, RBR's ppl is 9.352, below ARMOR's 9.956, so it is ahead of ARMOR and ahead of the best published value 9.956 from ARMOR [11]. Its ppl_c4 is 14.68, below ARMOR's 15.88 and ahead of the best value 15.88 from ARMOR [11]. Its speed_keep is 1.000, above ARMOR's 0.816 and tied with the best value 1.000 from Wanda [1].
On Qwen3-8B · 2:4 · 7-task zero-shot, RBR's zs_acc is 58.41, below ARMOR's 60.36, so it is behind ARMOR and behind the best published value 60.36 from ARMOR [11] because higher is better. Its speed_keep is 1.000, above ARMOR's 0.816 and tied with the best value 1.000 from Wanda [1].
On Qwen3-8B · 2:4 · MMLU + GSM8K, RBR's mmlu is 58.00, below ARMOR's 66.46, so it is behind ARMOR and behind the best published value 66.46 from ARMOR [11]. Its gsm8k is 31.92, also below ARMOR's 47.76 and behind the best value 47.76 from ARMOR [11]. Its speed_keep is 1.000, above ARMOR's 0.816 and tied with the best value 1.000 from Wanda [1].
How we got here
The starter implementation used an unweighted magnitude score and left the weights unchanged for the harness to mask. We changed the editable region to use the second-moment inverse, sequential compensation, dense-stream access, and the two reconstruction stages described above. The submitted code therefore moves from the starter's mask-only rule to a method that repairs both block outputs and the final output distribution.
We chose the robust mask because the calibration second moment can miss input directions, while the isotropic term makes the mask less dependent on those directions. We use block fitting to repair upstream drift: later blocks see the already-pruned stream, so fitting each block only in isolation would optimize the wrong inputs. We use the output-level tail stage for the same reason at a different scale: hidden-state error matters through the distribution produced by the remaining network and head.
We tested and rejected several alternatives during development: alternative losses, regularizers, augmentations, mask-learning schemes, and optimizers. We also tested failure paths for the tail and block fits and kept the fallback behavior. We do not turn those development checks into benchmark claims; the per-setting means reported in Results are the basis for the comparisons there.
Limitations
-
Mixed measured outcomes. RBR is ahead of the best published baseline on both perplexity metrics in Llama-3.1-8B · 2:4 · WikiText-2 + C4 perplexity and Qwen3-8B · 2:4 · WikiText-2 + C4 perplexity, on zero-shot accuracy in Llama-3.1-8B · 2:4 · 7-task zero-shot, and on both accuracy metrics in Llama-3.1-8B · 2:4 · MMLU + GSM8K. It trails the best baseline on zero-shot accuracy in Qwen3-8B · 2:4 · 7-task zero-shot and on both accuracy metrics in Qwen3-8B · 2:4 · MMLU + GSM8K. It matches the best
speed_keepvalue in every setting. -
Calibration dependence. The mask and both reconstruction targets are derived from the supplied calibration stream. If that stream misses important input directions, the isotropic term is only a heuristic, and the block and tail fits can still preserve the wrong behavior.
-
Compute and memory cost. The block stage performs gradient optimization over every decoder block, and the tail stage keeps dense copies, fitted blocks, optimizer state, and the output head. The memory estimate can disable the tail, and runtime failures can reduce the method to a less expressive fallback.
-
Fixed hyperparameters. The values
percdamp = 0.3,ft_epochs = 16,ft_lr = 5e-3,ft_bs = 4,tail_frac = 0.5,kd_epochs = 4,kd_lr = 3e-4, andkd_bs = 4are fixed in the implementation. The mixed results leave open whether they are well matched to every model or calibration regime. -
No side computation. Returning only the sparse core keeps the design simple and preserves the intended sparse execution path, but it gives RBR no auxiliary branch with which to recover errors that the surviving weights cannot represent.
References
- Mingjie Sun, Zhuang Liu, Anna Bair et al. (2024). A Simple and Effective Pruning Approach for Large Language Models. ICLR.
- Elias Frantar, Dan Alistarh (2023). SparseGPT: Massive Language Models Can Be Accurately Pruned in One-Shot. ICML.
- Xiang Meng, Kayhan Behdin, Haoyue Wang et al. (2024). ALPS: Improved Optimization for Highly Sparse One-Shot Pruning for Large Language Models. NeurIPS.
- Max Zimmer, Christophe Roux, Moritz Wagner et al. (2025). SparseSwaps: Tractable LLM Pruning Mask Refinement at Scale.
- Ivan Ilin, Peter Richtarik (2025). Thanos: A Block-wise Pruning Algorithm for Efficient Large Language Model Compression.
- Linghao Kong, Inimai Subramanian, Micah Adler et al. (2026). The Sparsity Whisperer. NeurIPS.
- Rocktim Jyoti Das, Mukul Ranjan, Mingjie Sun et al. (2023). Beyond Size: How Gradients Shape Pruning Decisions in Large Language Models.
- Peijie Dong, Lujun Li, Zhenheng Tang et al. (2024). Pruner-Zero: Evolving Symbolic Pruning Metric from scratch for Large Language Models. ICML.
- Yifan Yang, Kai Zhen, Bhavana Ganesh et al. (2025). Wanda++: Pruning Large Language Models via Regional Gradients. ACL.
- Pengxiang Zhao, Hanyu Hu, Ping Li et al. (2024). A Convex-optimization-based Layer-wise Post-training Pruner for Large Language Models.
- Lawrence Liu, Alexander Liu, Mengdi Wang et al. (2026). ARMOR: High-Performance Semi-Structured Pruning via Adaptive Matrix Factorization. ICLR.
- Lawrence Liu, Inesh Chakrabarti, Yixiao Li et al. (2025). NoWag: A Unified Framework for Shape Preserving Compression of Large Language Models.
- Guangji Bai, Yijiang Li, Chen Ling et al. (2024). SparseLLM: Towards Global Pruning for Pre-trained Language Models. NeurIPS.