nni_colab_support.rst 1.99 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
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
----------------------------------------

#. Install required packages and softwares.

Yuge Zhang's avatar
Yuge Zhang committed
11
   .. code-block:: bash
12

Yuge Zhang's avatar
Yuge Zhang committed
13
14
15
16
17
      ! pip install nni # install nni
      ! wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip # download ngrok and unzip it
      ! unzip ngrok-stable-linux-amd64.zip
      ! mkdir -p nni_repo
      ! git clone https://github.com/microsoft/nni.git nni_repo/nni # clone NNI's offical repo to get examples
18
19


Yuge Zhang's avatar
Yuge Zhang committed
20
#. Register a ngrok account `here <https://ngrok.com/>`__, then connect to your account using your authtoken.
21

Yuge Zhang's avatar
Yuge Zhang committed
22
   .. code-block:: bash
23

Yuge Zhang's avatar
Yuge Zhang committed
24
      ! ./ngrok authtoken YOUR_AUTH_TOKEN
25
26
27
28


#. 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 &``.

Yuge Zhang's avatar
Yuge Zhang committed
29
30
31
32
33
   .. code-block:: bash

      ! nnictl create --config nni_repo/nni/examples/trials/mnist-pytorch/config.yml --port 5000 &

   .. code-block:: python
34

Yuge Zhang's avatar
Yuge Zhang committed
35
      get_ipython().system_raw('./ngrok http 5000 &')
36
37
38
39


#. Check the public url.

Yuge Zhang's avatar
Yuge Zhang committed
40
   .. code-block:: bash
41

Yuge Zhang's avatar
Yuge Zhang committed
42
      ! curl -s http://localhost:4040/api/tunnels # don't change the port number 4040
43

Yuge Zhang's avatar
Yuge Zhang committed
44
   You will see an url like ``http://xxxx.ngrok.io`` after step 4, open this url and you will find NNI's Web UI. Have fun :)
45
46
47
48
49

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 <https://github.com/fatedier/frp>`__ to know more about how to deploy frp.