记一次服务器Cuda驱动崩溃修复过程

本文最后更新于:2023年11月8日 中午

基本过程

今天实验室师兄在服务器运行深度学习训练时候得到报错CUDA initialization: Unexpected error from cudaGetDeviceCount()疑似Cuda与NVIDIA显卡驱动沟通中出现了问题,使用nvidia-smi指令时提示Failed to initialize NVML: Driver/library version mismatch,经过沟通了解到,重启与重新配置Cuda环境均未能解决上述问题。

根据社区类似问题的帖子下工程师的指引,使用nvidia-bug-report.sh输出了报错的基本日志,得到如下关键信息

Oct 21 06:40:46 ubuntu-C621-WD12-IPMI kernel: [676742.295632] NVRM: API mismatch: the client has the version 535.113.01, but
Oct 21 06:40:46 ubuntu-C621-WD12-IPMI kernel: [676742.295632] NVRM: this kernel module has the version 525.105.17. Please
Oct 21 06:40:46 ubuntu-C621-WD12-IPMI kernel: [676742.295632] NVRM: make sure that this kernel module and all NVIDIA driver
Oct 21 06:40:46 ubuntu-C621-WD12-IPMI kernel: [676742.295632] NVRM: components have the same version.

定位基本问题为Cuda版本可能有自动更新,因此跟进/var/log/apt/history.log中,找到关于NVIDIA相关的信息

Install: nvidia-profiler:amd64 (10.1.243-3, automatic), nvidia-cuda-toolkit:amd64 (10.1.243-3), nvidia-visual-profiler:amd64 (10.1.243-3, automatic), nvidia-cuda-dev:amd64 (10.1.243-3, automatic), nvidia-cuda-doc:amd64 (10.1.243-3, automatic), nvidia-cuda-gdb:amd64 (10.1.243-3, automatic)
Upgrade: libnvidia-compute-535:amd64 (535.113.01-0ubuntu0.20.04.1, 535.113.01-0ubuntu0.20.04.3)

因此基本可以断定这次出错是由cuda-toolkit更新连带引起的

解决方案

先尝试通过将libnvidia-compute-535版本降到525版本,发现小版本号依然对不上(之前运维没有及时更新),所以考虑将kernel版本升级到535版本

首先运行sudo apt purge nvidia* libnvidia*准备重新安装,然后运行sudo apt install nvidia-driver-535,再次运行nvidia-smi,问题得解。

思考

在生产环境中应当尽可能避免做敏感升级和安装行为,在安装前最好检查一下要求的工具链,提前做好准备工作


记一次服务器Cuda驱动崩溃修复过程
https://www.0error.net/2023/11/52988.html
作者
Jiajun Chen
发布于
2023年11月2日
许可协议