Ubuntu18.04 安装CUDA进行AI工具使用的准备

人工智能
后台-插件-广告管理-内容页头部广告(手机)

Ubuntu 上安装CUDA流程记录。

先和Chat-GPT打个招呼,问问他如何搞。

作为一个系统架构师,现在需要搭建一个stable diffusion本地服务,目前手上有一台32G内存点Ubuntu的服务器,安装英伟达点显卡

Q:终端上安装nvidia驱动的指令

您可以使用以下命令在终端上安装NVIDIA驱动程序:

1. 添加NVIDIA驱动程序PPA存储库

```

sudo add-apt-repository ppa:graphics-drivers/ppa

sudo apt-get update

```

2. 安装NVIDIA驱动程序

如果您想安装最新版本的NVIDIA驱动程序,可以使用以下命令:

```

sudo apt-get install nvidia-driver-460

```

如果您希望安装其他版本的NVIDIA驱动程序,可以将“460”替换为您想要安装的版本号。

3. 检查NVIDIA驱动程序是否正确安装

您可以使用以下命令检查NVIDIA驱动程序是否正确安装:

```

nvidia-smi

```

如果您能够看到类似于以下内容的输出,则表示NVIDIA驱动程序已正确安装:

```

+-----------------------------------------------------------------------------+

| NVIDIA-SMI 465.19.01 Driver Version: 465.19.01 CUDA Version: 11.3 |

|-------------------------------+----------------------+----------------------+

| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |

| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |

| | | |

| 0 NVIDIA GeForce ... Off | 00000000:01:00.0 Off | N/A |

| 0% 38C P0 47W / 170W | 0MiB / 5934MiB | 0% Default |

| | | |

+-----------------------------------------------------------------------------+

```

总结:

以上就是在终端上安装NVIDIA驱动程序的指令。需要注意的是,安装NVIDIA驱动程序可能需要一些时间和配置。但一旦安装完成,您就可以在本地环境中使用Stable Diffusion了。

安装过程中,出现了大量的错误信息,应该是之前的安装导致的错误
E: The repository 'file:/var/cuda-repo-ubuntu1804-11-2-local Release' no longer has a Release file.

N: Updating from such a repository can't be done securely, and is therefore disabled by default.

N: See apt-secure(8) manpage for repository creation and user configuration details.

E: The repository 'file:/var/cuda-repo-ubuntu2004-11-6-local Release' no longer has a Release file.

N: Updating from such a repository can't be done securely, and is therefore disabled by default.

N: See apt-secure(8) manpage for repository creation and user configuration details.

E: The repository 'http://ppa.launchpad.net/maas/3.0/ubuntu bionic Release' does not have a Release file.

N: Updating from such a repository can't be done securely, and is therefore disabled by default.

N: See apt-secure(8) manpage for repository creation and user configuration details.

搜了一下解决方案,nvidia有官方的做法

https://developer.nvidia.com/blog/updating-the-cuda-linux-gpg-repository-key/

具体就是先删除Key,然后重新安装

sudo apt-key del 7fa2af80

(nvidia) ubuntu@ubun:~$ sudo rpm --erase gpg-pubkey-7fa2af80*

rpm: RPM should not be used directly install RPM packages, use Alien instead!

rpm: However assuming you know what you are doing...

error: package gpg-pubkey-7fa2af80* is not installed

安装新的Key

Ubuntu18.04 安装CUDA进行AI工具使用的准备

需要注意的是:$distro/$arch 要替换掉

export distro=ubuntu1804
export arch=x86_64 再执行安装新key的指令

$ wget https://developer.download.nvidia.com/compute/cuda/repos/$distro/$arch/cuda-keyring_1.0-1_all.deb

$ sudo dpkg -i cuda-keyring_1.0-1_all.deb

然后安装最新版本驱动

sudo apt-get install nvidia-driver-460

安装结束,执行nvidia-smi 出错

Failed to initialize NVML: Driver/library version mismatch

再次询问Chat-GPT

这个错误提示表明,您正在使用的NVIDIA驱动程序版本与您的NVIDIA管理库(NVML)版本不匹配。为了解决这个问题,您需要卸载旧版本的NVML并安装新版本的NVML。

以下是解决此问题的步骤:

1. 卸载旧版本的NVML

使用以下命令卸载旧版本的NVML:

```

sudo apt-get remove nvidia-ml*

```

2. 下载新版本的NVML

从NVIDIA官方网站下载最新版本的NVML。您可以在以下链接中找到适合您的操作系统和硬件的NVML版本:https://developer.nvidia.com/nvidia-management-library-nvml

3. 安装新版本的NVML

解压缩下载的NVML包,并使用以下命令安装:

```

sudo ./install.sh

```

4. 检查NVML是否正确安装

您可以使用以下命令检查NVML是否正确安装:

```

nvidia-smi

```

如果您能够看到类似于以下内容的输出,则表示NVML已正确安装:

总结:

以上就是解决“Failed to initialize NVML: Driver/library version mismatch”错误的步骤。需要注意的是,安装NVML可能需要一些时间和配置。

根据提示找到download地方,然后选择和我的系统相匹配的下载方法

Ubuntu18.04 安装CUDA进行AI工具使用的准备

https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=18.04&target_type=deb_local

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pinsudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600wget https://developer.download.nvidia.com/compute/cuda/12.1.0/local_installers/cuda-repo-ubuntu1804-12-1-local_12.1.0-530.30.02-1_amd64.debsudo dpkg -i cuda-repo-ubuntu1804-12-1-local_12.1.0-530.30.02-1_amd64.debsudo cp /var/cuda-repo-ubuntu1804-12-1-local/cuda-*-keyring.gpg /usr/share/keyrings/sudo apt-get updatesudo apt-get -y install cuda

做完以上操作,reboot重启Ubuntu服务器,再次执行 nvidia-smi后依然抱错

(nvidia) ubuntu@ubun:~$ nvidia-smi

Failed to initialize NVML: Driver/library version mismatch

检查一下nvidia的安装版本

(nvidia) ubuntu@ubun:~$ cat /proc/driver/nvidia/version

NVRM version: NVIDIA UNIX x86_64 Kernel Module 460.106.00 Tue Sep 28 12:05:58 UTC 2021

GCC version: gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)

找了一下应该是之前安装其他版本的CUDA导致程序执行异常了。

https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#ubuntu

执行 sudo apt-get autoremove 清理无用的程序

sudo apt-get update

sudo apt-get install cuda

sudo apt-get install nvidia-gds

sudo reboot

重启后看到了 nvidia-smi的执行结果

Ubuntu18.04 安装CUDA进行AI工具使用的准备

完成,继续后面的环境搭建

后台-插件-广告管理-内容页尾部广告(手机)
标签:

评论留言

我要留言

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。