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 |
+-----------------------------------------------------------------------------+

其它安装需要的依赖软件

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

  • 21
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值