theano使用GPU踩坑


1.安裝pygpu的部分

#使用豆瓣源or不使用,均安裝失敗
pip install pygpu  -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
#報錯:
Looking in indexes: http://pypi.douban.com/simple/
Collecting pygpu
  Could not find a version that satisfies the requirement pygpu (from versions: )
No matching distribution found for pygpu
#繼續嘗試使用conda,仍失敗
conda install -c conda-forge pygpu`
#報錯:
    Traceback (most recent call last):
      File "/data_d/public/miniconda2/lib/python2.7/site-packages/conda/exceptions.py", line 640, in conda_exception_handler
        return_value = func(*args, **kwargs)
      File "/data_d/public/miniconda2/lib/python2.7/site-packages/conda/cli/main.py", line 140, in _main
        exit_code = args.func(args, p)
      File "/data_d/public/miniconda2/lib/python2.7/site-packages/conda/cli/main_update.py", line 65, in execute
        install(args, parser, 'update')
      File "/data_d/public/miniconda2/lib/python2.7/site-packages/conda/cli/install.py", line 231, in install
        unknown=index_args['unknown'], prefix=prefix)
      File "/data_d/public/miniconda2/lib/python2.7/site-packages/conda/core/index.py", line 101, in get_index
        index = fetch_index(channel_priority_map, use_cache=use_cache)
      File "/data_d/public/miniconda2/lib/python2.7/site-packages/conda/core/index.py", line 120, in fetch_index
        repodatas = collect_all_repodata(use_cache, tasks)
      File "/data_d/public/miniconda2/lib/python2.7/site-packages/conda/core/repodata.py", line 75, in collect_all_repodata
        repodatas = _collect_repodatas_serial(use_cache, tasks)
      File "/data_d/public/miniconda2/lib/python2.7/site-packages/conda/core/repodata.py", line 485, in _collect_repodatas_serial
        for url, schan, pri in tasks]
      File "/data_d/public/miniconda2/lib/python2.7/site-packages/conda/core/repodata.py", line 115, in func
        res = f(*args, **kwargs)
      File "/data_d/public/miniconda2/lib/python2.7/site-packages/conda/core/repodata.py", line 473, in fetch_repodata
        with open(cache_path, 'w') as fo:
    IOError: [Errno 13] Permission denied: u'/data_d/public/miniconda2/pkgs/cache/6846611e.json'
#嘗試使用制定安裝版本
pip install pygpu==0.7.5
#仍報錯:
Collecting pygpu==0.7.5
  Could not find a version that satisfies the requirement pygpu==0.7.5 (from versions: )
No matching distribution found for pygpu==0.7.5

//已保證pip是最新的。

#嘗試將其拷貝到我的用戶目錄下
conda create -n my_root --clone="/data_d/public/miniconda2"
#激活環境
source activate my_root
#查看環境信息
 conda info -e
#激活環境后再次嘗試如下,仍舊失敗
conda install pygpu
#使用如下命令之后
sudo chown -R $USER:$USER ~/.conda/
#嘗試安裝,仍失敗
conda install pygpu

一些命令:

# 切換至對應環境安裝包
activate env_nameconda install pandas
#指定環境參數進行安裝
conda install -n env_name pandas 
# 查看已經安裝的包
conda list
# 指定查看某環境下安裝的package
conda list -n env_name
--------------------- 
作者:cathar 
來源:CSDN 
原文:https://blog.csdn.net/cathar/article/details/53729007 
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!
#嘗試更改文件所有者
chown  username 6846611e.json
#報錯:
chown: 正在更改'6846611e.json' 的所有者: 不允許的操作
#繼續嘗試sudo,成功
sudo chown  username 6846611e.json
#再次嘗試,失敗
conda install pygpu
 with open(cache_path, 'w') as fo:
    IOError: [Errno 13] Permission denied: u'/data_d/public/miniconda2/pkgs/cache/809318c1.json'

是否是所有相關的json文件所有者都要變成當前用戶?嘗試一下。

#使用此命令,將cache文件夾下所有json及q等文件的所有者變為當前用戶
sudo chown username cache -R

終於成功了!!!

The following NEW packages will be INSTALLED:

    libgcc-ng:   8.2.0-hdf63c60_1    
    libgpuarray: 0.7.6-h14c3975_0    
    mako:        1.0.9-py27_0        
    markupsafe:  1.1.1-py27h7b6447c_0
    pygpu:       0.7.6-py27h035aef0_0

Proceed ([y]/n)? y

libgpuarray-0. 100% |###################################################| Time: 0:00:01 223.06 kB/s
markupsafe-1.1 100% |###################################################| Time: 0:00:00 139.96 kB/s
mako-1.0.9-py2 100% |###################################################| Time: 0:00:00 176.48 kB/s
pygpu-0.7.6-py 100% |###################################################| Time: 0:00:01 428.93 kB/s
#python下import
>>> import pygpu
>>> pygpu.__version__
u'0.7.6'

>>> pygpu.__path__
['/data_d/old_home/home/username/.conda/envs/my_root/lib/python2.7/site-packages/pygpu']

對應的python版本是2.7,theno版本是1.0.

2.Theano使用GPU

#import theano報錯:
RuntimeError: 
Could not import 'mkl'.  If you are using conda, update the numpy
packages to the latest build otherwise, set MKL_THREADING_LAYER=GNU in
your environment for MKL 2018.

遂更新numpy

conda update numpy
#顯示如下:
The following packages will be UPDATED:

    mkl:            2017.0.3-0            https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free --> 2019.3-199           
    numpy:          1.13.1-py27_0         https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free --> 1.16.3-py27h7e9f1db_0

Proceed ([y]/n)? y

嘗試使用pip更新

pip install --upgrade theano

嘗試:

THEANO_FLAGS=mode=FAST_RUN,device=cuda,floatX=float32 python test_gpu.py
#輸出:
/.conda/envs/my_root/lib/python2.7/site-packages/theano/gpuarray/dnn.py:184: UserWarning: Your cuDNN version is more recent than Theano. If you encounter problems, try updating Theano or downgrading cuDNN to a version >= v5 and <= v7.
  warnings.warn("Your cuDNN version is more recent than "
Using cuDNN version 7201 on context None
Mapped name None to device cuda: GeForce GTX 1080 Ti (0000:03:00.0)#映射到了這個顯卡
[GpuElemwise{exp,no_inplace}(<GpuArrayType<None>(float32, vector)>), HostFromGpu(gpuarray)(GpuElemwise{exp,no_inplace}.0)]
Looping 1000 times took 0.221133 seconds
Result is [1.2317803 1.6187935 1.5227807 ... 2.2077181 2.2996776 1.623233 ]
Used the cpu
#最后居然是使用CPU

若不使用GPU:

python test_gpu.py
#輸出:
[Elemwise{exp,no_inplace}(<TensorType(float64, vector)>)]
Looping 1000 times took 31.611282 seconds
Result is [1.23178032 1.61879341 1.52278065 ... 2.20771815 2.29967753 1.62323285]
Used the cpu

//可見時間差距為143倍。。。

嘗試:

THEANO_FLAGS=mode=FAST_RUN,device=gpu1,floatX=float32 python test_gpu.py

報錯:

  File /.conda/envs/my_root/lib/python2.7/site-packages/theano/configdefaults.py", line 116, in filter
    'You are tring to use the old GPU back-end. '
ValueError: You are tring to use the old GPU back-end. It was removed from Theano. Use device=cuda* now. See https://github.com/Theano/Theano/wiki/Converting-to-the-new-gpu-back-end%28gpuarray%29 for more information.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM