machine-learninggputheanogoogle-colaboratory

Theano support GPU is not working on google Colab


I'm trying to train a model based on the Theano library. As my computer havn't enough memory to train this model, I need to do it in Google Colab. But I can't activate the GPU support of Theano.

This is how I installed Theano and Lasagne

!pip install --upgrade https://github.com/Theano/Theano/archive/master.zip
!pip install --upgrade https://github.com/Lasagne/Lasagne/archive/master.zip

And here is the way that I try to acctivate the GPU support

import os
os.environ["THEANO_FLAGS"] = "mode=FAST_RUN,device=cuda,floatX=float32"
import theano
print(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: None

cuda

I tried to upgrade pygpu using anaconda but anaconda is not installed in Google Collab.

Thanks in advence for your help.


Solution

    1. Install condacolab package:
    !pip install -q condacolab
    
    import condacolab
    condacolab.install()
    
    1. After auto restarting kernel do importing condacolab:
    import condacolab
    condacolab.check()
    
    1. Install theano and pygpu packages:
    !mamba install -y theano pygpu
    
    1. Configurate and import theano:
    import os
    os.environ["THEANO_FLAGS"] = "device=cuda,floatX=float32"
    
    import theano
    print(theano.config.__getattribute__('device'))
    

    To test Theano with GPU use the code from Theano docs.