驱动版本与库文件不匹配(Failed to initialize NVML: Driver/library version mismatch)导致nvidia驱动无法运行的解决思路(不重启)

发现nvidia-smi没法用了,但是之前启动的训练进程还没挂,尝试通过不重启进程、显卡、服务器的条件下解决问题。

  1. 使用nvidia-smi命令时提示报错:Failed to initialize NVML: Driver/library version mismatch。提示驱动版本与库文件不匹配

  2. 使用命令查看nvidia相关的安装记录

    cat /var/log/dpkg.log | grep nvidia
    

    发现确实存在对现有的NVIDIA相关的库文件进行改动的记录,可能是他人安装驱动失败的结果。

  3. 根据命令的结果,查找到现有驱动的版本

    cat /proc/driver/nvidia/version
    

    NVRM version: NVIDIA UNIX x86_64 Kernel Module 535.54.03 Tue Jun 6 22:20:39 UTC 2023
    GCC version: gcc version 12.3.0 (Ubuntu 12.3.0-1ubuntu1~23.04)
    (现有目前的GCC版本也对不上号了,需要切换)
    使用如下命令后,输入对应版本的数字并按回车,直接切换即可

     sudo update-alternatives --config gcc
    
    > $ sudo update-alternatives --config gcc
      [sudo] password for test: 
      There are 2 choices for the alternative gcc (providing /usr/bin/gcc).
        Selection    Path             Priority   Status
      ------------------------------------------------------------
        0            /usr/bin/gcc-10   10        auto mode
      * 1            /usr/bin/gcc-10   10        manual mode
        2            /usr/bin/gcc-9    9         manual mode
    
    Press <enter> to keep the current choice[*], or type selection number: 
    
  4. 查找并对应版本的驱动的安装包

  5. 使用--no-kernel-modules配置,来运行.run文件,实现只安装驱动核心以外的部分来对库文件等部分进行更新

    sudo sh NVIDIA-Linux-x86_64-535.54.03.run   --no-kernel-modules
    
  6. 试用nvidia-smi命令,问题成功解决,并且原有进程依然存在,在没有重启和关闭GPU相关的进程的的前提下解决了问题。
    安装选项可参考参考链接2,下面问题的选项可选No

    Would you like to run the nvidia-xconfig utility to automatically update your X configuration file so that the NVIDIA X driver will be used when you restart X?
    Any pre-existing X configuration file will be backed up.
    Yes No

参考链接

  1. Ubuntu 上切换多个版本的 GCC 编译器_ubuntu 切换gcc-CSDN博客
  2. Ubuntu在安装NVIDIA驱动后黑屏无法启动进入图形桌面_would you like to run the nvidia-xconfig utility t-CSDN博客
posted @ 2024-04-16 23:53  castall  阅读(924)  评论(0编辑  收藏  举报