Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Colab: "Unable to connect to the runtime" after uploading Pytorch model from local

I am using a simple (not necessarily efficient) method for Pytorch model saving.

import torch
from google.colab import files

torch.save(model, filename) # save a trained model on the VM
files.download(filename) # download the model to local

best_model = files.upload() # select the model just downloaded
best_model[filename] # access the model

Colab disconnects during execution of the last line, and hitting RECONNECT tab always shows ALLOCATING -> CONNECTING (fails, with "unable to connect to the runtime" message in the left bottom corner) -> RECONNECT. At the same time, executing any one of the cells gives Error message "Failed to execute cell, Could not send execute message to runtime: [object CloseEvent]"

I know it is related to the last line, because I can successfully connect with my other google accounts which doesn't execute that.

Why does it happen? It seems the google accounts which have executed the last line can no longer connect to the runtime.

Edit:

One night later, I can reconnect with the google account after session expiration. I just attempted the approach in the comment, and found that just files.upload() the Pytorch model would lead to the problem. Once the upload completes, Colab disconnects.

like image 615
Francis Avatar asked Jun 04 '18 07:06

Francis


People also ask

How do I reconnect to a runtime on Google Colab?

In Colaboratory, click the "Connect" button and select "Connect to local runtime...". Enter the URL from the previous step in the dialog that appears and click the "Connect" button. After this, you should now be connected to your local runtime.

Can Google colab work with local files?

Since a Colab notebook is hosted on Google's cloud servers, there's no direct access to files on your local drive (unlike a notebook hosted on your machine) or any other environment by default. However, Colab provides various options to connect to almost any data source you can imagine.

How do I import dataset from local machine to Google Colab?

Scroll down to Open files from Google Drive and click on INSERT. Go to the URL link on your browser to grant access to Colab, copy the authorization code and paste it into the space given in the notebook. You can now access all your datasets on your Drive directly on Colab.

How does colab read file from local path?

1) From Github (Files < 25MB) Click on the dataset in your repository, then click on View Raw. Copy the link to the raw dataset and store it as a string variable called url in Colab as shown below (a cleaner method but it's not necessary). The last step is to load the url into Pandas read_csv to get the dataframe.


1 Answers

Try disabling your ad-blocker. Worked for me

like image 70
Alex Avatar answered Oct 16 '22 09:10

Alex