开源推荐
morning
GitHub 热门项目:fsdp_qlora
摘要
GitHub项目:fsdp_qlora 仓库地址:https://github。
https
qlora
the
fsdp
and
2026-05-25
1 阅读
约7分钟阅读
GitHub Trending
GitHub 项目:fsdp_qlora
仓库地址:https://github.com/AnswerDotAI/fsdp_qlora
星级:1545 | 作者:AnswerDotAI
项目描述:使用 QLoRA + FSDP 培训法学硕士
===================================================
自述文件内容:
#fsdp_qlora
使用量化 LoRA + FSDP 培训法学硕士。
请阅读我们的[公告博客文章](https://www.answer.ai/posts/2024-03-06-fsdp-qlora.html)。
您应该将此脚本视为 alpha/预览版本。如果您对测试和调试模型不满意,我们建议您推迟几个月,等待社区更全面地测试该方法。
## 集成
FSDP+QLoRA 已集成到:
- [Axolotl](https://github.com/OpenAccess-AI-Collective/axolotl/pull/1378):实验支持
## 安装
以下步骤应该有效(在 Cuda 11.7、11.8 和 12.1 上测试):
- 克隆 https://github.com/AnswerDotAI/fsdp_qlora
- `pip install llama-recipes fastcore "transformers!=4.38.*,!=4.39.*" --extra-index-url https://download.pytorch.org/whl/test/cu118` 作为获取大多数依赖项的简单方法(将 118 替换为您想要的 Cuda 版本)
- 安装bitsandbytes `pip install bitsandbytes>=0.43.0`
- 运行“huggingface-cli login”(访问 Llama 2)
- 可选库:
- HQQ量化:按照HQQ安装[说明](https://github.com/mobiusml/hqq?tab=readme-ov-file#installation)。我们的训练脚本使用“HQQBackend.ATEN_BACKPROP”,因此还要确保构建自定义内核“cd hqq/kernels && python setup_cuda.py install”。
- 权重和偏差记录:`pip install wandb`
- [Pytorch >= 2.2](https://pytorch.org/blog/pytorch2-2/) 建议使用原生 flash-attention 2 内核。
## 在双 24GB GPU 上微调 Llama-2 70B
安装后,运行 cd fsdp_qlora ,然后运行以下命令开始在 [Alpaca](https://huggingface.co/datasets/yahma/alpaca-cleaned) 上微调 Llama-2 70B,最大序列长度为 512 个令牌。
````bash
蟒蛇火车.py \
--model_name meta-llama/Llama-2-70b-hf \
--batch_size 2 \
--context_length 512 \
--精度bf16 \
--train_type qlora \
--use_gradient_checkpointing true \
--use_cpu_offload true \
--数据集羊驼 \
--reentrant_checkpointing true
````
此示例命令当前使用刚刚超过 128GB 的 CPU RAM。如果您只有 128GB 可用空间,我们建议您创建一个 10-20GB 交换文件来适应最初的使用高峰。
## 培训选项
对于量化,我们支持 HQQ 和 bitsandbytes。我们目前正在进行基准测试,以帮助您决定使用哪个。如果您确实使用bitsandbytes,请务必传递“--reentrant_checkpointing True”以避免触发bitsandbytes中的错误,从而导致内存使用率过高(修复正在进行中)。
### `--train_type full`
完整的参数微调。
````bash
export CUDA_VISIBLE_DEVICES=4,5 # 可选设置设备
蟒蛇火车.py \
--world_size 2 \ # 可选,在单机上会自动设置
--master_port 12356 \ # 可选,默认为12355
--model_name meta-llama/Llama-2-7b-hf \
--gradient_accumulation_steps 4 \
--batch_size 8 \
--context_length 512 \
--精度bf16 \
--train_type 完整\
--use_gradient_checkpointing true \
--use_cpu_offload false \
--use_activation_cpu_offload false \
--log_to 瓦
相关推荐
GitHub热门项目: RedInk
GitHub项目:RedInk 仓库地址:https://github.com/HisMax/RedInk Stars:5393 | 作者:HisMax 项目描
07-06
👁 None
★ 100
GitHub热门项目: one-small-step
GitHub项目:one-small-step 仓库地址:https://github.com/karminski/one-small-step Stars:6
07-06
👁 None
★ 100
GitHub热门项目: pgai
GitHub项目:pgai 仓库地址:https://github.com/timescale/pgai Stars:5797 | 作者:timescale 项
07-06
👁 None
★ 100
GitHub 热门项目:gemma-2B-10M
GitHub项目:gemma-2B-10M 仓库地址:https://github。com/mustafaaljadery/gemma-2B-10M Stars
06-29
👁 None
★ 95
GitHub 热门项目:efflux-backend
GitHub项目:efflux-backend 仓库地址:https://github。
06-28
👁 None
★ 95