博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
伤透了心的pytorch的cuda容器版
阅读量:4364 次
发布时间:2019-06-07

本文共 3860 字,大约阅读时间需要 12 分钟。

公司GPU的机器版本本比较低,找了好多不同的镜像都不行,

自己从anaconda开始制作也没有搞定(因为公司机器不可以直接上网),

哎,官网只有使用最新的NVIDIA驱动,安装起来才顺利。

最后,找到一个暂时可用的镜像:

https://linux.ctolib.com/anibali-docker-pytorch.html

其间遇到两个问题:

1, 安装全没出错,但torch.cuda.is_available()为False,这表示torch还是不能使用GPU。

2,在跑例程时,显示RuntimeError: CUDA error: out of memory,这表示运行的时候使用CUDA_VISIBLE_DEVICES限制一下使用的GPU。

 

PyTorch Docker image

Ubuntu + PyTorch + CUDA (optional)

Requirements

In order to use this image you must have Docker Engine installed. Instructions for setting up Docker Engine are .

CUDA requirements

If you have a CUDA-compatible NVIDIA graphics card, you can use a CUDA-enabled version of the PyTorch image to enable hardware acceleration. I have only tested this in Ubuntu Linux.

Firstly, ensure that you install the appropriate NVIDIA drivers and libraries. If you are running Ubuntu, you can install proprietary NVIDIA drivers  and CUDA .

You will also need to install nvidia-docker2 to enable GPU device access within Docker containers. This can be found at .

Prebuilt images

Pre-built images are available on Docker Hub under the name . For example, you can pull the CUDA 10.0 version with:

$ docker pull anibali/pytorch:cuda-10.0

The table below lists software versions for each of the currently supported Docker image tags available for anibali/pytorch.

Image tag CUDA PyTorch
no-cuda None 1.0.0
cuda-10.0 10.0 1.0.0
cuda-9.0 9.0 1.0.0
cuda-8.0 8.0 1.0.0

The following images are also available, but are deprecated.

Image tag CUDA PyTorch
cuda-9.2 9.2 0.4.1
cuda-9.1 9.1 0.4.0
cuda-7.5 7.5 0.3.0

Usage

Running PyTorch scripts

It is possible to run PyTorch programs inside a container using the python3 command. For example, if you are within a directory containing some PyTorch project with entrypoint main.py, you could run it with the following command:

docker run --rm -it --init \  --runtime=nvidia \  --ipc=host \  --user="$(id -u):$(id -g)" \ --volume="$PWD:/app" \ -e NVIDIA_VISIBLE_DEVICES=0 \ anibali/pytorch python3 main.py

Here's a description of the Docker command-line options shown above:

  • --runtime=nvidia: Required if using CUDA, optional otherwise. Passes the graphics card from the host to the container.
  • --ipc=host: Required if using multiprocessing, as explained at .
  • --user="$(id -u):$(id -g)": Sets the user inside the container to match your user and group ID. Optional, but is useful for writing files with correct ownership.
  • --volume="$PWD:/app": Mounts the current working directory into the container. The default working directory inside the container is /app. Optional.
  • -e NVIDIA_VISIBLE_DEVICES=0: Sets an environment variable to restrict which graphics cards are seen by programs running inside the container. Set to all to enable all cards. Optional, defaults to all.

You may wish to consider using  to make running containers with many options easier. At the time of writing, only version 2.3 of Docker Compose configuration files supports the runtimeoption.

Running graphical applications

If you are running on a Linux host, you can get code running inside the Docker container to display graphics using the host X server (this allows you to use OpenCV's imshow, for example). Here we describe a quick-and-dirty (but INSECURE) way of doing this. For a more comprehensive guide on GUIs and Docker check out .

On the host run:

sudo xhost +local:root

You can revoke these access permissions later with sudo xhost -local:root. Now when you run a container make sure you add the options -e "DISPLAY" and --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw". This will provide the container with your X11 socket for communication and your display ID. Here's an example:

 

docker run --rm -it --init \  --runtime=nvidia \  -e "DISPLAY" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \ anibali/pytorch python3 -c "import tkinter; tkinter.Tk().mainloop()"

十倍的时间差距:

 

转载于:https://www.cnblogs.com/aguncn/p/10966494.html

你可能感兴趣的文章
【Python 19】BMR计算器3.0(字符串分割与格式化输出)
查看>>
函数和模块的使用
查看>>
sqlx使用说明
查看>>
[转载]SQL Plus 一些使用技巧
查看>>
Dashboard集群
查看>>
TMS320F28335——IO控制/定时计操作
查看>>
MyBatis操作指南-与Spring集成(基于注解)
查看>>
23种设计模式的优点与缺点概况
查看>>
透明的iframe
查看>>
[Unity3D]Unity3D游戏开发之怪物AI
查看>>
玩转MySQL之Linux下的简单操作(服务启动与关闭、启动与关闭、查看版本)
查看>>
CTU 2017 J - Punching Power (二分图匹配)
查看>>
Cisco TrustSec(理解)
查看>>
Android Activity类讲解(一)
查看>>
Mysql中代替like模糊查询的一种方法
查看>>
C++实例讲解Binder通信
查看>>
AutoCAD如何方便截图放到Word文档,改成白底黑字
查看>>
Django 和 html
查看>>
算法与数据结构(一)
查看>>
【java】对象变成垃圾被垃圾回收器gc收回前执行的操作:Object类的protected void finalize() throws Throwable...
查看>>