How to Push Google Colab to its limits

I started using Google Colaboratory (Colab), a python notebook that comes with free computing resources, when taking a graduate Machine Learning course.
During the first or two months it was quite devastating, because a noticeable proportion to students had access to computing resources from their labs, or the department. Students who attempted to get higher results with free GPU saw and felt the discrepancy.
I was among them at first, but fortunately, there were tips and tricks passed on from former student, or shared between peers, and most people are willing to help. I have also developed some techniques on my own and contibute to the pool.
Eventually Colab became a more and more powerful tool in my hands, and I was able to get by. I was even lucky enough to get ranked as 1st place for days in several of our Kaggle competitions.
Know what GPU you are working on
You can do this by running !nvidia-smi
. As an example below, I am working with a Tesla K80.

At the time writing, Colab offers 4 types of GPUs, and they are listed below by general performance from high to low.
- V100
- T4
- P100
- K80
The GPU restarts on every session, and sessions and be restarted by clicking on the upper left tool bar at Runtime > Factory Reset Runtime.
Not all sessions are born equal
It was discovered that the probability of getting a better GPU and longer runtime is not fixed. From my experience and that shared by people around me, some accounts enjoy longer sessions up to 3 to 9 hours, while others get cut-off after reaching slightly above 1 hour.
By testing across different accounts, I found that the allowed runtime is most correlated with two factors.
1. Which Google account is using Colab
Looking across more than 20 Google accounts and over 100 runs, it happens that Google is treating each account with a different standard of how long it is allowed to use the service.
I did not find any reliable predictor for an account’s endurance. At first, it was tempting to assume that accounts that have been active and around for a while would have better endurance compared to freshly created entities, and educational accounts would also last longer than free Google accounts. Surprisingly, none of these hypothesis proved to be true, and I often see similar account profiles treated in vastly different styles.
Based on how unpredictable it could be, I would say that the best way to find out if an account is good to go, would be to get your hands dirty and just test for yourself. By comparing across different accounts, you should be able to decide on which account is the best choice for your deep learning project.
2. How often does the account use Colab
It also seems that Google applies a "cool down" policy: accounts that have seen more recent usage in Colab can usually train longer than accounts that are recently used abusively.
Note that with the previous point still holding true, the starting quota for using GPU before cool-down to every account is different. Some accounts gets banned right after the first several sessions, while others enjoy getting assigned with T4 GPU on default and can train up to 8 or 9 hours for many runs.
In short, if you run into a usage problem on Colab, consider changing the account of use and it might help.
Preserve training progress with a little coding
In the default setting, everything that happens in a sessions, including trained parameters or checkpoints are only stored temporarily on colab and would disappear after the session ends. Here are some measures to prevent the tragedy.
Mount your content on Google drive
On the left side of Colab, click on files > mount drive and follow the instructions to save or load files to your google drive.


Use %cd content/drive/MyDrive/the_name_of_folder
to move around directories in your drive.
With this done, all the files created during the session will be automatically saved to the account’s Google drive and does not vanish right after the session ends.
Training from account to account
It is possible to keep training on and on, simply by logging into different Google accounts on Colab, but mounting on the same account’s Google drive.
However, this is given that you are familiar with how to save training checkpoints, which from my perspective isn’t that easy for starters. I would recommend starting with the guide from Pytorch.
My favorite subscription: Colab Pro
Colab offers a subscription plan of $9.99 per month for faster GPU and longer runtime, which is usually a pretty good deal unless you run into problems.
In short, the account you choose to upgrade for subscription is crucial to the experience you will be getting.
I learned this the hard way. Upon hearing about the plan, I pulled out my card and got on immediately. Outrageously, after using it for less than 1 hour, my session was cut off and I couldn’t connect to the GPU.
After cooling down for a while, I can still use it, but I get cut off after using it for about 1 hour. (Compared to 3–9 hours in the free plan)
Plus I wasn’t even getting the best GPU. While typically assigned to T4, the default assignment on Colab Pro was P100.
That being said, I still wanted to train my neural network. I decided to subscribe to Pro again with a different account, and it turned out as a much better experience. Under that account I could train with the following benefits.
Train faster with V100
V100 is very good. Although it is hard to quantify how good, I can see it going 10 times faster than T4 on some of my NLP projects.
Fast is not only time saving but sometimes play a big role. There was one occasion that I had a deadline in 23 hours but it typically takes 24 hours to finish training. I was on the verge of giving up, but in the last 10 hours I got on V100 and finished on time.
Train overnight
It was only after getting on Pro with the right account that I was able to have 8 hours sleep while the training was going on.
Train under unstable internet
This is also hard to quantify, but when my internet gets cut off, the training still continues, which under my impression is different from what we get in the free plan.
Open multiple sessions
In the free version you can only train one notebook at a time, while on paid plan you can sometimes train up to three tabs. This again does not apply to every account, and in my opinion levels up the odds of getting banned from GPU. Therefore, I usually do one or two tabs and it works pretty well.
Corgi & Kitty

Finally, Colab comes with this cute feature that does nothing but keep you in a happy mood to work longer, which I would regards as an advantage. You can find it in Settings> Miscellaneous and click on Corgi mode/Kitty mode.
Final Words
Colab made my journey towards Data Science fun and possible, and I hope you will enjoy yours as well.
The Medium membership made it possible for me to learn enough and write for Towards Data Science. Sign up with my personal link, then comment below, and I will send you a pdf that shares my full journey.