我在尝试使用Theano库训练一个模型。由于我的电脑内存不足以训练这个模型,我需要在Google Colab上进行操作。但我无法启用Theano的GPU支持。
这是我安装Theano和Lasagne的方式
!pip install --upgrade https://github.com/Theano/Theano/archive/master.zip!pip install --upgrade https://github.com/Lasagne/Lasagne/archive/master.zip
以下是我尝试启用GPU支持的方式
import osos.environ["THEANO_FLAGS"] = "mode=FAST_RUN,device=cuda,floatX=float32"import theanoprint(theano.config.__getattribute__('device'))
ERROR (theano.gpuarray): pygpu was configured but could not be imported or is too old (version 0.7 or higher required)NoneType: Nonecuda
我尝试通过Anaconda升级pygpu,但Google Colab上没有安装Anaconda。
提前感谢您的帮助。
回答:
- 安装
condacolab
包:
!pip install -q condacolabimport condacolabcondacolab.install()
- 自动重启内核后导入
condacolab
:
import condacolabcondacolab.check()
- 安装
theano
和pygpu
包:
!mamba install -y theano pygpu
- 配置并导入
theano
:
import osos.environ["THEANO_FLAGS"] = "device=cuda,floatX=float32"import theanoprint(theano.config.__getattribute__('device'))
要测试Theano的GPU使用,请参考Theano文档中的代码。