(llamafactory用多张4090卡,训练qwen14B大模型时oom(out of memory)报错,torch.OutOfMemoryError:CUDA out of memory,Tried to allocate 136MB,GPU 5 has a total capacity of 23.64GB which 16.56MB is free,已解决)
1.问题描述
通过export CUDA_VISIBLE_DVICES=0,1,2,3,4,5,6,7指定使用8张显卡,训练qwen2.5-7B大模型时正常,但训练qwen2.5-14B,qwen2.5-32B模型时报错,torch.OutOfMemoryError:CUDA out of memory,Tried to allocate 136MB,GPU 5 has a total capacity of 23.64GB which 16.56MB is free 。 大概意思就是说GPU显存不足,很明显不符合实际,我的8张4090卡总显存是8*24GB,理论上14B的大模型肯定能跑起来。
linux服务器环境: 系统:Ubuntu22; 硬件:本机512G内存,8张4090显卡; python:3.10版本; llamafactory版本:0.9.1.dev0; cuda版本:12.4版本; pytorch版本:2.4.0+cuda121(GPU); 大模型:qwen2.5(7B,14B,32B,72B)Instruct版;
2.解决方案

run_train_bash.sh文件中内容:
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 accelerate launch src/train.py \\
––deepspeed ds_config_zero3.json \\
––stage sft \\
––do_train True \\
––model_name_or_path /home/admin1/Qwen2.5
评论前必须登录!
注册