惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
NISL@THU
NISL@THU
T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
Lohrmann on Cybersecurity
V
Visual Studio Blog
Cyberwarzone
Cyberwarzone
D
Docker
The Hacker News
The Hacker News
C
CERT Recently Published Vulnerability Notes
Vercel News
Vercel News
Project Zero
Project Zero
S
Schneier on Security
aimingoo的专栏
aimingoo的专栏
I
Intezer
腾讯CDC
M
MIT News - Artificial intelligence
Hugging Face - Blog
Hugging Face - Blog
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
Vulnerabilities – Threatpost
G
Google Developers Blog
N
Netflix TechBlog - Medium
The Cloudflare Blog
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
A
Arctic Wolf
S
Securelist
酷 壳 – CoolShell
酷 壳 – CoolShell
Cisco Talos Blog
Cisco Talos Blog
Recent Announcements
Recent Announcements
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 热门话题
T
Threatpost
Latest news
Latest news
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
The GitHub Blog
The GitHub Blog
T
Tor Project blog
P
Proofpoint News Feed

Miya's Blog

博客大修记录 (2026) 我在用什么? 记一次软件源归档导致的 CI 构建问题 Denoising Diffusion Null-Space Model 可逆神经网络 Invertible Diffusion Model 常见推理后端安装及配置 Jupyter Notebook 安装及配置 论文复现 - MAGIS 浅谈非易失内存 深度学习环境配置(二) Debian 配置 V2Ray-A Diffusion 入门 CV 基础(二) CV 基础(一) 内存体系结构 - 简述 Programming Persistent Memory 第三章笔记 地址映射与TLB CuBase 小记
深度学习环境配置(一)
Miya · 2025-04-20 · via Miya's Blog

CUDA/CuDNN/PyTorch 安装配置

前置 | Python 安装

因为一些原因,Python 采用手动编译安装。参考 [1] 查找版本对应,切换 Python 版本,然后执行如下命令进行手动编译安装

1
2
./configure --enable-optimizations
make altinstall

安装后进行版本切换。最好通过 config alter,如果只是临时使用,在 .bashrc 使用 alias 命令临时替换也可以,如下

1
2
3

alias python='/usr/local/bin/python3.x'
$ source ~/.bashrc

卸载命令如下。源码安装情况下,删除目录便是卸载

1
2
rm -rf /usr/local/bin/python3.x
rm -rf /usr/local/bin/python3.x-config

注意事项。编译安装后,装包时容易报 ModuleNotFoundError 或动态库链接缺失等。解决方案是把缺的包装好后重新编译 Python,以 BZIP2 为例

1
apt install libbz2-dev

CUDA

安装 CUDA 前,首先确保已安装了 Nvidia 驱动,并执行 nvidia-smi 检查当前 Nvidia 驱动支持的最高 CUDA 版本。如果机器上已经有 CUDA,建议切换版本安装,不卸载当前版本 CUDA。

检查 CUDA 安装情况

1
2
whereis cuda

1
2
3
sudo dpkg -l | grep cuda


卸载当前 CUDA 命令如下。不建议此方式。

1
sudo dpkg --remove libcuda1:amd64

安装 CUDA。官方网站提供 .deb .run 等安装方式,这里使用 .run

1
2
wget https://developer.download.nvidia.com/compute/cuda/11.6.2/local_installers/cuda_11.6.2_510.47.03_linux.run
sudo sh cuda_11.6.2_510.47.03_linux.run

根据提示完成安装,然后在 .bashrc 设置环境变量

1
2
export PATH="/usr/local/cuda-x.x/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda-x.x/lib64:$LD_LIBRARY_PATH"

检查 CUDA 安装情况,nvcc 有输出,则初步安装完成。

1
2
3
4
5
6
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Tue_Mar__8_18:18:20_PST_2022
Cuda compilation tools, release 11.6, V11.6.124
Build cuda_11.6.r11.6/compiler.31057947_0

CuDNN

从 .tar 安装或更换 CuDNN

1
2
3
4
tar -xvf cudnn-linux-x86_64-8.4.0.27_cuda11.6-archive.tar.xz
mv ...
sudo cp include/cudnn* /usr/local/cuda-11.6/include/
sudo cp lib/libcudnn* /usr/local/cuda-11.6/lib64/

现在,分别从 torch 和源码检查 CuDNN 版本,发现并不一致

从 torch 检查

1
2
>>> print(torch.backends.cudnn.version())
90100

从源码检查

1
2
3
4
cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2



实战中并无影响,所以便没有修复。如果从 Conda 安装会容易很多。

PyTorch

安装时需要注意版本匹配 (CUDA/CuDNN/PyTorch) 方可正常运行。本次实验安装 PyTorch 1.13

1
pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116

附 | NumPy

可能遇到 NumPy 相关报错,一般是使用了 Numpy 1.x 的废弃接口导致。将 Numpy 降回 v1.26 即可。


  1. https://juejin.cn/post/7329572942274363430 ↩︎

版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Miya's Blog