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

推荐订阅源

IT之家
IT之家
U
Unit 42
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
G
Google Developers Blog
Recent Announcements
Recent Announcements
B
Blog RSS Feed
罗磊的独立博客
博客园 - Franky
J
Java Code Geeks
S
SegmentFault 最新的问题
D
DataBreaches.Net
C
Check Point Blog
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
有赞技术团队
有赞技术团队
腾讯CDC
博客园_首页
美团技术团队
V
Visual Studio Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
GbyAI
GbyAI
The Cloudflare Blog
aimingoo的专栏
aimingoo的专栏

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
Dependency Hell When Building A PyTorch GPU Docker Image
2022-02-09 · via jdhao's digital space

In order to for PyTorch to use host GPU inside a Docker container, their versions must match.

Use correct nvidia-cuda docker as base image#

First, in order to use GPU, we can not just use a regular docker image as the base image, we need to use images provided by nvidia/cuda. For example, to use CUDA 10.1 as the base image:

FROM nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04
#... other build steps follows

Otherwise, even if you have installed PyTorch inside the container, torch.cuda.is_available() is still False.

PyTorch and torchvision versions#

Another point to remember is to install the right version of PyTorch that supports your CUDA versions. If you install PyTorch without specifying the version, the latest one is installed. It will have higher requirement for CUDA version. If you try to use CUDA, then you see error like this:

pytorch the nvidia driver on your system is too old (found version 10010)

To check which version of CUDA torch is built with, use torch.version.cuda (source here).

Find suitable PyTorch version#

To find the PyTorch version built with CUDA 10.1, in the PyTorch stable release page, search cu101. We know that there is v1.6.0 built with CUDA 10.1, then we can run the following command to install v1.6.0:

pip install torch==1.6.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html

Match torchvision with torch version#

The torchvision package version should also match version of torch. In this page, we can see a table of version correspondence. For example, for torch 1.6.0, torchvision 0.7.0 is fine. So our final install command:

pip install torch==1.6.0+cu101 torchvision==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

Ref#

https://pytorch.org/get-started/previous-versions/