Fully Connected Layers: Two Layers via Singular Value Decomposition
The weights of a fully connected layer y=Wx (WโRmรn) are decomposed with singular value decomposition (SVD).
W=USVโค
The diagonal of S holds the singular values in descending order. If the singular values decay quickly, an approximation that keeps only the top t of them is sufficient (Section 3.2.1 of Denton et al.).
W~=UtโStโVtโคโ,UtโโRmรt,ย StโโRtรt,ย VtโโRnรt
The procedure is as follows (left side of the figure at the top).
- Compute the singular value decomposition of the trained layer's weight W.
- Choose the rank t to keep, and extract only the top t singular values and singular vectors.
- Replace the original layer with two layers: an nโt linear layer (weights StโVtโคโ) and a tโm linear layer (weights Utโ). No activation function is inserted between them.
- Repeat the same for the other layers.
- Recover the lost accuracy with fine-tuning.
The number of parameters drops from mn to t(m+n), and the number of multiplications per input drops by the same ratio. A reduction is only achieved when t<m+nmnโ, so t must be sufficiently small.
The approximation error is determined by the magnitude of the discarded singular values. The maximum error is bounded by the largest discarded singular value st+1โ.
โฅW~xโWxโฅโคst+1โโฅxโฅ
Singular value decomposition rearranges a matrix in order of its "most influential directions." Keeping only the top t corresponds to keeping only the main directions and discarding fine components, similar to keeping only the main components in image compression.
Convolutional Layers: Splitting Along Spatial and Channel Directions
The weights of a convolutional layer form a 4D tensor with C input channels, N output channels, height d, and width d. Scheme 2 of Jaderberg et al. replaces a dรd convolution with two stages: a vertical dร1 convolution (CโK channels) and a horizontal 1รd convolution (KโN channels) (Eq. (1) in the paper).
Wnโโzโk=1โKโhnkโโ(vkโโz)
vkโ are the vertical filters and hnkโ are the horizontal filters. The computation per output pixel drops from NCd2 to K(N+C)d. If K, N, and C are of similar size, this amounts to a speedup of about d times (right side of the figure at the top).
Lebedev et al. (2015) used CP decomposition, which approximates a 4D tensor with a sum of R rank-1 tensors.
K(i,j,s,t)โr=1โRโKx(i,r)Ky(j,r)Ks(s,r)Kt(t,r)
i,j are the vertical and horizontal positions, s is the input channel, and t is the output channel; Kx,Ky,Ks,Kt are matrices of size dรR, dรR, SรR, and TรR, respectively (Eq. (4) in the paper). This turns one convolutional layer into a stack of four small convolutions: a 1ร1 that mixes input channels, a vertical one, a horizontal one, and a 1ร1 that produces the output channels. The number of stored values is not the total number of tensor elements but R times the sum of the lengths along each direction.