Llamafactory分布式训练

内容 在L20* 8 服务器, Ubuntu 22.04 系统上 使用llamafactory框架 进行 sft 训练。分别使用单机多卡,和多机多卡模式。 环境配置 下载代码仓库,配置一个新的conda环境,并安装依赖 git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git cd LLaMA-Factory conda activate llamafactory_env pip install -e . pip install -r requirements/metrics.txt -i https://pypi.tuna.tsinghua.edu.cn/simple 准备sft数据,放在data文件夹,并记录在dataset_info.json中 cd ./data 打开 dataset_info.json 并加入数据集,例如 "my_example": { "file_name": "my_example.json" }, # SFT数据使用Alpaca 或ShareGPT 格式,此处用Alpaca示例 # Alpaca格式:(其中instruction会和input自动用\n拼接) [{ "instruction": "人类指令(必填)", "input": "人类输入(选填)", "output": "模型回答(必填)", "system": "系统提示词(选填)", "history": [ ["第一轮指令(选填)", "第一轮回答(选填)"], ["第二轮指令(选填)", "第二轮回答(选填)"] ] }] 单机多卡训练 # 参考./examples里存在的模版准备一个yaml文件并运行即可。 # 如果使用deepspeed 来执行多卡训练,通过 CUDA_VISIBLE_DEVICES 来指定用多少张gpu CUDA_VISIBLE_DEVICES=0,1 FORCE_TORCHRUN=1 llamafactory-cli train examples/train_lora/qwen3_30b_lora_sft.yaml #训练完以后的参数可以在 yaml 文件里的 output_dir 路径找到 训练完后可以用vllm调用lora框架,这里是一个docker compose 的模板 ...

2026-01-21 · 1 分钟 · 162 字 · Me