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

推荐订阅源

B
Blog RSS Feed
Jina AI
Jina AI
雷峰网
雷峰网
Blog — PlanetScale
Blog — PlanetScale
Hugging Face - Blog
Hugging Face - Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
博客园 - 司徒正美
罗磊的独立博客
J
Java Code Geeks
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
Vercel News
Vercel News
A
About on SuperTechFans
I
InfoQ
D
DataBreaches.Net
爱范儿
爱范儿
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
U
Unit 42
aimingoo的专栏
aimingoo的专栏
宝玉的分享
宝玉的分享
P
Proofpoint News Feed
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队

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/