fine-tuning은 all the parameters of the pre-trained model을 update한다.
large model을 pre-train하기에, 모든 model parameter들을 retraining하는 full fine-tuning은 less feasible해지고 있다.
GPT-3 175B를 예로 들면, 각 175B parameter의 independent한 fine-tunde model의 instance를 deploy하는 것은 매우매우매우 비싸다.
많은 이전의 연구들은, new task를위해,
약간의 parameter를 adapting하거나,
external modules를 learning하는 방법을 사용했다.
inspiration
학습된 over-parametrized 모델들이 실제로 낮은 intrinsic dimension에 위치한다는 것을 보인 연구를 토대로,
model adaptation 과정에서 발생하는 weight 변화 또한 낮은 "intrinsic rank"를 가질 것이라고 가설을 세움.
LoRA를 사용하면 neural network의 일부 dense layer들을 indirect하게 학습 가능.
pre-trained weight들을 frozen 상태로 유지하면서,
adaptation 과정에서 dense layer의 변화를 rank decomposition matrix(low-rank matrix)들을 optimize하는 방식
LoRA는 pretrained model weight를 freeze하고,
trainalbe rank decomposition matrices를 각 Transformer의 layer에 inject한다.
➡️ downstream task를 위한 trainable parameter 개수를 크게 줄임.
Adam으로 fine-tuned된 GPT-3 175B와 비교해서,
trainable paramter를 10,000배 줄이고
GPU memory requirment를 3배 줄임.
no additional inference latency
full-fine tuning 과정에 대해 살펴 보면,
pre-trained (auto-regresive) language model 는 parametrized by
Each downstream task는
training dataset of context-target pairs: 으로 표현됨.
: sequence of tokens,
: sequence of tokens
ex) in NL2SQL,
: natural language query
: corresponding SQL commdands
ex) for summarization,
: content of article
: its summary
full-finetuning 동안,
model은 pre-trained weight 로 intialized.
그리고 로 updated됨.

full-finetuing의 main drawback
각 downstream task에 대해, 각기 다른 parameter set 을 학습해야 한다는 점.
따라서, pre-trained model이 크다면, 각 independent한 fined-tuned model들의 instance를 stroing하고 deploy하는 것은 challenging 함.
LoRA
parameter-efficient approach
task-specific parameter incerement 는 low-rank representation을 사용해서,
훨씬 작은 parameters set 로 encode한다.
를 찾는 task에서,
를 optimize하는 task로 바뀜.

efficient adaptation의 두 가지 주요 전략
1.Adapter Layers
각 Transformer block마다 두 개의 adapter layer를 추가하거나,
adapter layer와 추가적인 LayerNorm 사용하는 연구 등.
단점: 매우 작은 bottleneck dimension을 사용하더라도 adapter를 사용할 때 latency가 눈에 띄게 증가
2.Optimizing the Prompt
대표적인 예인 Prefix tuning은 optimize하기 어려움.
trainable parameter 수에 따른 성능 변화가 예측 불가능함.
adaptation을 위해 sequence length의 일부를 사용함으로써 downstream task를 위한 유효 sequence length가 줄어드는 trade-off가 존재.
layer의 weight matrix들은 주로 full-rank를 갖는다.
Intrinsic Dimensionality Explains the Effectiveness of Language Model Fine-Tuning(Aghajanyan et al, 2020) 연구는
specific task에 adapting할 때, pre-trained language model들이 낮은 "intrinsic dimension"을 가지고 있으며,
smaller subspace로의 random projection에도 불구하고 여전히 efficient하게 learning 할 수 있다는 것을 보임.
위 연구에 inspired 받아,
저자는 adaptation 동안 weight에 대한 update도 낮은 "intrinsic rank"를 가질 것이라고 hypothesize함.
pre-trained weight matrix 에 대해,
의 update 를 low-rank decomposition로 제한한다(constrain)
where , ,
rank
training 동안,

를 로 scaling

No Additional Inference Latency
LoRA는 어떤 weight matrix들의 subset에도 적용해서, trainable parameter를 줄일 수 있음.
Tranformer 구조에선, self-attention module에 4개의 weight matrix들 ()과 MLP module에 2개의 matrix가 존재.
LoRA는 (또는 )를 dimension의 single matrix로 취급함.
이는 output dimension이 일반적으로 attention head들로 나눠지더라도 마찬가지.
simplicity와 parameter-efficiency를 위해 downstream task에서
attention weight 🔥만을 adapt하고 MLP module은 freeze ❄️
(즉, MLP module은 training되지 않음)
MLP layers, LayerNorm layers, 나머지 parameter들의 adapting에 관한 empirical investigation은 future work로 남김.
Praticial Benefit & Limitation
Benefit
memory와 storage usage의 reduction
Adam으로 train된 large Transformer의 경우, 이면 frozen parameter에 대한 optimizer state를 store할 필요가 없음
➡️ VRAM usage 까지 감소
r = 4이고 query와 value projection matrix만 adapt할 경우,
➡️ checkpoint size가 약 10,000배 감소(350GB에서 35MB로).
➡️ 훨씬 적은 수의 GPU로 train할 수 있고 I/O bottleneck을 피할 수 있음.
LoRA가 전체 model weight를 저장하지 않고, 작은 rank의 update만을 저장하기 때문에 가능
또한 모든 layer가 아닌 query와 value projection matrix만 adapt하는 것도 size 감소에 기여
deployed 상태에서 모든 parameter가 아닌 LoRA weight만 swap함으로써 훨씬 낮은 cost로 task를 switch 가능.
limitation
각 input마다 다른 weight: 를 사용해야 하므로,
기존의 batch matrix multiplication을 직접 적용할 수 없음.
이로 인해, 단일 task에 대한 inference는 빨라지지만,
여러 task의 input을 동시에 효율적으로 처리하는 것은 복잡해짐.
empirical studies to answer the follwing questions
1) Given a parameter budget constraint, which subset of weight matrices in a pre-trained Transformer should we adapt to maximize downstream performance?
Limited parameter budget (18M, 약 35MB)에서 어떤 weight를 adapt해야 downstream task에서 최고의 성능을 얻을 수 있는지 조사.
Self-attention module의 weight matrix만 고려.

주요 발견
rank가 4로 낮아도 의 충분한 information을 capture 가능.
단일 type의 weight를 높은 rank로 adapt하는 것보다 여러 weight matrix를 낮은 rank로 adapt하는 것이 더 효과적.
2) Is the "optimal" adaptation matrix really rank-deficient?
If so, what is a good rank to use in practice?

Table 6은 놀랍게도 LoRA가 매우 작은 로도 이미 competitive한 performance를 보인다는 것을 보여줌
(Wq만 adapt하는 것보다 {Wq,Wv}에서 더 좋음).
이는 update matrix 가 매우 작은 "intrinsic rank"를 가질 수 있음을 suggest함.
이 finding을 further support하기 위해, 서로 다른 값과 다른 random seed에 의해 학습된 subspace들의 overlap을 check.
r을 증가시키는 것이 더 meaningful한 subspace를 cover하지 않는다고 주장,
이는 low-rank adaptation matrix가 sufficient하다는 것을 suggest.
subspace similarity between different
rank 이 다른 두 adaptation matrix 간의 subspace similarity를 분석.
구체적으로는, 과 의 adaptation matrix 사이에 어떤 singular vector가 얼마나 겹치는지를 조사
이를 위해 두 rank에 대한 singular value decomposition을 수행하고, right-singular unitary matrices 와 의 similarity를 비교함.
이 유사성을 측정하기 위해, Grassmann distance 기반의 정규화된 subspace similarity를 사용.
에서 상위 개의 singular vectors가 에서 상위 개의 singular vectors와 얼마나 겹치는지를 평가
⭐ 실험 결과
과 에서 상위 singular vector directions는 상당히 겹치지만, 나머지 방향들은 그렇지 않다는 점을 발견
즉, r이 작은 경우에도 상위 singular vectors는 중요한 정보를 담고 있으며,
조차도 다운스트림 작업에서 효과적인 이유를 설명 가능.
이 커질수록 유용한 정보는 증가하지만,
많은 singular directions는 noise에 가깝다는 결론에 도달
이 분석은 LoRA의 adaptation matrix가 매우 낮은 rank에서도 유용한 정보를 충분히 캡처할 수 있다는 것을 강조.
Subspace similarity between different random seeds
random seeds를 다르게 설정한 두 번의 rank r = 64로 학습한 결과들 간의 subspace similarity를 분석.
이를 통해, 동일한 rank r = 64로 학습했을 때, ∆Wq와 ∆Wv의 차이점을 관찰 가능.
실험 결과
∆Wq는 ∆Wv보다 더 높은 "intrinsic rank"를 가지고 있는 것으로 나타남.
또한, 두 개의 random Gaussian matrices를 비교했을 때,
이들 사이에는 공통된 singular value directions가 거의 없다는 사실이 도출됨.
이 실험을 통해, ∆Wq가 ∆Wv보다 더 중요한 singular directions를 학습하며,
rank가 높을수록 유의미한 sub-space가 더 잘 포착된다는 것을 확인.
3) What is the connection between and ?
Does highly correlate with ?
How large is comparing to ?

LoRA는 다른 효율적인 적응 방법과 결합될 수 있으며, 이로 인해 orthogonal improvement(서로 독립적인 성능 향상)을 이끌어낼 가능성.
LoRA 또는 fine-tuning의 메커니즘은 아직 명확하지 않음.
pre-trianing 중에 학습된 특성들이 어떻게 downstream task에 잘 적용되는지에 대한 이해가 부족.
LoRA는 full fine-tuning보다 이러한 질문에 답을 제시하는 데 더 효과적일 것으로 보임.
현재는 LoRA를 적용할 weight matrices를 선택하는 데 있어 주로 경험적인 방법(heuristics)에 의존.
이를 더 원칙적인 방법으로 개선할 수 있는지에 대한 연구 필요.
∆W의 rank-deficiency는 W 또한 rank-deficient 할 수 있다는 점을 시사.