transformers支持GaLora,24G家用显卡全参微调7B大模型时代到来
作者: NLP前沿 来源: NLP前沿
GaLore的具体原理,可以参照上周的推文,今天的推文汇总一些网友的测试结果
https://mp.weixin.qq.com/s?__biz=MzkyOTU5NzY1Mw==&mid=2247485777&idx=2&sn=b49f0ecde5573059546dd2cbc417f826&chksm=c20658ebf571d1fd13e3a9f4b2ac0f418c9117c8256406c296224ef0391af0bbebf51d92b605#rd
https://github.com/huggingface/transformers/pull/29588
https://github.com/jiaweizzhao/GaLore/issues/6
https://github.com/hiyouga/LLaMA-Factory/tree/main
- LLaMA-Factory repo已经支持galora
-
可以通过添加–use_galore 来使用
-
已经支持了之前提到的LORA+的trick,通过参数loraplus_lr_ratio=16.0来控制
- 16bit 全参微调llama2-7B,不同超参数下的显存占用
RankRetain gradMemoryToken/s
8-bit AdamW
Yes 40GB 1434
8-bit GaLore 16 Yes 28GB 1532
8-bit GaLore 128 Yes 29GB 1532
16-bit GaLore 128 Yes 30GB 1615
16-bit GaLore 128 No 18GB 1587
8-bit GaLore 1024 Yes 36GB 1238
- GaLore微调损失曲线非常漂亮
-
hf的使用方式
import torch
import datasets
from transformers import TrainingArguments, AutoConfig, AutoTokenizer, AutoModelForCausalLM
import trltrain_dataset = datasets.load_dataset(‘imdb’, split=‘train’)
args = TrainingArguments(
output_dir="./test-galore",
max_steps=100,
per_device_train_batch_size=2,
optim=“galore_adamw”,
optim_target_modules=[“attn”, “mlp”]
)model_id = “mistralai/Mistral-7B-v0.1”
config = AutoConfig.from_pretrained(model_id)
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_config(config).to(0)trainer = trl.SFTTrainer(
model=model,
args=args,
train_dataset=train_dataset,
dataset_text_field=‘text’,
max_seq_length=512,
)trainer.train()
更多AI工具,参考Github-AiBard123,国内AiBard123