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 检查是否有输出,例子如下:

bash 复制代码
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 torch2.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

相关推荐
weixin_408099677 分钟前
python请求文字识别ocr api
开发语言·人工智能·后端·python·ocr·api·ocr文字识别
一休哥助手12 分钟前
2026年4月14日人工智能早间新闻
人工智能
跨境猫小妹12 分钟前
平台评价体系调整跨境卖家如何提升转化率
大数据·人工智能
用户5853437884324 分钟前
AI Harness Engineering:从概念、场景到落地方法
人工智能·后端
何中应32 分钟前
OpenClaw本地部署&使用
人工智能·ai·ai编程·openclaw
波动几何41 分钟前
通用内容构成方法论技能compose-methods
人工智能
bryant_meng1 小时前
【Hung-yi Lee】《Introduction to Generative Artificial Intelligence》(9)
人工智能·llm·aigc
用户585343788431 小时前
Harness Engineering:从 Prompt、Context 到 Agent 系统工程
人工智能·后端
春风化作秋雨1 小时前
从长方形面积到微积分:一场“累积”的思维革命
人工智能·数据