当前位置:   article > 正文

centos 7.x 上安装 AI insightface + pytorch + cuda

centos 7.x 上安装 AI insightface + pytorch + cuda

centos 英伟达检查工具

lsb_release -a
nvidia-smi
lspci | grep -i nvidia

CUDA v11.7 安装

首先在centos机器上必须先安装英伟达驱动,参考下面的文档
https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#
https://developer.nvidia.com/cuda-11-8-0-download-archive

然后用 nvidia-smi 检查是否有输出,例子如下:

Wed Mar 13 20:30:18 2024       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 515.65.01    Driver Version: 515.65.01    CUDA Version: 11.7     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Quadro RTX 4000     Off  | 00000000:3B:00.0 Off |                  N/A |
| 30%   35C    P8     9W / 125W |   2829MiB /  8192MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
|   1  Quadro RTX 4000     Off  | 00000000:5E:00.0 Off |                  N/A |
| 30%   31C    P8     2W / 125W |      3MiB /  8192MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
|   2  Quadro RTX 4000     Off  | 00000000:B1:00.0 Off |                  N/A |
| 30%   35C    P8    12W / 125W |      3MiB /  8192MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
|   3  Quadro RTX 4000     Off  | 00000000:D9:00.0 Off |                  N/A |
| 30%   31C    P8     9W / 125W |      3MiB /  8192MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A     54587      C   python                           2045MiB |
|    0   N/A  N/A    254047      C   python                            781MiB |
+-----------------------------------------------------------------------------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

其它安装需要的依赖软件

conda create -n ai_py310 python==3.10
conda activate ai_py310
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config list

安装pytorch会自动安装 numpy 和 cudnn(cudnn会自动安装cudatoolkit包)

参考文档安装pytorch, https://pytorch.org/get-started/previous-versions/

conda install pytorch2.0.1 torchvision0.15.2 torchaudio2.0.2 pytorch-cuda=11.7 -c pytorch -c nvidia
#如果用pip安装,则用下面的命令来安装Pytorhch支持 CUDA
#pip install torch
2.0.1 torchvision0.15.2 torchaudio2.0.2

CUDA 11.7

pip install torch2.0.1 torchvision0.15.2 torchaudio==2.0.2

CUDA 11.8

pip install torch2.0.1 torchvision0.15.2 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cu118

CPU only

pip install torch2.0.1 torchvision0.15.2 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cpu

pip install onnxruntime-gpu==1.14.1
#我们的是cuda 11.7,故用onnxruntime-gpu:1.14.1和conda install cudnn=8.9.2.26
#conda install cudnn=8.9.2.26 会安装cudatoolkit包
conda install cudnn=8.9.2.26

pip install insightface==0.7.3
pip install tqdm
pip install redis
pip install boto3
pip install opencv-python
pip install python-multipart
pip install fastapi
pip install uvicorn
pip install pillow
pip install loguru
pip install psutil

//安装 ffmpeg
#通过源码编译方式安装,见 https://blog.csdn.net/coding_zhang/article/details/87178146

wget https://ffmpeg.org/releases/ffmpeg-6.1.1.tar.xz
tar -xf ./ffmpeg-6.1.1.tar.xz
cd ffmpeg-6.1.1
./configure --prefix=/data/home/tanghongbin/ffmpeg
#碰到 nasm/yasm not found or too old. Use --disable-x86asm for a crippled build.

则执行 yum install yasm

make && make install

git config --global user.name tanghongbin
git config --global credential.helper cache

附录
ONNX runntime和cuda版本对应:
https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#requirements
pytorch和cuda版本对应:
https://pytorch.org/get-started/previous-versions/
docker nvida install guide:
https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/289286
推荐阅读
相关标签
  

闽ICP备14008679号