I bought a gaming laptop and Google provides a service called Colab, So now I can learn how to use deep learning.

Several days ago, I bought a gaming laptop to do some deep learning work. My girlfriend is very happy because now she can use the new gaming laptop play the Playerunknown battleground. And I’m happy because this laptop is much faster than my Mac pro several times when you are doing deep learning tasks.

I update all the codes from tensorflow and play the codes in the tutorials one by one. And I found out now Google provides a service called Colab. Our codes can run on Google’ VM with a GPU google provides.

But a lot of people find out their codes can’t run on Colab because the system often breaks by the error of out of memory. Turns out, Google may share memory and  GPUs between your different sessions. There are some codes can help understand how much memory is free for you.

Normally Google provides a Tesla K80 with 11GB memory, so when you get lucky you may will get this information:

And sometimes your memory almost  all is used, like this:

When the bad thing is happening, you can use command kill to free memory first:

You may need to wait for several minutes, it will kill your current runtime and after you connect to a new runtime, you may be lucky to have full memory unused.

When I try the example DCGAN from tensorflow tutorials, My Mac Pro  (3.7 GHz Quad-Core Intel Xeon E5, Two AMD FirePro D300 2048 MB) needs 255 seconds to finish one epoch.

Google Colab (Nvidia Tesla K80 11GB) needs 30 seconds to finish one epoch. 

My gaming laptop (Nvidia GeForce 1050 ti 4GB) needs 34 seconds to finish one epoch.

So, Google Colab is very useful, but when you run some tasks which took too long, Colab may disconnect and you may never connect to the original session, so you may need run it again and again. So I am happy that I bought my own gaming laptop. 

See also: https://stackoverflow.com/questions/48750199/google-colaboratory-misleading-information-about-its-gpu-only-5-ram-available

Why Google built TPU instead invent some superpower GPU?

Deep learning researchers always think training is the core problem. Because they always lack funds to purchase the quickest machines. But Google doesn’t worry this, they just have tons of powerful machines, find resources to train a good model isn’t very hard for Google.

Win some deep learning contests isn’t the goal of Google, it is just their PR tricks. Google want to provide AI cloud services. So they kept releasing their well-trained models, Inception-v3, Word2vec, etc. Most of the customers will use API from Google’s well-trained models, like Cloud Natural Language API, Cloud Speech API, Cloud Translation API, Cloud Vision API, Cloud Video Intelligence API. Some of them will want to use models that provide by Google or other companies, or just do some fine tune. And only a little of them will want to train their model all from the beginning.

So, Google cares about service more than training, so they build TPU to speed up service, to reduce service latency.

How to install Theano on Mac OS X EI Capitan with OpenCL support

I have two Mac, a Mac pro and Macbook pro. They both use AMD display card, so I can’t use CUDA speed up machine learning, so I want to use OpenCL.

First install some requirements:

Then make install environment ( use virtualenv can make everything easy ):

Install Theano:

Then you can use this demo code ( test.py ) to test your Theano:

This test will show something like this:

It just do some math 1000 time, took 1.492254 seconds, and use cpu.

Then we must install libgpuarray to make Theano support OpenCL:

Then we can use THEANO_FLAGS to set use OpenCL device.

Use OpenCL & Cpu in my Mac pro:

Note: Code showed “Used the gnu”, but as you can see, this was using CPU.

Use OpenCL & GPU 1 in My Mac pro:

Finally, we can use OpenCL and GPU.


My Mac pro

屏幕截图 2016-04-01 15.09.25

My Macbook pro

屏幕截图 2016-04-01 15.09.32

Note: Now we can use Theano and OpenCL. But I was very sad, when I found out Theano is using CUNN, so when you use Theano to do Neural Network, we still need CUDA support. Just for now I don’t know how to solve this problem.

Chinese version of this article.