【问题标题】:theanorc for multiple GPUs用于多个 GPU 的 theanorc
【发布时间】:2016-11-25 05:15:26
【问题描述】:

我有一台配备 4 个 GPU 的 aws 机器:

00:03.0 VGA compatible controller: NVIDIA Corporation GK104GL [GRID K520] (rev a1)
00:04.0 VGA compatible controller: NVIDIA Corporation GK104GL [GRID K520] (rev a1)
00:05.0 VGA compatible controller: NVIDIA Corporation GK104GL [GRID K520] (rev a1)
00:06.0 VGA compatible controller: NVIDIA Corporation GK104GL [GRID K520] (rev a1)

我的 theanorc 文件如下所示:

[global]
floatX = float32
device = gpu0

[lib]
cnmem = 1

当我打开一个 jupyter notebook 并导入 theano 时,我得到以下信息(我假设它只使用一个 GPU):

Using Theano backend.
Using gpu device 0: GRID K520 (CNMeM is enabled with initial size: 95.0% of memory, cuDNN 5105)
/home/sabeywardana/anaconda3/lib/python3.5/site-packages/theano/sandbox/cuda/__init__.py:600: UserWarning: Your cuDNN version is more recent than the one Theano officially supports. If you see any problems, try updating Theano or downgrading cuDNN to version 5.

但是,如果我同时在同一台机器上打开第二个 jupyter 笔记本。然后我得到错误:

ERROR (theano.sandbox.cuda): ERROR: Not using GPU. Initialisation of device 0 failed:
initCnmem: cnmemInit call failed! Reason=CNMEM_STATUS_OUT_OF_MEMORY. numdev=1

ERROR (theano.sandbox.cuda): ERROR: Not using GPU. Initialisation of device gpu failed:
initCnmem: cnmemInit call failed! Reason=CNMEM_STATUS_OUT_OF_MEMORY. numdev=1

如果我手动更改我的 .theanorc 以使用 gpu1,那么第二个 jupyter 笔记本工作正常。 所以问题是:有没有办法配置 .theanorc 以获得可用的 GPU?

【问题讨论】:

  • 我不确定。虽然努力。尝试仅用 gpu 替换 gpu0。让我知道它是否有效。
  • 试过了,gpu? 没有运气。

标签: theano theano-cuda


【解决方案1】:

您可以使用device=gpu,它将选择第一个可用的 GPU。 但是,在您的情况下,GPU 0 仍将被视为“可用”(它没有多少内存剩余,但仍然可以执行)。您可以使用nvidia-smi 将 GPU 的计算模式设置为“独占线程”,以便第一个笔记本“阻塞”第一个 GPU 以独占使用,而第二个笔记本将使用另一个。

另一个选项是在导入 theano 之前从笔记本内部更改 THEANO_FLAGS 环境变量。比如:

import os

os.environ['THEANO_FLAGS'] = os.environ.get('THEANO_FLAGS', '') + ',' + 'device=gpu1'

import theano

【讨论】:

  • 我认为与其从笔记本内部更改 env 变量,不如让他通过 $THEANO_FLAGS=device=gpuN jupyter notebook 启动笔记本。
【解决方案2】:

导入theano后无法更改gpu设备。

也许你可以试试这个-

import os
os.system("THEANO_FLAGS='device=gpu0' python script_1.py")
os.system("THEANO_FLAGS='device=gpu1' python script_2.py")
os.system("THEANO_FLAGS='device=gpu1' python script_3.py")
os.system("THEANO_FLAGS='device=gpu1' python script_4.py")

如果您想从笔记本内部执行此操作(更多程序化),您可以使用以下 sn-p :-

import theano.sandbox.cuda
theano.sandbox.cuda.use("gpu0")

将此粘贴​​到每个笔记本并更改 gpu id。它会起作用的。

【讨论】:

    猜你喜欢
    • 2012-06-22
    • 2017-06-22
    • 2017-12-15
    • 1970-01-01
    • 2021-12-27
    • 2017-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多