무함마드 파위
코드 doi :
연구 사전 인쇄 doi :
이 repo에는 LORA (Low Rank Adaptation)의 맥락에서 CUR Matrix Decomposition을 활용하는 LLM (Lange Language Models)을 미세 조정하는 새로운 접근 방식 인 Carlora Research Paper의 코드가 포함되어 있습니다. 우리의 방법은 LLM 미세 조정에서 두 가지 중요한 과제를 다룹니다. 지속적인 학습 중에 치명적인 잊어 버리고 훈련 가능한 매개 변수의 수를 줄입니다. 우리는 기존 지식을 손상시키지 않으면 서 LLM을 새로운 작업에 적응시키는보다 효율적이고 안정적인 방법을 가능하게하기 위해 CUR 분해 프로세스에 대한 고유 한 수정을 제안합니다. 우리는 Carlora가 치명적인 잊어 버리는 것을 완화하는 데 표준 LORA를 능가하는 여러 데이터 세트에 대한 실험을 통해 보여줍니다. 작업 전반에 걸쳐 모델 안정성과 성능을 유지하면서 훈련 가능한 매개 변수의 수를 크게 줄입니다. 우리의 결과는 Carlora가 LORA에 비해 우수한 정확도와 당황 스코어를 달성한다는 것을 보여줍니다. 특히 데이터가 제한된 시나리오에서.
CURLoRA.pdf : Carlora 접근법을 자세히 설명하는 연구 논문.code/ : Carlora 구현 및 실험을 포함하는 디렉토리.code/curlora.py : Carlora 클래스 포함.code/utils.py : 헬퍼 기능.code/lora.py : lora 클래스.code/curlora_experiment.ipynb : Mistral 7B를 사용한 Carlora 실험 (MRPC, SST-2 및 Sentiment140의 미세 조정).code/curlora_experiment-gpt.ipynb : GPT2-LARGE를 사용한 Carlora 실험 (MRPC, SST-2 및 Sentiment140의 미세 조정).code/squad_gpt-curlora.ipynb : Squad Dataset의 Carrora 및 Sfttrainer가있는 Q & A의 미세 조정 GPT2-LARGE. 먼저 요구 사항을 설치합니다
pip3 install -r code/requirements.txt모든 Carlora 도우미 기능 및 클래스는 Code/Currora.py 및 Code/Utils.py 에 정의됩니다.
모델을로드하고 Carlora를 적용하십시오
from transformers import AutoTokenizer , AutoModelForCausalLM
from utils import *
model_name = "gpt2-large"
model = AutoModelForCausalLM . from_pretrained ( model_name )
model . to ( "cuda" ) # this will make all existing layers in CUDA
# turning off grad for all layers
for param in model . parameters ():
param . requires_grad = False
# replace original Q,K,V layers with CURLoRA (GPT2-Large specific)
# refer to utils.py for a more general way
for name , module in model . named_modules ():
if isinstance ( module , type ( model . transformer . h [ 0 ]. attn )):
# rank = 24, alpha = 1
module . c_attn = LinearWithCURLoRA ( module . c_attn , 24 , 1 )
# now look at how many CURLoRA parameters to be trained
total_params = sum ( p . numel () for p in model . parameters () if p . requires_grad )
print ( f"Total trainable parameters after: { total_params :, } " )
# making sure CURLoRA layers are on CUDA as well
model . to ( "cuda" )이제 정상적으로 미세 조정 또는 추론에 사용할 수있는주의 레이어 (키, 값 및 쿼리)에 적용되는 Carlora 레이어가있는 모델이 있습니다.
레이어를 올바르게 교체 할 수 있도록 레이어가 어떻게 호출되는지 알아야 할 수도 있습니다. 예를 들어, 미스트랄의 Q, K, V를 통해 찾을 수 있습니다.
for name , module in model . named_children ():
if any ( l in name for l in [ "q_proj" , "v_proj" , "k_proj" ]):
setattr ( model , name , LinearWithCURLoRA ( module , rank , alpha ))참고 :
이 프로젝트는 MIT 라이센스에 따라 라이센스가 부여됩니다. 자세한 내용은 라이센스 파일을 참조하십시오.
Carlora Research 또는 코드가 도움이되면 인용하는 것을 고려하십시오.
@software { Fawi_CURLoRA_Leveraging_CUR_2024 ,
author = { Fawi, Muhammad } ,
title = { {CURLoRA: Leveraging CUR Matrix Decomposition for
Stable LLM Continual Fine-Tuning and Catastrophic
Forgetting Mitigation} } ,
month = jul,
year = 2024 ,
publisher = { Zenodo } ,
version = { v4.0.0 } ,
doi = { 10.5281/zenodo.12729738 } ,
url = { https://zenodo.org/doi/10.5281/zenodo.12729738 }
} Fawi, M. (2024). CURLoRA: Leveraging CUR Matrix Decomposition for Stable LLM Continual Fine-Tuning and Catastrophic Forgetting Mitigation (v4.0.0) [Computer software]. Zenodo. https://doi.org/10.5281/zenodo.12729738
@misc { fawi_2024_12730055 ,
author = { Fawi, Muhammad } ,
title = { {CURLoRA: Leveraging CUR Matrix Decomposition for
Stable LLM Continual Fine-Tuning and Catastrophic
Forgetting Mitigation} } ,
month = jul,
year = 2024 ,
publisher = { Zenodo } ,
doi = { 10.5281/zenodo.12730055 } ,
url = { https://doi.org/10.5281/zenodo.12730055 }
} Fawi, M. (2024). CURLoRA: Leveraging CUR Matrix Decomposition for Stable LLM Continual Fine-Tuning and Catastrophic Forgetting Mitigation. Zenodo. https://doi.org/10.5281/zenodo.12730055
기여와 아이디어는 대단히 감사 할 것입니다