← 全部文章← All posts

Low-Rank Clone:从 FFN 记忆到高效蒸馏

文章目录
  1. 一、一些insights:既然FFN是key-value memory,能否进行压缩?
  2. 二、LRC 方法
  3. 三、实验
  4. 学生模型成功继承了教师的知识分布

最近我们高效蒸馏的工作 “Low-Rank Clone (LRC)” 非常幸运被 NeurIPS 2025 接收为 Spotlight。

TL;DR: 我们通过训练一组 Low-Rank Projection (低秩投影) 矩阵,将一个强大的教师大模型(Teacher LLM)直接“投影”成一个更小的学生模型(Student SLM)。我们不需要从头创建或训练学生模型的庞大权重,只需训练这些投影矩阵。最终,仅用 20B 训练数据,我们得到的 LRC-1.7B 模型就能超越使用 36T 数据训练的 SOTA 模型 Qwen3-1.7B ,实现了超过1000倍的训练效率提升 。

Low-Rank Clone 原文配图 1

论文链接: arxiv.org/abs/2505.12781

代码和权重链接:https://github.com/CURRENTF/LowRankClone https://huggingface.co/JitaiHao/LRC-4B-SFT


一、一些insights:既然FFN是key-value memory,能否进行压缩?

在介绍我们的方法前,我想先分享一下最初的思考,希望能给大家一些启发。

LRC 的核心灵感直接来源于一篇经典工作 “Transformer Feed-Forward Layers Are Key-Value Memories” (Geva et al., 2021) 。这篇文章了认为FFN 模块可以理解为:它其实扮演了一个键值记忆库(Key-Value Memory)的角色 。

我们来回顾一下 FFN 的计算过程,以 SwiGLU 激活函数为例 :

offn=SwiGLU(xWup⊤,xWgate⊤)Wdowno_{ffn} = \text{SwiGLU}(xW_{up}^{\top}, xW_{gate}^{\top})W_{down}

这个过程可以直观地理解为:

  1. 查询与匹配:输入向量 x 分别与 W_up 和 W_gate (可以理解为 Key 矩阵) 进行矩阵乘法,计算相似度并生成一个激活值分布 。
  2. 内容提取:用上一步得到的激活值,对 W_down (可以理解为 Value 矩阵) 进行加权求和,从而提取出存储的知识 。

既然 FFN 是一个 Key-Value Memory,那么一个自然而然的问题就来了:我们能否在不显著损害其存储知识的前提下,对 Key 和 Value 矩阵进行压缩?

这便是 LRC 方法的起点。

二、LRC 方法

为了实现对 FFN 记忆的压缩,我们设计了一个统一的框架,包含两个核心步骤:低秩投影 (Low-Rank Projection) 和 激活克隆 (Activation Clone) 。

1. Low-Rank Projection:用投影生成学生权重

传统方法要么从头训练学生模型 ,要么通过“硬剪枝”粗暴地丢掉教师模型的部分权重 ,这两种方式都会导致信息丢失或效率低下 。

LRC 另辟蹊径,我们不训练学生模型的权重,而是训练一组轻量级的 投影矩阵 WmPW_m^P 。学生模型的权重 WmSW_m^S 由教师模型的权重 WmTW_m^T 直接投影生成 。

对于 Transformer 的每一层 i 中的每一个权重矩阵 m (例如 q, k, v, o, up, gate, down),其生成公式如下 :

Wm,iS=Wm,iTWm,iPW_{m,i}^S = W_{m,i}^T W_{m,i}^P

这里,Wm,iT∈RdmT×dTW_{m,i}^T \in \mathbb{R}^{d_{m}^{T}\times d^{T}} 是教师模型的权重,Wm,iP∈RdT×dSW_{m,i}^P \in \mathbb{R}^{d^{T}\times d^{S}} 是我们唯一需要训练的低秩投影矩阵 。通过这种方式,我们将教师模型庞大的权重“软压缩”到了学生模型的维度空间,最大限度地保留了原始知识结构 。

Method
Method

2. Activation Clone:确保投影后产生一致的相似度

仅仅投影权重还不够,我们还需要确保压缩后的 Key-Value Memory 在面对相同的输入时,能产生和教师模型相似的“反应”。

因此,我们引入了 激活克隆 机制,通过均方误差(MSE)损失函数,强制学生模型在各个中间步骤的激活值与教师模型的激活值保持一致 。

我们的克隆损失函数 Lclone\mathcal{L}_{clone} 覆盖了注意力模块和 FFN 模块的多个中间输出 :

Lclone=∑il[E(oattn,iS,oattn,iTWo,iP)+E(offn,iS,offn,iTWdown,iP)+∑m∈{q,k,v,up,gate}E(hm,iS,hm,iT)]\mathcal{L}_{clone} = \sum_{i}^{l} \left[ \mathcal{E}(o_{attn,i}^S, o_{attn,i}^T W_{o,i}^P) + \mathcal{E}(o_{ffn,i}^S, o_{ffn,i}^T W_{down,i}^P) + \sum_{m \in \{q,k,v,up,gate\}} \mathcal{E}(h_{m,i}^S, h_{m,i}^T) \right]

其中,E\mathcal{E} 代表 MSE Loss 。这个公式确保了学生模型不仅在最终输出层,更在模型的“思考”过程的每一步,都尽可能地模仿教师模型的行为 。

最终,模型的总训练目标由三部分组成:传统的 KL散度损失 LKL\mathcal{L}_{KL}、语言模型损失 LLM\mathcal{L}_{LM},以及我们的 克隆损失 Lclone\mathcal{L}_{clone} 。

三、实验

LRC 的有效性在实验中得到了充分验证。我们用 Llama-3.2-3B、Qwen2.5-3B/7B 等开源模型作为教师,训练了一系列 LRC 学生模型 。

Low-Rank Clone 原文配图 3
Low-Rank Clone 原文配图 4

如上表所示,我们的 LRC-1.7B 模型仅用 20B tokens,平均分达到 64.98,超过了使用 36T tokens 训练的 Qwen3-1.7B (63.17) 。同时,LRC-4B 模型使用约 18B 训练 tokens,平均分达到 70.30,与使用 36T tokens 训练的 Qwen3-4B (70.29) 性能相当 。(均使用 lm-eval==0.4.8 进行测试,补充自 2025-11-30 小红书更新。)

学生模型成功继承了教师的知识分布

为了验证我们的核心假设,我们进行了一项神经元掩码实验 。我们发现,在教师模型中对事实性知识反应强烈的“重要神经元”,在学生模型的相同位置也扮演着同样的角色 。当我们掩盖这些神经元时,师生模型的性能都会同步大幅下降,这有力地证明了学生模型成功继承了教师的知识结构 。

Low-Rank Clone 原文配图 5

如果大家对我们的工作感兴趣,欢迎阅读论文,也给我们 GitHub 点点 Star,我们会继续优化代码让LRC更易用!

Low-Rank Clone: From FFN Memory to Efficient Distillation

Contents
  1. 1. The initial insight: if an FFN is a key-value memory, can we compress it?
  2. 2. The LRC method
  3. 3. Experiments
  4. The student inherits the teacher’s knowledge structure

Our work on efficient distillation, Low-Rank Clone (LRC), was selected as a Spotlight at NeurIPS 2025.

TL;DR: We train a set of low-rank projection matrices that directly project a strong teacher LLM into a smaller student language model. Instead of creating or training the student’s large weight matrices from scratch, we train only these projections. With just 20B training tokens, our LRC-1.7B outperforms Qwen3-1.7B, a state-of-the-art model trained on 36T tokens, yielding a more than 1,000-fold improvement in training-token efficiency.

Low-Rank Clone: original figure 1

Paper: arxiv.org/abs/2505.12781

Code and weights: https://github.com/CURRENTF/LowRankClone https://huggingface.co/JitaiHao/LRC-4B-SFT


1. The initial insight: if an FFN is a key-value memory, can we compress it?

Before introducing the method, I would like to share the thinking that led to it, in the hope that it offers a useful perspective.

LRC takes direct inspiration from the classic paper “Transformer Feed-Forward Layers Are Key-Value Memories” (Geva et al., 2021), which interprets the FFN module as a key-value memory.

Let us revisit the FFN computation, using SwiGLU as an example:

offn=SwiGLU(xWup⊤,xWgate⊤)Wdowno_{ffn} = \text{SwiGLU}(xW_{up}^{\top}, xW_{gate}^{\top})W_{down}

Intuitively, this computation has two stages:

  1. Querying and matching: the input vector x is multiplied by W_up and W_gate, which can be viewed as key matrices, to compute similarities and produce an activation distribution.
  2. Retrieving content: those activations weight the rows of W_down, which can be viewed as a value matrix, to retrieve the stored knowledge.

If an FFN is a key-value memory, a natural question follows: can we compress its key and value matrices without substantially damaging the knowledge they store?

That question is the starting point for LRC.

2. The LRC method

To compress FFN memory, we designed a unified framework with two core components: low-rank projection and activation clone.

1. Low-rank projection: generating student weights through projection

Conventional methods either train a student from scratch or discard parts of the teacher’s weights through hard pruning. These approaches can be inefficient or lose valuable information.

LRC takes a different approach. We train lightweight projection matrices WmPW_m^P, rather than the student’s weights. The student weights WmSW_m^S are generated directly by projecting the teacher weights WmTW_m^T.

For each weight matrix m, such as q, k, v, o, up, gate, down, in each Transformer layer i, the student weights are generated as follows:

Wm,iS=Wm,iTWm,iPW_{m,i}^S = W_{m,i}^T W_{m,i}^P

Here, Wm,iT∈RdmT×dTW_{m,i}^T \in \mathbb{R}^{d_{m}^{T}\times d^{T}} denotes the teacher weights, and Wm,iP∈RdT×dSW_{m,i}^P \in \mathbb{R}^{d^{T}\times d^{S}} is the low-rank projection matrix we train. This softly compresses the teacher’s large weight matrices into the student’s dimensional space while preserving as much of the original knowledge structure as possible.

Method overview.
Method overview.

2. Activation clone: preserving similarity after projection

Projecting the weights alone is not enough. We also need the compressed key-value memory to respond similarly to the teacher when given the same input.

We therefore introduce activation clone, using a mean squared error (MSE) loss to align the student’s intermediate activations with the teacher’s.

Our clone loss Lclone\mathcal{L}_{clone} covers multiple intermediate outputs in both the attention and FFN modules:

Lclone=∑il[E(oattn,iS,oattn,iTWo,iP)+E(offn,iS,offn,iTWdown,iP)+∑m∈{q,k,v,up,gate}E(hm,iS,hm,iT)]\mathcal{L}_{clone} = \sum_{i}^{l} \left[ \mathcal{E}(o_{attn,i}^S, o_{attn,i}^T W_{o,i}^P) + \mathcal{E}(o_{ffn,i}^S, o_{ffn,i}^T W_{down,i}^P) + \sum_{m \in \{q,k,v,up,gate\}} \mathcal{E}(h_{m,i}^S, h_{m,i}^T) \right]

Here, E\mathcal{E} denotes the MSE loss. This objective encourages the student to imitate the teacher not only at the final output layer, but also throughout its intermediate computation.

The complete training objective combines three terms: the conventional KL divergence loss LKL\mathcal{L}_{KL}, the language modeling loss LLM\mathcal{L}_{LM}, and our clone loss Lclone\mathcal{L}_{clone}.

3. Experiments

We evaluated LRC by training a series of student models using open-source teachers such as Llama-3.2-3B and Qwen2.5-3B/7B.

Low-Rank Clone: original figure 3
Low-Rank Clone: original figure 4

As shown in the table above, LRC-1.7B achieves an average score of 64.98 with only 20B training tokens, exceeding Qwen3-1.7B (63.17), which was trained on 36T tokens. Meanwhile, LRC-4B reaches 70.30 with approximately 18B training tokens, matching Qwen3-4B (70.29), also trained on 36T tokens. All models were evaluated with lm-eval==0.4.8, as clarified in the Xiaohongshu update of November 30, 2025.

The student inherits the teacher’s knowledge structure

To test our central hypothesis, we conducted a neuron-masking experiment. We found that neurons strongly associated with factual knowledge in the teacher play similar roles at the same positions in the student. Masking those neurons causes a substantial performance drop in both models, providing strong evidence that the student inherits the teacher’s knowledge structure.

Low-Rank Clone: original figure 5

If you are interested in the work, please read the paper and consider starring the GitHub repository. We will continue improving the code to make LRC easier to use!