【发布时间】:2016-01-26 01:19:55
【问题描述】:
我有一个名为simple_theano_tasks的Celery task:
@app.task(bind=True, queue='test')
def simple_theano_tasks(self):
import theano, numpy as np
my_array = np.zeros((0,), dtype=theano.config.floatX)
shared = theano.shared(my_array, name='my_variable', borrow=True)
print 'Done. Shared value is {}'.format(shared.get_value())
当 THEANO 被配置以使用 CPU 时,一切都按预期工作(没有错误):
$ THEANO_FLAGS=device=cpu celery -A my_project worker -c1 -l info -Q test
[INFO/MainProcess] 收到任务:my_project.tasks.simple_theano_tasks[xxxx]
[警告/Worker-1] 完成。共享值为 []
[INFO/MainProcess] 任务 my_project.tasks.simple_theano_tasks[xxxx] 0.00407959899985s 成功
现在,当我在启用 GPU 的情况下执行完全相同的操作时,Theano(或 CUDA)会引发错误:
$ THEANO_FLAGS=device=gpu celery -A my_project worker -c1 -l info -Q test
...
使用 gpu 设备 0:GeForce GTX 670M(启用 CNMeM)
...
[INFO/MainProcess] 收到任务:my_project.tasks.simple_theano_tasks[xxx]
[ERROR/MainProcess] 任务 my_project.tasks.simple_theano_tasks[xxx] 引发意外:RuntimeError("Cuda error 'initialization error' while copying %lli data element to device memory",)
Traceback(最近一次调用最后一次):
文件“/.../local/lib/python2.7/site-packages/celery/app/trace.py”,第 240 行,在 trace_task R = retval = fun(*args, **kwargs)
protected_call 中的文件“/.../local/lib/python2.7/site-packages/celery/app/trace.py”,第 438 行 return self.run(*args, **kwargs)
文件“/.../my_project/tasks.py”,第 362 行,在 simple_theano_tasks shared = theano.shared(my_array, name='my_variable', borrow=True)
文件“/.../local/lib/python2.7/site-packages/theano/compile/sharedvalue.py”,第 247 行,共享 allow_downcast=allow_downcast, **kwargs)
文件“/.../local/lib/python2.7/site-packages/theano/sandbox/cuda/var.py”,第 229 行,在 float32_shared_constructor deviceval = type_support_filter(value, type.broadcastable, False, None) RuntimeError:将 %lli 数据元素复制到设备内存时出现 Cuda 错误“初始化错误”
最后,当我在 Python shell 中运行完全相同的代码时,我没有错误:
$ THEANO_FLAGS=device=gpu python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import theano, numpy as np
Using gpu device 0: GeForce GTX 670M (CNMeM is enabled)
>>> my_array = np.zeros((0,), dtype=theano.config.floatX)
>>> shared = theano.shared(my_array, name='my_variable', borrow=True)
>>> print 'Done. Shared value is {}'.format(shared.get_value())
Done. Shared value is []
有没有人知道:
- 为什么 theano 在 Celery worker 中的行为会有所不同?
- 如何解决这个问题?
一些额外的上下文:
[全局]
floatX=float32
设备=gpu
[模式]=FAST_RUN
[nvcc]
fastmath=真
[库]
cnmem=0.1
[cuda]
root=/usr/local/cuda
【问题讨论】:
-
@asksol 你有什么想法吗? BR