【文献阅读】LORA: LOW-RANK ADAPTATION OF LARGE LANGUAGE MODELS

目录

  • [1. motivation](#1. motivation)
  • [2. overall](#2. overall)
  • [3. model](#3. model)
    • [3.1 low rank parametrized update matrices](#3.1 low rank parametrized update matrices)
    • [3.2 applying lora to transformer](#3.2 applying lora to transformer)
  • [4. limitation](#4. limitation)
  • [5. experiment](#5. experiment)
  • [6. 代码](#6. 代码)
  • [7. 补充](#7. 补充)
  • 参考文献

1. motivation

  • 常规的adaptation需要的微调成本过大
  • 现有方法的不足:
    • Adapter Layers Introduce Inference Latency
    • Directly Optimizing the Prompt is Hard

2. overall

  • inspiration
    Aghajanyan[1] 证明了预训练语言模型有一个低的"intrinsic rank",并且将其映射到一个子空间后仍然可以有效率的学习
  • hypothesis
    假设模型自适应过程中,权重的改变也具有一个低的"intrinsic rank"
  • core idea
    通过优化全连接层改变量的秩分解矩阵去微调全连接层

3. model

3.1 low rank parametrized update matrices

采用秩分解矩阵代表权重的改变量:

则对于任意的输出:

A ∈ R d × r , B ∈ R r × d , r < < d {A\in R^{d \times r}}, {B \in R^{r \times d}}, r<<d A∈Rd×r,B∈Rr×d,r<<d

对于A采用一个随机的高斯初始化,对于B采用0初始化。

采用 α / r {\alpha/r} α/r缩放 δ W x {\delta Wx} δWx,r是矩阵的秩, α {\alpha} α是一个常数。这个缩放可以减小当r改变时,我们重新微调参数的需要
A generalization of full fine-tune

adapter-based的方法通常是利用一个MLP或者一个prefix-based方法,导致模型不允许长序列的输入。不同于adapter-based的方法,LORA是针对原始模型训练的。LORA微调时,我们可以通过设置r来达到恢复全量微调的效果。因为LORA在适应过程中不要求对权重矩阵的累积梯度更新具有完整的秩。

no additional inference latency

部署到实际生产时,可以先计算存储 W = W 0 + B A {W = W_0 + BA} W=W0+BA。对于不同的下游任务,只用计算BA和其变化量的差值就可以了。

3.2 applying lora to transformer

  • transformer的框架中,有四个权重矩阵在自注意力层( W q , W k , W v , W o {W_q,W_k, W_v, W_o} Wq,Wk,Wv,Wo),两个在MLP。
  • lora微调时只针对四个自注意力层的矩阵,冻结MLP的两个矩阵(即下游任务不训练)。

4. limitation

For example, it is not straightforward to batch inputs to different tasks with different A and B in a single forward pass, if one chooses to absorb A and B into W to eliminate additional inference latency. Though it is possible to not merge the weights and dynamically choose the LoRA modules to use for samples in a batch for scenarios where latency is not critical.

5. experiment



6. 代码

  • lora层
  • 普通的前馈网络
  • 加入lora后

7. 补充

OLoRA是lora的一个变种,是在lora的基础上引入了量化,减小了对资源量的需求。
创新点:4 位量化、4 位 NormalFloat 数据类型、双量化和分页优化器

参考文献

1\] Armen Aghajanyan, Luke Zettlemoyer, and Sonal Gupta. Intrinsic Dimensionality Explains the Effectiveness of Language Model Fine-Tuning. arXiv:2012.13255 \[cs\], December 2020. URL http://arxiv.org/abs/2012.13255. \[2\][大模型微调原理与代码实战案例(四):LoRA](https://blog.csdn.net/2301_78285120/article/details/132701965)

相关推荐
桃子叔叔6 小时前
Prompt Engineering 完全指南:从基础到高阶技术深度解析
大数据·人工智能·prompt
腾飞开源6 小时前
14_Spring AI 干货笔记之 Azure OpenAI 对话模型
人工智能·向量存储·对话模型·工具调用·spring ai·azure openai·ai模型集成
晨同学03276 小时前
【中文】CLIP4Clip: An Empirical Study of CLIP for End to End Video Clip Retrieval
人工智能·多模态
后端小肥肠6 小时前
Coze+ComfyUI 实战:一键生成爆款梦核物语视频,直通剪映草稿
人工智能·aigc·coze
老蒋新思维6 小时前
创客匠人洞察:创始人 IP 变现的长期主义,文化根基与 AI 杠杆的双重赋能
大数据·网络·人工智能·tcp/ip·重构·创始人ip·创客匠人
冷雨夜中漫步6 小时前
AI入坑之路——(1)搭建本地的Python与Jupyter开发环境
人工智能·python·jupyter
Coding茶水间6 小时前
基于深度学习的水稻虫害检测系统演示与介绍(YOLOv12/v11/v8/v5模型+Pyqt5界面+训练代码+数据集)
图像处理·人工智能·深度学习·yolo·目标检测·计算机视觉
试着6 小时前
【投资学习】腾讯控股(0700.HK)
大数据·人工智能·业界资讯·腾讯
百泰派克生物科技6 小时前
液相色谱-质谱(LC-MS)肽段分析
人工智能·生物学·质谱·实验外包
qq_411262426 小时前
四博智联的`AI-01开发板`,基于乐鑫ESP32-C2 + 专属定制的离线语音模组
人工智能·物联网·四博智联