1

I am running a simple deep learning model on Google's colab, but it's running slower than my MacBook Air with no GPU.

I read this question and found out it's a problem because of dataset importing over the internet, but I am unable to figure out how to speed up this process.

My model can be found here. Any idea of how I can make the epoch faster?

My local machine takes 0.5-0.6 seconds per epoch and google-colabs takes 3-4 seconds

Phydeaux
  • 2,795
  • 3
  • 17
  • 35
Mansi Shukla
  • 377
  • 3
  • 23
  • 2
    Did you enable GPU? – Amir Jan 21 '19 at 20:30
  • 1
    Yes @Amir problem is with how we are importing dataset as google drive's i/o is not that efficient I think – Mansi Shukla Jan 21 '19 at 20:55
  • It is not very likely that data import is the problem. In your code, you import the data from the `.csv` file. This is one time operation, and once data is loaded you do not have other I/O, so it can not possibly affect you during training. Yet, you say that each epoch is taking lot's of time. – igrinis Jan 24 '19 at 07:17
  • Hmm, then I guess it's the problem of google colabs itself because on my macbook air it's running way more fast. And on colabs I was running with GPU. So I guess no use of GPU here @igrinis – Mansi Shukla Jan 24 '19 at 13:11
  • 4
    Can you share the data set or a suitable replacement in a notebook that replicates your performance issue? That will simplify diagnosis and help us to offer concrete suggestions. – Bob Smith Jan 24 '19 at 18:46
  • How big is your datasete? – anand_v.singh Jan 31 '19 at 05:11
  • @MansiShukla Would you mind sharing if the answer by anand_v.singh solved your problem - more precisely, did increasing the batch size decrease the training time? – NeStack Aug 27 '19 at 12:02

1 Answers1

2

Is GPU always faster than CPU? No, why? because the speed optimization by a GPU depends on a few factors,

  1. How much part of your code runs/executes in parallel, i.e how much part of your code creates threads that run parallel, this is automatically taken care by Keras and should not be a problem in your scenario.

  2. Time Spent sending the data between CPU and GPU, this is where many times people falter, it is assumed that GPU will always outperform CPU, but if data being passed is too small, the time it takes to perform the computation (No of computation steps required) are lesser than breaking the data/processes into thread, executing them in GPU and then recombining them back again on the CPU.

The second scenario looks probable in your case since you have used a batch_size of 5. classifier=KerasClassifier(build_fn=build_classifier,epochs=100,batch_size=5), If your dataset is big enough, Increasing the batch_size will increase the performance of GPU over CPU.

Other than that you have used a fairly simple model and as @igrinis pointed out that data is loaded only once from drive to memory so the problem in all theory should not be loading time because the data is on drive.

anand_v.singh
  • 2,768
  • 1
  • 16
  • 35