How to train a deletion mask
This post is the workshop version: how a mask is actually trained, what it costs, and what we changed from the paper's script. The method, again, is Deletion Tuning (Lu et al., arXiv 2611.10866, NeurIPS 2026, code at agentic-learning-ai-lab/deleting-weights). Our 9B and 27B ToolAlpaca masks follow their supervised fine-tuning recipe.
The loop, in four steps
scripts/train_sft.sh: 400 steps, learning rate 5e-4, batch size 4, sharpness 100 to 1,000.flowchart LR
A[Wanda prior] --> B[Soft mask]
B --> C[Answer-token loss]
C --> D[Hard mask file]
1. A Wanda prior. Before any training step, the trainer scores each gate_proj weight the way Wanda does (Sun et al., 2023, arXiv 2306.11695):
score_ij = |W_ij| · ‖X_·j‖
Low-scoring weights are the ones the prior would rather delete. The trainer then shifts the mask logits: down for those weights, up for the rest, by prior_strength standard deviations (3.0 in our runs). About init_sparsity = 1/2048 ≈ 0.049% of the weights start already on the deleted side. After this, our 9B runs had about 0.18% of logits on the deleted side of zero, before the 400 training steps moved that number up to about 0.66–0.68%.
2. A soft mask, getting sharper. At each step the mask is m = σ(g · s). Sharpness s rises linearly from 100 to 1,000 over the 400 steps. Early updates can still flip a weight's fate; late updates are closer to a hard yes or no.
3. A loss on the answers, not on the base weights. The pretrained weights stay frozen. The only trainable numbers are the mask logits. The main loss is the usual next-token cross-entropy, taken on the answer tokens of each training example (4,046 ToolAlpaca training items in our runs). A small sparse-weight regularizer starts at 10⁻⁵ and decays linearly to 0, which nudges the mask not to delete everything.
I should be honest about a gap: the summary.json files from our runs record sparsity, step time, and eval scores, but they do not export the per-step training loss. I am not going to invent a loss curve. The scores I trust are the held-out exact-match numbers in the next post.
4. A hard mask on disk. After training, a weight is kept exactly when its logit is positive. That binary map is what we save: about 20 MB for a 9B cartridge, 57 MB for the preferred 27B one.
Our recipe, including the small deviations
We used the paper's SFT defaults (400 steps, lr 5 × 10⁻⁴, batch 4, max sequence 2,048, sharpness 100 → 1,000, Wanda prior 3.0, weight_reg 10⁻⁵). A few engineering choices were ours, and they are written down in the training script:
- Build the mask once per optimizer step, not on every forward. The regularizer's gradient is applied to the logits in closed form so it matches the paper's path. There is a
--mask_path upstreamswitch if we want their exact path. - Run the loss only on answer positions, so we do not materialize a giant
[batch, seq, vocab]logit tensor. - Calibrate Wanda on 256 training prompts, not the whole train set.
- Split layers across devices with plain hooks, so the same script can also run on CPU + MPS.
Our 9B masks were trained with this SFT loss, not with the paper's on-policy self-distillation (SDFT) path. The published 7B ToolAlpaca and Science masks from Lu et al. were trained with SDFT. That difference matters when we compare to their 7B files later.
What it cost
Each 9B run completed 400 steps on one Hugging Face rtx-pro-6000 at $2.75/hour. Full wall clock, including download, Wanda, a base eval, training, and a masked eval:
| Run | Wall clock | Minutes | Cost = wall × $2.75 / 3600 |
|---|---|---|---|
| Seed 1 | 741.74 s | 12.36 | $0.567 |
| Seed 2 | 730.04 s | 12.17 | $0.558 |
| Seed 3 | 742.26 s | 12.37 | $0.567 |
Training itself was about 480–492 seconds, a little over eight minutes. Peak CUDA memory during training was about 49 GB on that one GPU.
The 27B runs used two GPUs (rtx-pro-6000x2 at $5.50/hour). The preferred run finished in 272 of 400 requested steps, 1,446.76 s (24.1 min), which is 1446.76 × 5.50 / 3600 = $2.21. A second 27B run went the full 400 steps in 1,869.75 s ($2.86) and scored the same 65/97, while deleting more weights, so we keep run 1.
Seeds
A seed here is the training seed: 0, 2, and 3 for the three 9B masks. Everything else in the recipe stayed put. If three independent starts find a similar skill and a similar set of weights, we can be less afraid that we got lucky once. That test is the next post.
Previous: How it works inside the model. Next: How we test a mask.
Project: Skill cartridges · Tags: Deletion masks Fine-tuning Cost Model tuning