20

DOUBLE your Google Colab RAM in 10 seconds using these 10 characters

 3 years ago
source link: https://mc.ai/double-your-google-colab-ram-in-10-seconds-using-these-10-characters/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
FbANZze.jpg!web

There is one catch: after the 25 GB upgrade, your current runtime’s state will be lost, including local files. You need to run your program again, from scratch. Perhaps upload files again, etc. So if you KNOW that you’ll certainly NEED that extra RAM, allocate it first, before finding out about it after it is too late.

So how do you allocate so much RAM? I found a few solutions online, but (1) they take around 60 seconds (2) they require multiple lines of code.

I decided to come up with an easier solution: a single, 10-character line of code that will do the trick, and do it very fast, in just 10 seconds. Here it is:

[1]*10**10

That’s it. That’s the code. How does it work? Python will attempt to create a list comprised of 10¹⁰=10,000,000,000 integers. However, such a list requires more than 12 GB. In fact, it takes about 80 GB of RAM to store this list. Hence, the session will crash and the upgrade will quickly be available. So: if you are sure that your program will need the double RAM, run [1]*10**10 in a scratch cell (Ctrl/⌘+Alt+N), accept the RAM upgrade, and that’s it. You’re done.

Hope you enjoyed the post! And now, to the coding challenge

And now for the CODING CHALLENGE!

Can you find a shorter piece of code that will use up all the RAM in 10 seconds? Post it in the comments!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK