Reading Notes on E³-PRUNER
This is a pruning method proposed by Huawei.
At a high level, it has two key steps:
- Prune the model.
- Fine-tune the model.
During the training loop, pruning and fine-tuning are optimized jointly in the early iterations. The remaining iterations perform fine-tuning only.
Searching for a Pruning Configuration
Naively, given a parameter K, finding the best way to remove K layers from a model would require brute-force enumeration followed by evaluation. For every dataset, this means evaluating
C(L,K)=K!(L−K)!L!
possible configurations.
Even setting aside the cost of millions or trillions of configurations multiplied by tens of thousands of samples, pruning K layers all at once can easily produce a false optimum. Every candidate is likely to emit nonsense immediately after such aggressive pruning, and choosing the best result from a collection of broken outputs is not meaningful.
Removing layers one at a time can also lead to mistakes. Once a layer has been removed, the decision cannot be undone. A layer that appears unimportant on the current data may in fact be useful elsewhere, so a greedy procedure is unlikely to find the global optimum.
These problems arise from discrete pruning. Discrete decisions leave no room for error correction. E3-PRUNER instead uses Gumbel-TopK to turn a discrete Top-K choice into a differentiable approximation.
The Gumbel-TopK Algorithm
Requires: layer scores S, temperature τ, and number of retained layers k.
1:S1=S+Gumbel(0,1)2:M~1=03:fori=1tokdo4:Si+1=Si+log(1−Softmax(τSi))5:M~i+1=M~i+Softmax(τSi)6:end for7:M=STE(TopK(M~k+1,k))8:returnPruning maskM
As shown above, every layer has a score S. A Gumbel noise term is added to each score at initialization, preventing tiny changes among nearly equal scores from producing disproportionately large changes in the selection.
Line 4 “penalizes” repeatedly selected high scores so that the method does not keep choosing the same few layers. The crucial component is the STE (Straight-Through Estimator), which makes backpropagation possible through the selection operation.
The temperature τ follows a linear annealing schedule, allowing broader exploration early in training.
The iterative update is:
M~i+1=M~i+Softmax(τSi),Si+1=Si+log(1−Softmax(τSi))
Fine-Tuning
1. Joint Training
After a particular layer is removed, the model weights must be fine-tuned accordingly; otherwise accuracy drops sharply.
Algorithm 1:
Parameters:
- LLM Θ
- Total number of iterations T
- Number of mask-search iterations TM
- Layer scores S
- Layer mask M
- Total number of layers L
1:fort=1toTdo2:τ=1−β⋅t/T,k′=L−⌈(L−k)⋅t/T⌉3:ift≤TM:4:M=Gumbel-TopK(S,τ,k′)5:S=S−λ⋅∂L(x,Θ,M)/∂S6:end if7:Θ=Θ−λ⋅∂L(x,Θ,M)/∂Θ8:end for9:returnPruned modelΘ∗
The important detail is that the STE (Straight-Through Estimator) makes the backward pass possible.
The Gumbel-TopK procedure is written as Algorithm 2 in my notes:
Parameters:
- Layer scores S
- Temperature τ
- Number of layers k
1:S1=S+Gumbel(0,1)2:M1~=03:for i=1 to k do4:M=Gumbel-TopK(S,τ,k′)5:S=S−λ⋅∂L(x,Θ,M)/∂S6:end if7:Θ=Θ−λ⋅∂L(x,Θ,M)/∂Θ8:end for9:returnPruned modelΘ∗
The loss function described in the paper is:
{Θ∗,M∗}=argminΘ,ML(x;Θ,M)s.t.∥M∥0=k
This leads to the adaptive distillation loss:
Ladaptive-KD=N1∑i=1NH(Softmax(zt(i))c)⋅∑c∈SiKSoftmax(zt(i))c⋅log(Softmax(zs(i))cSoftmax(zt(i))c)
It has two parts. First, the token loss:
Ltoken=∑c∈SiKSoftmax(zt(i))c⋅log(Softmax(zs(i))cSoftmax(zt(i))c)
Here, zs is the student’s output and zt is the teacher’s output. Because running the teacher online during training would be expensive, its top-K logits are computed and stored in advance.
The weighting term is:
Wi=H(Softmax(zt(i))c)
2. Post-Training
As shown in Algorithm 1, after the joint-training phase the remaining iterations optimize only the model parameters. The goal is to recover accuracy while keeping the pruned architecture fixed.
Further Thoughts
Training against the output distribution often has a higher ceiling than directly aligning vector directions, because directional alignment does not necessarily make the final logits more accurate.
Once a large model produces a hidden representation h, the final logits are obtained from
z=Wuh
After pruning, the predicted hidden representation will deviate to some extent. Let h′=h+Δh. Then:
z′=Wuh′=Wu(h+Δh)=z+WuΔh
The final logit distribution therefore does not depend only on the similarity of the vector Δh. It depends on the complete product WuΔh.
Even when Δh is large, the logits can still be approximated well if the distribution of its elements overlaps strongly with the null space of Wu.
Conversely, even a small Δh can produce a large logit error Δz if it happens to align with directions in which Wu has large values. This is why directly aligning hidden-vector directions can have a lower performance ceiling.
The corresponding advantage is lower training cost. The learned vectors are also unlikely to differ drastically from those produced by output-distribution training. In theory, aligning the outputs during post-training should therefore recover better results.