Light-weight JupyterLab with GPU-access

Marko Gasparic Marko Gašparič
Oct 12, 2021 - 5 min read
Reddit LinkedIn

Today, we will look at how to set up a JupyterLab, with graphics card access. We will deploy a Docker container, based on the latest cschranz/gpu-jupyter Docker image, which already contains everything we need. Remember, you do not need to install anything on your local machine.


JupyterLab is a web-based interactive development environment for Jupyter notebooks, code, and data. It is very popular with data scientists and offers great support for writing Python scripts. So, let's get started.

Hardware Selection

Since some rigs in San Jose have an attractive price tag, we can use those. Tesla T4 is a bit old, but still provides more than enough power for most tasks. Also, a short usage limit of 3 hours and 15 minutes will suffice for the initial development session.

Time and Region Selection Example

For the purposes of this tutorial, one virtual machine is enough. Under the "Number of Instances" label, select "1". If you want to pick a different region and/or a different rig, do not forget to select at least one graphics card there too. In my case, one Tesla T4 is the only option, as are the number of CPU cores (4), memory size (16 GB), and storage size (116 GB). This virtual machine is going to be more powerful than necessary, but that is not a problem.

Hardware Selection Example

If you are going to pick hardware with more options, you can customize it further. For cschranz/gpu-jupyter, 2 cores are enough, while memory requirements largely depend on the scripts you are planning to execute. For most machine learning tasks, 8 GB should be enough, but maybe you need 32 GB.


Likewise, storage requirements depend on the size of your dataset. Keep in mind that you need approximately 30 GB of space for the JupyterLab, Python, Cuda, Nvidia drivers, etc., thus, you certainly need to add a considerable amount of extra space on top of your dataset size. If your scripts are going to generate more data, do not forget to count that in as well.

Environment Selection

Great! We can now define the environment we would like to install on the virtual machine. As already mentioned, "cschranz/gpu-jupyter" is the image of the day. Furthermore, as JupyterLab will be opened in a local browser, while running on a remote machine, we need to enable HTTPS-access. See the checkmark under "Supported Access Protocols". Additionally, we need to map "Https Ingress Port" "443" to "8888", which is the default port used by cschranz/gpu-jupyter.

Image and Port Selection Example

Actually, the above setting is enough to run the old Jupyter Notebook, but we are going to make three more tweaks. First, we are going to add an environment variable for the JupyterLab, i.e., "JUPYTER_ENABLE_LAB=yes". Second, we are going to grant ourselves super-user rights, just in case, if we need them in the future, i.e., "GRANT_SUDO=yes". And third, we are going to define a custom path for the "Persistent Storage Location", using "/home/jovyan/work" directory.

Environment Variables and Persistent Storage Location Selection Example

That is it. The environment is defined, and we are ready to pay.

Payment

At the final step of the hiring process, on the left side, you are able to double-check the selected environment and hardware. If something is wrong, you should navigate back and correct the mistakes. Otherwise, you may enter your email address and click "Confirm", to activate the Terms of Service agreement checkmark.

Email Confirmation Example

When you express your agreement with the Terms of Service, PayPal buttons will appear, and you can decide between the direct PayPal payment or Credit Card payment via PayPal. Both options ensure that Tensor Sharing will not see any of your payment credentials. The platform will only receive the information on the payment status, which, in case of success, will finish the virtual machine hiring process.

Terms of Service Agreement Example

For example, if you click on the upper PayPal button, a pop-up window will appear, and you can use your PayPal account to execute the payment. The payment limit for the selected hardware and duration is $0.93, which means that $0.93 will be reserved, but you may be charged less if you terminate your session earlier.

PayPal Pop-up Example

If the payment is successful, you will see a corresponding message with two options. To navigate back to the Tensor Sharing main page, you should select the "Home" button, and to see the control board of the hired virtual machine, you should select the "Log" button.

Success Message Example

The equivalent to the Log content will be sent also to the email address you specified.

Virtual Machine Log and Email Examples

Take a note that if you deleted the email sent by "no-reply@tensorsharing.com", you closed the web-page or navigated away from the https://www.tensorsharing.com/hire, and you do not have the Tensor Sharing account, you can still recover your access to the virtual machine by creating a new Tensor Sharing account with the same email address that you used for the payment. If you already have the Tensor Sharing account, hired virtual machines will always be visible in your dashboard. However, if you cannot access the selected email address, and you cannot sign in to your Tensor Sharing account, you will not be able to control or access the virtual machine you just hired when https://www.tensorsharing.com/hire is closed.

JupyterLab

It will take two or three minutes, on average, before the virtual machine spins up and some content appears when you click on the "Open" button. For security reasons, the URL of the virtual machine, has the following format: "https://[ID].vm.sharedtensors.com/?TS-Authorization=[TOKEN]". Do not share this link or the TS-Authorization token with anyone! It gives you secure access to your virtual machine.


Even though the size of the cschranz/gpu-jupyter image is small for this type of environment, it still may take some time before it is downloaded and deployed. You can track the progress on the virtual machine web-page.

Virtual Machine Progress Example

Once the Docker container is up and running, you can enter JupyterLab. The default password is "gpu-jupyter". It is out of the scope of this tutorial, but it is possible to get rid of the password requirement or to change the password by implementing an appropriate "Initialization Script", when the environment is selected. However, the JupyterLab password does not affect the overall security of the notebooks saved on your virtual machine.

JupyterLab Dashboard

Select the Python 3 Kernel, to open a new notebook, and write your first script, which will run on the hardware you hired.

Python Script Printing GPUs

Have fun writing your scripts and use Tensor Sharing to speed up your work, by hiring the affordable processing power owned by ordinary citizens. Have a nice day!