PEFT documentation
VeLoRA
快速入门
指南
方法
API 参考
You are viewing main version, which requires installation from source. If you'd like
regular pip install, checkout the latest stable version (v0.21.0).
VeLoRA
这是 LoRA 的一种变体,因此,除非本页另有说明,LoRA 支持的所有功能在此方法中均适用。
VeLoRA 是 LoRA 的一种变体,它通过压缩前向传播中为 LoRA 保存的激活值,并在反向传播中重建这些激活值以实现更新规则,从而降低训练内存占用。在 PEFT 中,VeLoRA 通过 LoraConfig 上的 velora_config 参数配置为 LoRA 变体。
from peft import LoraConfig, VeloraConfig
config = LoraConfig(
target_modules=["q_proj", "v_proj"],
velora_config=VeloraConfig(
num_groups=64,
scale=0.2,
init_type="batch_average",
),
)VeLoRA 会应用于由 target_modules 选定的每个 LoRA 层。num_groups 控制压缩前如何划分输入激活的深度。如果激活深度不能被 num_groups 整除,VeLoRA 会在内部对分组表示进行填充,并在重建后移除填充。scale 在反向传播过程中对重建的激活进行重新缩放,而 init_type 则决定投影的初始化方式。
使用 batch_average_once 从第一个训练批次初始化投影,使用 batch_average 从每次训练前向传播中更新它,或使用 random 立即从一个随机归一化向量进行初始化。
以下是使用 MetaMathQA 基准 获得的一些结果。
| 变体 | 训练损失 | 最大内存 (GiB) | 每秒令牌数 |
|---|---|---|---|
| LoRA | 0.5427 | 27.69 | 2366.2 |
| LoRA + GC | 0.5426 | 13.17 | 1671.8 |
| LoRA+VeLoRA | 0.5427 | 19.94 | 2057.6 |
注意事项
- VeLoRA 目前仅支持标准的 LoRA 线性层。