【Stable-Diffusion/SD-WebUI】适配40系高算力之环境安装(WSL2+Docker+Nvdia-Smi+CUDA+cuDNN) Docker Stable-Diffusion
1、 Win10安装最新nvidia显卡驱动(最新版本N卡驱动已经集成wsl)
The NVIDIA Windows GeForce or Quadro production (x86) driver that NVIDIA offers comes with CUDA and DirectML support for WSL
https://www.nvidia.com/Download/index.aspx?lang=zh-cn
2、Win10安装WSL2
https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
# 启动管理员PowerShell Start-Process powershell -Verb runAs # 启用 wsl 低於18362 的版本不支持WSL 2 dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart # 启用虚拟机 dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart # 设置 wsl 默认版本 wsl --set-default-version 2 # 查看可用Linux发行版 wsl -l -o # 目前已安装发行版及版本 wsl -l -v # 安装发行版 wsl -d Ubuntu-22.04 --cd 存储目录 # 默认登陆用户root ubuntu2204.exe config --default-user root # 进入子系统 bash # 查看是否有显卡驱动 nvidia-smi # nvidia-smi无效的解决办法,不用重装nvdia驱动 # 普通用户及root配置环境变量 vim ~/.bashrc # 末尾加入 export PATH=$PATH:/usr/lib/wsl/lib source ~/.bashrc
将已有ubuntu系统迁移到其他盘
wsl --export Ubuntu-22.04 d:\WSL\ubuntu2204.tar wsl --unregister Ubuntu-22.04 wsl --import Ubuntu-22.04 d:\WSL\Ubuntu-22.04 d:\WSL\ubuntu2204.tar
3、根据nvidia-smi,选择安装对应版本的cuda(11.8.0),选择Linux -> x86_64 -> WSL-Ubuntu -> 2.0 -> runfile(local)
# 安装gcc Cuda 安装需要 apt install -y build-essential # 下载和安装 wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run sudo sh cuda_11.8.0_520.61.05_linux.run
安装出错: Unable to find the kernel source tree for the currently running kernel 解决方法: # 查看内核版本 root@DESKTOP-990CIL0:~# uname -r 5.15.90.1-microsoft-standard-WSL2 # 下载安装对应内核头文件及源码(安装失败) https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.15.90/ cd /opt wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.15.90/amd64/linux-headers-5.15.90-051590-generic_5.15.90-051590.202301240242_amd64.deb && wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.15.90/amd64/linux-headers-5.15.90-051590_5.15.90-051590.202301240242_all.deb && wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.15.90/amd64/linux-image-unsigned-5.15.90-051590-generic_5.15.90-051590.202301240242_amd64.deb sudo dpkg -i *.deb
# 下载安装对应内核头文件及源码(WSL2) https://github.com/microsoft/WSL2-Linux-Kernel cd /usr/src wget https://github.com/microsoft/WSL2-Linux-Kernel/archive/refs/tags/linux-msft-wsl-5.15.90.1.tar.gz && tar -xzvf linux-msft-wsl-5.15.90.1.tar.gz
# 修改环境变量 vim ~/.bashrc # 文件未追加 #export PATH=/usr/local/cuda/bin${PATH:+:${PATH}} #export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} export PATH=$PATH:/usr/local/cuda/bin:~/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64 # reload 环境变量配置 source ~/.bashrc # 检查是否生效 nvcc -V
# 测试cuda apt install -y git cd /opt && git clone https://github.com/NVIDIA/cuda-samples.git cd ./cuda-samples/Samples/1_Utilities/deviceQuery make ./deviceQuery # 输出Pass 则成功了
4、安装cuda对应的cudnn(8.9.1.23)
当前版本:
https://developer.nvidia.com/rdp/cudnn-download
历史版本:
https://developer.nvidia.com/rdp/cudnn-archive
https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html
apt-get -y install zlib1g libfreeimage-dev && dpkg -i cudnn-local-repo-ubuntu2204-8.9.1.23_1.0-1_amd64.deb && cp /var/cudnn-local-repo-ubuntu2204-8.9.1.23/cudnn-local-1E24EB2B-keyring.gpg /usr/share/keyrings/ && dpkg -i cudnn-local-repo-ubuntu2204-8.9.1.23_1.0-1_amd64.deb && apt update && apt install -y libcudnn8 libcudnn8-dev libcudnn8-samples && cp -r /usr/src/cudnn_samples_v8/ $HOME && cd $HOME/cudnn_samples_v8/mnistCUDNN && make clean && make && ./mnistCUDNN # 输出Test passed! 则成功了
# 查看cudnn版本 cat /etc/alternatives/cudnn_version_h |grep CUDNN_MAJOR -A 2
#define CUDNN_MAJOR 8 #define CUDNN_MINOR 9 #define CUDNN_PATCHLEVEL 1 -- #define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL) /* cannot use constexpr here since this is a C-only file */
低版本升级到高版本cudnn,手动选择更新配置 sudo update-alternatives --config libcudnn
5、安装nvidia-docker2
curl https://get.docker.com | sh distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \ && curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - \ && curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list \ && curl -s -L https://nvidia.github.io/libnvidia-container/experimental/$distribution/libnvidia-container-experimental.list | sudo tee /etc/apt/sources.list.d/libnvidia-container-experimental.list sudo apt update sudo apt-get install nvidia-docker2 service docker start # 搜索符合当前cuda版本的镜像 https://hub.docker.com/r/nvidia/cuda # 拉取镜像 docker pull nvidia/cuda:12.0.1-devel-ubuntu22.04 # nvidia-docker 测试 sudo docker run -idt --name nvidia_docker_test --gpus all --shm-size 16G nvidia/cuda:12.0.1-devel-ubuntu22.04 && sudo nvidia-docker start nvidia_docker_test && sudo nvidia-docker attach nvidia_docker_test # 查看是否有显卡驱动 nvidia-smi # 有则判定 nvidia-docker 已经成功安装和使用 exit
最新回复 (0)