LLaMA-Factory多机多卡训练实战

https://www.dong-blog.fun/post/1999

参考资料:https://llamafactory.readthedocs.io/zh-cn/latest/advanced/distributed.html

以训练qwen2.5vl 7b 为例子。

创建空间

创建数据集

如果数据集文件非常多,可以选择上tar.gz包,然后再数据集页面面,点击终端进入到/mnt/data目录。执行 tar-zxfxxx.tar.gz 命令解压,请解压到当前目录(/mnt/data目录是挂载盘目录)

上传模型

制作一个训练镜像

启动镜像,进入容器中设置数据集和平台匹配。

bash 复制代码
docker run -it --rm --gpus  '"device=1,2,3"' --shm-size 16G kevinchina/deeplearning:llamafactory20250311-3 bash
bash 复制代码
如果镜像用的是ubuntu
要执行一下命令,安装libibverbs1才能使用rdma网卡,加速训练
sudo apt-get update
sudo apt-get install libibverbs1 -y

这个镜像里已经安装:

bash 复制代码
root@260e21033aae:/app# apt-get install libibverbs1 -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
libibverbs1 is already the newest version (39.0-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

在data里增加训练json数据集,/app/examples/train_lora中增加训练yaml文件。

docker commit 这个容器,将此镜像传到hub。

创建任务

为了多机多卡,需要在每台机器启动这个:

bash 复制代码
FORCE_TORCHRUN=1 NNODES=2 NODE_RANK=0 MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 llamafactory-cli train examples/train_lora/qwen2vl_lora_sft_zizhi.yaml

FORCE_TORCHRUN=1 NNODES=2 NODE_RANK=1 MASTER_ADDR=192.168.0.1 MASTER_PORT=29500 llamafactory-cli train examples/train_lora/qwen2vl_lora_sft_zizhi.yaml

训练指令写为下面这样,那三个变量由环境自动指定:

bash 复制代码
FORCE_TORCHRUN=1 \
NNODES=2 \
NODE_RANK=${RANK} \
MASTER_ADDR=${MASTER_ADDR} \
MASTER_PORT=${MASTER_PORT} \
llamafactory-cli train examples/train_lora/qwen2vl_lora_sft_zizhi.yaml

此外,为了为rDMA,需要设置这三个环境变量:

复制代码
CUDA_DEVICE_MAX_CONNECTIONS=1
NCCL_DEBUG=INFO
NCCL_IB_DISABLE=0
相关推荐
修一呀1 天前
[大模型微调]基于llama_factory用 LoRA 高效微调 Qwen3 医疗大模型:从原理到实现
人工智能·llama·大模型微调
liliangcsdn1 天前
基于llama.cpp的量化版reranker模型调用示例
人工智能·数据分析·embedding·llama·rerank
gptplusplus1 天前
Meta AI 剧变:汪滔挥刀重组,Llama 开源路线告急,超级智能梦碎还是重生?
人工智能·开源·llama
AI大模型6 天前
基于 Docker 的 LLaMA-Factory 全流程部署指南
docker·llm·llama
m0_6038887112 天前
LLaMA-Adapter V2 Parameter-Efficient Visual Instruction Model
人工智能·深度学习·ai·llama·论文速览
三千院本院16 天前
LlaMA_Factory实战微调VL大模型
llama
爱分享的飘哥21 天前
第四十六章:AI的“瞬时记忆”与“高效聚焦”:llama.cpp的KV Cache与Attention机制
llama·llama.cpp·kv cache·attention优化·llm cpu推理·量化attention·gguf推理
psyq22 天前
LLaMA Factory 角色扮演模型微调实践记录
人工智能·llama
liliangcsdn1 个月前
mac测试ollama llamaindex
数据仓库·人工智能·prompt·llama
茫茫人海一粒沙1 个月前
使用 LLaMA 3 8B 微调一个 Reward Model:从入门到实践
llama