How to Accelerate Your Python Deep Learning with Cloud GPU?

Overloaded

This afternoon, I trained a 3-layers neural network as a regression model to predict the house price in Boston district with Python and Keras.

The example case came from the book "Deep Learning with Python".

There were 2 big loop during the running procedure.

The first one went through the data for 100 times (epochs), while the second one ran 500 epochs.

My poor laptop was apparently overladed in such a hot summer weather and the fan was roaring.

It seems the laptop is not the best choice to train deep neural models.

It would be so great if I have got a GPU.

Suddenly, it occurs to me that it is not necessary to train the model locally. It's a cloud computing age!

How about to run the code on cloud GPU to save my laptop's effort?

Encounter

It reminds me a video clip post by Siraj Raval on Youtube recently.

He recommended cloud GPU platform, namely Floydhub, in this video.

Actually, I once tried AWS GPU product in a online deep learning course. The instructor collaborated with AWS and provided all the students with AWS Computing power to solve the exercise as well as the homework.

However, it was not a very good experience, since he had to make a long video to show the students how to configure the AWS instance.

Indeed, comparing with some other solutions, the AWS was simple enough, yet still not so simple for the new newbies.

The website FloydHub, on the other hand, solved the pain point well.

Firstly, it is wrapper over AWS, and filtered out a lot of complex operations.

Secondly, FloydHub is batteries-included with a lot of main stream machine learning frameworks.

Besides, it is well-documented and friendly to the new users.

The slogan is:

Focus on what matters. Let FloydHub handle the grunt work.

Honestly, I like all the things designed for the lazy folks.

So I registered immediately and validated my email.

Then I got 2 hours GPU running time for free!

To spend the precious GPU running time on something import, I read the Quick Start Tutorial eagerly.

Several minutes later, I feel confident to use it.

Trial

I created a new job from personal control panel on FloydHub and named it "try-keras-boston-house-regression".

Then I exported a Python Script file from my local Jupyter Notebook.

I created a new directory and copied the script file into it.

To save the Evaluation Metrics of the training and evaluation process, I added 3 lines of code in the end of the Python Script.

import pickle

with open('data.pickle', 'wb') as f:
    pickle.dump([all_scores, all_mae_histories], f)

In this way, we can save all_scores and all_mae_histories data into a file named data.pickle with the Pickle Module in Python.

Then let's dive into the shell and navigate to this new created folder with cd command and execute the following command:

pip install floyd-cli

The command line interface of FloydHub is ready to use.

We can login the FloydHub account with:

floyd login

Then input your FloydHub username and password.

When it's ready, run:

floyd init try-keras-boston-house-regression

Please notice the last parameter should be identical to the title you input just now when created the new job from control panel.

Now we can run the Python script with following command:

floyd run --gpu --env tensorflow-1.8 "python 03-house-price.py"

In this command, --gpu means that we ask the FloydHub to run the script in a GPU environment instead of a default CPU one, and --env tensorflow-1.8 means it will use Tensorflow version 1.8, and the Keras version is 2.1.6 accordingly.

If you want to use other framework or choose a different version, please refer to this link.

In response, we get the following messages from FloydHub.

It's all set.

Yes, so easy. And your learning job is already running in the cloud.

Results

While the job was running, I drank some tea, read several pages of books and browsed some news on Social Media with my phone.

When the running job is done, it will terminate the environment and will not charge you any extra GPU running time. So you don't need to keep an eye on it.

When I came back to my computer, the job's already fininished.

GPU memory was busy during the whole procedure, as the Utilization was above 90% most of the time.

The GPU, on the other hand, was not busy at all.

Maybe my neural network was too simple.

Scrolling down the page, we can see the logs.

The output was similar to the one when you train the model locally. Besides, it showed you extra information about GPU resource allocation.

To see the saved file, you can open the Files tag.

The pickle file's already there.

FloydHub helped us with all the hard computing job, and my laptop is much cooler this time.

You can download the pickle file, and put it back into the original working directory.

Let's go back to the Jupyter Lab page on the laptop and open a new ipynb file.

The following code can check the running results.

import pickle
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline

with open('data.pickle', 'rb') as f:
    [all_scores, all_mae_histories] = pickle.load(f)

num_epochs = 500
average_mae_history = [
    np.mean([x[i] for x in all_mae_histories]) for i in range(num_epochs)
]

plt.plot(range(1, len(average_mae_history) + 1), average_mae_history)
plt.xlabel('Epochs')
plt.ylabel('Validation MAE')
plt.show()

Please notice these codes will only do some drawings.

Here is the result:

The visualization result is identical to the textbook which shows the code ran smoothly on the Cloud GPU environment.

You can check the remaining GPU running time easily.

There's still more than 1 hour to play with. Great!

Workspace

Just now, I showed you how to run FloydHub in Command Line Interface. If you are familiar with bash command, it will be great.

However, for the new users who do not want to use the shell command, I recommend you to try an easier way.

Click the Workspace tab.

You will see two existing Workspace examples.

Try to open the first one and check it out.

Hit the green Resume button on top right, the system will try to provide us the environment.

When it's done, you'll see the familiar Jupyter lab interface.

Open the dog-breed-classification.ipynb from the left side file list.

It's a complete example to separate different dog breeds.

Hit Run -> Restart Kernel and Run All Cells from the menu.

You'll figure out there is no significant difference with running the code locally.

However, this time, you are using GPU!

What if you want to set up a new workspace yourself?

You can go back to the Project page .

For each project, you can create new workspace with the Create Workspace button.

Floydhub will ask you how to create the new workspace.

Let's select Start from scratch on the left side and choose the environment.

Let's change the default one into Tensorflow 1.9 and GPU.

Hit the Create Workspace.

Then click on the link try-keras-boston-house-regression workspace.

A Jupyter Lab interface is ready.

You don't need to install Tensorflow or configure the GPU yourself.

Even better, you don't need to run bash commands this time. Just input the Python code, and use Keras and Tensorflow freely.

That's cool!

Start your own Deep Learning Journey with Floydhub.

Summary

You don't need to buy your own expensive deep learning device if you just need GPU computing power occasionally. It will be a waste, and you'll not get a good price when you want to sell it to make an upgrade. In this case, Cloud GPU is a better choice.

Have you ever used any other Cloud GPUs? What are the pros and cons comparing with Floydhub?

I would like to have your feedbacks.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末烙肺,一起剝皮案震驚了整個濱河市竣贪,隨后出現(xiàn)的幾起案子唆涝,更是在濱河造成了極大的恐慌榕暇,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,277評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機亏镰,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評論 3 393
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來拯爽,“玉大人索抓,你說我怎么就攤上這事√号冢” “怎么了逼肯?”我有些...
    開封第一講書人閱讀 163,624評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長桃煎。 經(jīng)常有香客問我篮幢,道長,這世上最難降的妖魔是什么为迈? 我笑而不...
    開封第一講書人閱讀 58,356評論 1 293
  • 正文 為了忘掉前任三椿,我火速辦了婚禮缺菌,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘搜锰。我一直安慰自己伴郁,他們只是感情好,可當我...
    茶點故事閱讀 67,402評論 6 392
  • 文/花漫 我一把揭開白布蛋叼。 她就那樣靜靜地躺著焊傅,像睡著了一般。 火紅的嫁衣襯著肌膚如雪狈涮。 梳的紋絲不亂的頭發(fā)上狐胎,一...
    開封第一講書人閱讀 51,292評論 1 301
  • 那天,我揣著相機與錄音歌馍,去河邊找鬼握巢。 笑死,一個胖子當著我的面吹牛骆姐,可吹牛的內(nèi)容都是我干的镜粤。 我是一名探鬼主播,決...
    沈念sama閱讀 40,135評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼玻褪,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了公荧?” 一聲冷哼從身側(cè)響起带射,我...
    開封第一講書人閱讀 38,992評論 0 275
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎循狰,沒想到半個月后窟社,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,429評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡绪钥,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,636評論 3 334
  • 正文 我和宋清朗相戀三年灿里,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片程腹。...
    茶點故事閱讀 39,785評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡匣吊,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出寸潦,到底是詐尸還是另有隱情色鸳,我是刑警寧澤,帶...
    沈念sama閱讀 35,492評論 5 345
  • 正文 年R本政府宣布见转,位于F島的核電站命雀,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏斩箫。R本人自食惡果不足惜吏砂,卻給世界環(huán)境...
    茶點故事閱讀 41,092評論 3 328
  • 文/蒙蒙 一撵儿、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧狐血,春花似錦统倒、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至报亩,卻和暖如春浴鸿,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背弦追。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評論 1 269
  • 我被黑心中介騙來泰國打工岳链, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人劲件。 一個月前我還...
    沈念sama閱讀 47,891評論 2 370
  • 正文 我出身青樓掸哑,卻偏偏與公主長得像,于是被迫代替她去往敵國和親零远。 傳聞我的和親對象是個殘疾皇子苗分,可洞房花燭夜當晚...
    茶點故事閱讀 44,713評論 2 354