模型剪枝作为深度学习模型压缩的核心技术,通过移除冗余参数显著降低计算资源需求。
一、剪枝技术的数学本质与分类体系
1.1 参数空间优化视角
给定神经网络参数集合 θ ∈ R d \theta \in \mathbb{R}^d θ∈Rd,剪枝本质是寻找稀疏子集 θ ′ ⊂ θ \theta' \subset \theta θ′⊂θ使得:
min θ ′ L ( f ( x ; θ ′ ) ) s.t. ∥ θ ′ ∥ 0 ≤ k \min_{\theta'} \mathcal{L}(f(x;\theta')) \quad \text{s.t.} \quad \|\theta'\|_0 \leq k θ′minL(f(x;θ′))s.t.∥θ′∥0≤k
其中 ∥ ⋅ ∥ 0 \|\cdot\|_0 ∥⋅∥0 表示非零参数数量。该优化问题可分解为两个阶段:
- 重要性评估:建立参数重要性评分函数 S ( θ i ) S(\theta_i) S(θi)
- 阈值筛选:确定保留参数的比例 r = k / d r = k/d r=k/d
1.2 非结构化剪枝的数学形式化
1.2.1 局部剪枝(Layer-wise)
对第 l l l 层权重 W ( l ) ∈ R m × n W^{(l)} \in \mathbb{R}^{m \times n} W(l)∈Rm×n,定义剪枝掩码 M ( l ) ∈ { 0 , 1 } m × n M^{(l)} \in \{0,1\}^{m \times n} M(l)∈{ 0,1}m×n,剪枝后权重:
W pruned ( l ) = W ( l ) ⊙ M ( l ) W_{\text{pruned}}^{(l)} = W^{(l)} \odot M^{(l)} Wpruned(l)=W(l)⊙M(l)
其中掩码生成策略:
M i j ( l ) = { 1 if ∣ W i j ( l ) ∣ ≥ τ ( l ) 0 otherwise M_{ij}^{(l)} = \begin{cases} 1 & \text{if } |W_{ij}^{(l)}| \geq \tau^{(l)} \\ 0 & \text{otherwise} \end{cases} Mij(l)={ 10if ∣Wij(l)∣≥τ(l)otherwise
阈值