A100单机多卡大模型训练踩坑记录(CUDA环境、多GPU卡住且显存100%)

news/2024/7/20 18:53:54 标签: linux, ubuntu, 运维, 单机多卡, 大模型

踩坑1:服务器只装了 CUDA Driver 没装 CUDA Toolkit

系统:Ubuntu-18.04
deepspeed 跑百亿模型训练时,报关于 CUDA_HOME 的错误。

AssertionError: CUDA_HOME does not exist, unable to compile CUDA op(s)

执行 echo $CUDA_HOMEnvcc -V 发现没装 cuda(只装了显卡驱动因此 nvidia-smi 执行没问题,而 torch.cuda.is_available() 返回 True 是因为 pip install 环境时,cudatoolkit 之类的已经装到了 python 环境里)。

于是按提示执行 sudo apt install nvidia-cuda-toolkit,这个命令不会给你把 cuda 装到 /usr/local/cuda,而是分散到很多地方,而且装的是 9.1 版本,跟 deepspeed 环境支持版本不兼容:
在这里插入图片描述
因此找运维看看能不能给装个 cuda 11.3,于是运维甩来 nvidia 官网的安装命令(来自这个链接):
在这里插入图片描述
然而,前两种安装方式(deb)都遇到问题(要么是 apt-key 那步公钥问题,要么最后一步报错)

$ sudo apt-get -y install cuda

Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 cuda : Depends: cuda-12-1 (>= 12.1.1) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

于是用runfile方式本地安装成功!执行:

$ wget https://developer.download.nvidia.com/compute/cuda/11.3.0/local_installers/cuda_11.3.0_465.19.01_linux.run
$ sudo sh cuda_11.3.0_465.19.01_linux.run

在这里插入图片描述
安装时提示检测到装了驱动,直接选continue,在下一步取消选择 driver 那项,只选 cuda toolkit 的相关那些进行安装(参考资料)
安装完后,输出如下:

===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-11.3/
Samples:  Installed in /u01/isi/, but missing recommended libraries

Please make sure that
 -   PATH includes /usr/local/cuda-11.3/bin
 -   LD_LIBRARY_PATH includes /usr/local/cuda-11.3/lib64, or, add /usr/local/cuda-11.3/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-11.3/bin
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 465.00 is required for CUDA 11.3 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
    sudo <CudaInstaller>.run --silent --driver

Logfile is /var/log/cuda-installer.log

此时,/usr/local/cuda-11.3/ 成功出现。
在这里插入图片描述

最后按提示配环境变量(没用sudo用户配,配的个人用户)。在 ~/.bashrc 中追加( :$PATH 的含义是追加到环境变量 $PATH 的末尾,最后 LD_LIBRARY_PATH 那行非必要,我是因为不加的话 deepspeed 报错才加上):

export PATH=/usr/local/cuda-11.3/bin:$PATH  
export LD_LIBRARY_PATH=/usr/local/cuda-11.3/lib64:$LD_LIBRARY_PATH
export CUDA_HOME=/usr/local/cuda-11.3
export LD_LIBRARY_PATH=/u01/xxxxxxx/miniconda3/envs/xxxx/lib/python3.8/site-packages/nvidia/cublas/lib/:$LD_LIBRARY_PATH

此时执行 nvcc -V 就正常了!(其实后面又换了个11.4的版本)
在这里插入图片描述

踩坑2:超过2张卡就直接卡住不动 且显存占用100%

不管是跑 deepspeed 还是只用 python -m torch.distributed.launch --nproc_per_node 4 train.py 跑数据并行,单卡或者两卡都没事,只要大于3卡,直接卡死,而且显存占用一直100%。
在这里插入图片描述
折磨了大半天,一篇知乎文章拯救了我。根据文章,是由于BIOS里IO虚拟化默认启动了PCI访问控制服务(ACS)导致GPU间无法直接通过P2P方式通信。最快的方案,执行之前添加环境变量:

export NCCL_P2P_DISABLE=1

执行命令训练百亿模型实验,成功。

export TOKENIZERS_PARALLELISM=false
export NCCL_P2P_DISABLE=1
deepspeed --num_gpus=8 \
    --module training.trainer \
    --data-path data/train_20230426.json \
    --input-model checkpoints/xxx \
    --deepspeed config/stage2.json \
    --epochs 3 \
    --local-output-dir results \
    --per-device-train-batch-size 2 \
    --per-device-eval-batch-size 2 \
    --logging-steps 5 \
    --save-steps 100 \
    --save-total-limit 10 \
    --eval-steps 100 \
    --warmup-steps 100 \
    --test-size 500 \
    --lr 2e-5 \
    --seed 515

http://www.niftyadmin.cn/n/273084.html

相关文章

4月JAVA面试太难,吃透这份JAVA架构面试笔记后,成功涨到30K

昨天跟一位高级架构师的前辈聊天时&#xff0c;聊到今年的面试。有两个感受&#xff0c;一个是今年面邀的次数比往年要低不少&#xff0c;再一个就是很多面试者准备明显不足。不少候选人能力其实不差&#xff0c;进入团队干活后达到期望不难&#xff0c;但由于没准备或不会表达…

uniapp 截图或者生成海报

需求&#xff1a;uniapp移动端需要生成一张当前界面的海报 方案一&#xff1a;类似于手机按钮截图效果。实现代码如下&#xff1a; doSaveScreen() { let $this this; uni.showLoading({ //加载框 title: 保存中..., …

Cahpter 3 : Defining Clocks(ug903:Vivado using constraints

1、About Clocks 在数字设计中&#xff0c;时钟代表了从寄存器到寄存器可靠传输数据的时间基准。XilinxVivado集成设计环境&#xff08;IDE&#xff09;时序引擎使用时钟特性来计算时序路径要求&#xff0c;并通过松弛计算报告设计时序裕度。必须正确定义时钟&#xff…

Github为开发者打造的AI代码编写建议插件

仓库&#xff1a; GitHub - github/copilot.vim: Neovim plugin for GitHub Copilot 特性&#xff1a; GitHub Copilot Your AI pair programmer GitHub 目录 代码建议 付费使用 专注于解决问题 支持常用IDE ​在不熟悉的领域自信地编写代码 GitHub Copilot使用Open…

【2023年五一数学建模竞赛C题】“双碳”目标下低碳建筑研究--完整思路和代码

1.问题背景与描述 赛题评析&#xff1a;这道题其实主要还是考察学生搜集资料的能力&#xff0c;可发挥空间大&#xff0c;适合小白快速上手 2.解题思路分析 2.1 问题一的分析 1.空调性能系数 2.热导系数 热导系数是指物质导热的能力&#xff0c;通常用单位时间内单位面积…

卡尔曼滤波器简介——多维卡尔曼滤波

原文&#xff1a;多维卡尔曼滤波 (kalmanfilter.net) 目录 前言 基本背景 状态外推方程 示例 - 飞机 - 无控制输入 示例 - 带控制输入的飞机 示例 – 坠落物体 状态外推方程维度 线性时不变系统 线性动态系统建模 状态外推方程的推导 状态空间表示形式 示例 - 等速…

HTTPS建立连接原理、SSL工作原理

HTTPS与HTTP相比有什么区别&#xff1f; HTTPS保证安全的原理是什么&#xff1f; HTTPS是如何建立连接的&#xff1f; 巨人的肩膀 3.1 HTTP 常见面试题 | 小林coding HTTP与HTTPS的区别 HTTP是超文本传输协议&#xff0c;传输的内容是明文(HTTP1.1及之前版本)。HTTPS在TCP与HT…

「C/C++」C/C++静态链接库与动态链接库

博客主页&#xff1a;何曾参静谧的博客 文章专栏&#xff1a;「C/C」C/C学习 目录 相关术语案例环境&#xff1a;Win10VS2019一、链接库介绍二、静态链接库&#xff08;Static Library&#xff09;2.1、静态库优缺点2.2、静态库的创建2.2.1、创建静态库项目2.2.2、添加.h头文件…