Search code examples
gitgoogle-colaboratory

How to preserve session data when switching from cpu to gpu in google colab?


When we switch from CPU to GPU hardware in google colab, we loose all the data in the session, that means, we need to upload all the data again to the new GPU session which is very time-consuming process, as we also need to re-run the data processing.

Is there a way or any workaround/hack to change the CPU session to that of GPU at the same time preserving our session data ?

I read somewhere we can push it to git and then clone the data in a new GPU session. I know how to clone the git data but don't know how to push the google colab session data to git. Any help in this regard would be highly appreciated.


Solution

  • What I do is to upload my files to google drive and mount it, like this:

    from google.colab import drive
    drive.mount('/gdrive')
    
    %cd /gdrive/MyDrive/somefolder/anotherfolder/
    
    

    Then I can use the files on /somefolder/anotherfolder/ whether they are python files to import them or data