如何更改theano使用的设备

时间:2015-05-12 07:58:11

标签: python theano

我尝试更改基于theano的程序中使用的设备。

from theano import config
config.device = "gpu1"

但是我收到了错误

Exception: Can't change the value of this config parameter after initialization!

我想知道在代码中将gpu更改为gpu1的最佳方法是什么?

由于

3 个答案:

答案 0 :(得分:8)

在同一进程中运行的代码中无法更改此值。您可以做的最好的事情是拥有一个“父”进程,例如,改变THEANO_FLAGS环境变量并生成子进程。但是,产卵方法将决定孩子们在哪个环境中运作。

另请注意,无法通过更改维护进程内存的方式执行此操作。您无法开始在CPU上运行,使用存储在内存中的值执行某些操作然后更改为在GPU上运行并继续使用早期(CPU)工作阶段仍在内存中的值运行。必须关闭并重新启动该过程才能更改要应用的设备。

只要您import theano设备已修复且无法在导入过程中进行更改。

答案 1 :(得分:7)

另一种对我有用的可能性是在导入theano之前在过程中设置环境变量:

SQL> select  id, t1.name as name_t1, t2.name as name_t2
  2  from myTable t1
  3    inner join myTable t2 using(id)
  4  where t1.name != t2.name
  5    and t1.code = '100'
  6    and t2.code = '999';

  ID NAME_T1    NAME_T2
---- ---------- ----------
   2 B          C

答案 2 :(得分:0)

删除"设备"在.theanorc中配置,然后在你的代码中:

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

它对我有用。

https://groups.google.com/forum/#!msg/theano-users/woPgxXCEMB4/l654PPpd5joJ