How to enable GPU and stop kicking off from colab when using SSH from VScode

Viewed 583

I have been following this thread to remote in through VSCode using SSH and ngrok Configuring Google Colab Like A Pro. It works pretty good. But I have encountered two problems:

Q1. How to setup GPU from VSCode? In the Colab there is a dropdown menu, where you could select GPU to accelerate the training process. But how do we do it in VScode through SSH?

Q2. How to prevent kicking off from Colab? I have read a trick in this Configuring Google Colab Like a Pro and How to prevent Google Colab from disconnecting. But they are not intended to be used in the VScode environment through SSH. Basically it has to be run in the Colab cell.

Thanks.

1 Answers

I have found a hack to solve the problems you're facing [I was having the same issue too :) ]

Steps:

  1. Go to Google Colab, create a new notebook
  2. Run this command !export -p in a cell; you should see the list of environment variables available to the Colab environment.
  3. Find this line in the output declare -x COLAB_GPU="0".
  4. In another cell, run the following code:
    import os
    os.environ['COLAB_GPU'] = "1"
  1. Run !export -p again, now you should see declare -x COLAB_GPU="1".
  2. Now run !pip install colab_ssh --upgrade
  3. After installing colab_ssh, set a secret_password and run the following code:
    from colab_ssh import launch_ssh_cloudflared
    launch_ssh_cloudflared(secret_password)
  1. Follow the Client-machine configuration as shown in the output cell.

Assuming you've successfully connected your local VSCode IDE to Colab Kernel over ssh-tunnel, you should now be able to open a notebook from your GDrive and run codes that require GPU access/High-RAM.

Related