ムハンマド・ファウィ
コードdoi:
Preprint doiを研究する:
このレポは、低ランク適応(LORA)のコンテキストでカーマトリックス分解を活用する大規模な言語モデル(LLM)を微調整するための新しいアプローチであるCurlora Research Paperのコードが含まれています。私たちの方法では、LLM微調整における2つの重要な課題に対処します。継続的な学習中の壊滅的な忘却の緩和と、訓練可能なパラメーターの数を減らすことです。既存の知識を損なうことなく、より効率的で安定した方法を新しいタスクに適応させるために、より効率的で安定した方法を可能にするために、CUR分解プロセスの独自の変更を提案します。複数のデータセットでの実験を通じて、壊滅的な忘却を緩和する際に、Curloraが標準のLORAを上回ることを実証します。タスク全体のモデルの安定性とパフォーマンスを維持しながら、トレーニング可能なパラメーターの数を大幅に削減します。私たちの結果は、特にデータが限られているシナリオでは、CurloraがLoraと比較して優れた精度と困惑のスコアを達成することを示しています。
CURLoRA.pdf :Curloraアプローチを詳述する研究論文。code/ :Curloraの実装と実験を含むディレクトリ。code/curlora.py :curloraクラスを含む。code/utils.py :ヘルパー機能。code/lora.py :loraクラス。code/curlora_experiment.ipynb :curlora Mistral 7b(MRPC、SST-2、およびSentiment140で微調整)を実験します。code/curlora_experiment-gpt.ipynb :curlora gpt2-large(MRPC、SST-2、およびsentiment140の微調整)を使用して実験します。code/squad_gpt-curlora.ipynb :Q&A用の微調整gpt2-large with curlora and sfttrainer on squad Dataset。 最初に要件をインストールします
pip3 install -r code/requirements.txtすべてのCurloraヘルパー機能とクラスは、code/curlora.pyおよびcode/utils.pyで定義されています。
モデルをロードして、Curloraを適用します
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" )これで、通常の微調整または推論に使用できる注意層(キー、値、クエリ)にカルロラ層が適用されたモデルがあります。
レイヤーがどのように呼び出されているかを知る必要がある場合があります。そうすれば、正しく交換できるようにする必要があります。たとえば、ミストラルの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ライセンスに基づいてライセンスされています。詳細については、ライセンスファイルを参照してください。
Curloraの研究やコードが役立つと思われる場合は、それらを引用することを検討してください。
@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
貢献とアイデアは大歓迎です