Theano无法导入pygpu / cudnn(macOS,CUDA 8)

时间:2017-05-13 08:40:54

标签: python theano theano-cuda

问题是我无法导入theano。我知道有关于同一问题的其他几个问题,但它们都没有对我有用,通常它们是旧版本或不同操作系统。我一直试图解决这个问题几天,我已经尝试了所有可以找到的修复和技巧,所以我无法想出任何其他的东西来尝试,而不是在这里问。

如果我在没有sudo的情况下尝试python3 -c "import theano",我会得到以下内容:

ERROR (theano.gpuarray): Could not initialize pygpu, support disabled
Traceback (most recent call last):
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gpuarray/__init__.py", line 164, in <module>
    use(config.device)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gpuarray/__init__.py", line 151, in use
    init_dev(device)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gpuarray/__init__.py", line 68, in init_dev
    context.cudnn_handle = dnn._make_handle(context)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gpuarray/dnn.py", line 86, in _make_handle
    raise RuntimeError("error creating cudnn handle")
RuntimeError: error creating cudnn handle

sudo我得到了

ERROR (theano.gpuarray): Could not initialize pygpu, support disabled
Traceback (most recent call last):
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gpuarray/__init__.py", line 164, in <module>
    use(config.device)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gpuarray/__init__.py", line 151, in use
    init_dev(device)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gpuarray/__init__.py", line 66, in init_dev
    avail = dnn.dnn_available(name)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gpuarray/dnn.py", line 175, in dnn_available
    if not dnn_present():
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gpuarray/dnn.py", line 158, in dnn_present
    dnn_present.avail, dnn_present.msg = _dnn_check_version()
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gpuarray/dnn.py", line 131, in _dnn_check_version
    v = version()
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gpuarray/dnn.py", line 339, in version
    profile=False)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/compile/function.py", line 326, in function
    output_keys=output_keys)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/compile/pfunc.py", line 486, in pfunc
    output_keys=output_keys)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/compile/function_module.py", line 1795, in orig_function
    defaults)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/compile/function_module.py", line 1661, in create
    input_storage=input_storage_lists, storage_map=storage_map)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gof/link.py", line 699, in make_thunk
    storage_map=storage_map)[:3]
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gof/vm.py", line 1047, in make_all
    impl=impl))
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gof/op.py", line 935, in make_thunk
    no_recycling)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gof/op.py", line 839, in make_c_thunk
    output_storage=node_output_storage)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gof/cc.py", line 1190, in make_thunk
    keep_lock=keep_lock)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gof/cc.py", line 1131, in __compile__
    keep_lock=keep_lock)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gof/cc.py", line 1586, in cthunk_factory
    key=key, lnk=self, keep_lock=keep_lock)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gof/cmodule.py", line 1159, in module_from_key
    module = lnk.compile_cmodule(location)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gof/cc.py", line 1489, in compile_cmodule
    preargs=preargs)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gof/cmodule.py", line 2325, in compile_str
    return dlimport(lib_filename)
  File "/Users/np/miniconda3/lib/python3.6/site-packages/theano/gof/cmodule.py", line 302, in dlimport
    rval = __import__(module_name, {}, {}, [module_name])
ImportError: dlopen(/Users/np/.theano/compiledir_Darwin-16.5.0-x86_64-i386-64bit-i386-3.6.1-64/tmp3r02thlc/m3d1cf20adb1014f04986e6a344a55bde.so, 2): Library not loaded: @rpath/libcudnn.6.dylib
  Referenced from: /Users/np/.theano/compiledir_Darwin-16.5.0-x86_64-i386-64bit-i386-3.6.1-64/tmp3r02thlc/m3d1cf20adb1014f04986e6a344a55bde.so
  Reason: image not found

我知道这是动态链接的问题,但我无法弄清楚它为什么不起作用。

我尝试了以下内容:

  • 已禁用SIP
  • 现在重新安装CUDA和cudnn大约10次
    • cudnn文件同时包含/Developer/NVIDIA/CUDA-8.0/lib/usr/local/cuda/lib
  • 现在重新安装了python,conda,theano,pygpu大约10次
  • 从头开始编译libgpuarray
  • 重新启动几次以确保它不是那个
  • 已执行update_dyld_shared_cache以查看是否为缓存问题
  • 尝试将libcudnn.6.dylib与install_name_tool链接到pygpu .so但是没有做任何事情

以下是来自.zshrc的路径:

export CUDA_HOME=/usr/local/cuda
export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:/usr/local/cuda/extras/CUPTI/lib
export LD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
export PATH=$CUDA_HOME/bi:$DYLD_LIBRARY_PATH:$PATH

.theanorc

[global]
floatX = float32
device = cuda
force_device = True
allow_gc = False
optimizer_including=cudnn

[cuda]
root = /usr/local/cuda

[dnn]
enabled = True
include_path=/usr/local/cuda/include
library_path=/usr/local/cuda/lib

版本号:

  • macOS 10.12.4
  • CUDA 8.0和cudnn 6.0
  • Python 3.6.1
  • Theano 0.9.0
  • libgpuarray 0.6.4
  • pygpu 0.6.4

1 个答案:

答案 0 :(得分:1)

我终于能够通过将libcudnn *文件移动到/usr/lib来解决这个问题。我完全不知道为什么pygpu无法使用/usr/local/cuda/lib。没有sudo,我仍然会收到RuntimeError: error creating cudnn handle错误,但现在它至少可以使用sudo。

虽然现在我和Segmentation fault: 11打架,但我猜这是一个不同的问题。 Theano绝对是......