Use NNI on Google Colab

NNI can easily run on Google Colab platform. However, Colab doesn’t expose its public IP and ports, so by default you can not access NNI’s Web UI on Colab. To solve this, you need a reverse proxy software like ngrok or frp. This tutorial will show you how to use ngrok to access NNI’s Web UI on Colab.

How to Open NNI’s Web UI on Google Colab

  1. Install required packages and softwares.

    ! pip install nni # install nni
    ! wget # download ngrok and unzip it
    ! unzip
    ! mkdir -p nni_repo
    ! git clone nni_repo/nni # clone NNI's offical repo to get examples
  2. Register a ngrok account here, then connect to your account using your authtoken.

    ! ./ngrok authtoken YOUR_AUTH_TOKEN
  3. Start an NNI example on a port bigger than 1024, then start ngrok with the same port. If you want to use gpu, make sure gpuNum >= 1 in config.yml. Use get_ipython() to start ngrok since it will be stuck if you use ! ngrok http 5000 &.

    ! nnictl create --config nni_repo/nni/examples/trials/mnist-pytorch/config.yml --port 5000 &
    get_ipython().system_raw('./ngrok http 5000 &')
  4. Check the public url.

    ! curl -s http://localhost:4040/api/tunnels # don't change the port number 4040

    You will see an url like after step 4, open this url and you will find NNI’s Web UI. Have fun :)

Access Web UI with frp

frp is another reverse proxy software with similar functions. However, frp doesn’t provide free public urls, so you may need an server with public IP as a frp server. See here to know more about how to deploy frp.