This content originally appeared on Level Up Coding - Medium and was authored by Kasper Groes Albin Ludvigsen
Not all AWS EC2 instance types are supported by the AMI images offered by AWS, but luckily you can install a GPU driver yourself in less than 10 easy steps.
Suppose you have launched an AWS EC2 p2.xlarge instance with the Deep Learning AMI GPU PyTorch 1.11.0 (Ubuntu 20.04) 20220824 image and now you want to run some GPU intensive Python script such as training a transformer for time series forecasting.
This will fail. It will tell you that the instance does not have a GPU.
If you’re wondering why the GPU is not working out of the box for your AWS EC2 p2 instance using a Deep Learning AMI, it is because these Deep Learning AMIs are only supported on specific instance types such as G3, P3, P3dn, P4d, G5, G4dn.
But there is a workaround that will allow you to install an Nvidia GPU driver on your AWS EC2 p2 instance and make the instance recognize the GPU such that your Python / PyTorch script can use it.
I spent hours trying to figure out how to get the Nvidia GPU installation right on my EC2 instance, and with the help of an AWS wizard colleague, it finally worked. To save you the trouble, I made this post. Once you know how to do it, it’s really simple.
Here’s how to install an Nvidia GPU driver on an AWS EC2 instance such as p2.xlarge launched with a Deep Learning AMI:
- Launch instance and connect via ssh e.g. using Putty. On Amazon Linux AMI’s the username you have to use to connect is “ec2-user” but on Ubuntu AMI’s the username is “ubuntu”
- Run sudo apt-get update
- Run sudo apt-get upgrade (notice the difference between 2 and 3)
- Reboot the instance by running sudo reboot— The putty session will become inactive as the instance reboots. It might take a few minutes before you can connect through a new session.
- Run sudo apt-get install xorg
- Run sudo apt-get install nvidia-driver-460
- Reboot again: sudo reboot
- Run nvidia-smi to verify that the GPU is now installed.
- To test if PyTorch is able to access and use the GPU, you can run the command pip install torchthen upload a file with the code below and run the file from the Putty command line like so python3 get_gpu_devices.py The output should be “True” and “0” (assuming you’re on a AWS EC2 p2.xlarge instance)
That’s it! I hope you enjoyed this post 🤞
Feel free to follow. I sometimes write about AWS tips. I also write about time series forecasting, green software engineering and the environmental impact of data science 🍀
And feel free to connect with me on LinkedIn.
How to install an Nvidia GPU driver on an AWS EC2 instance was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.
This content originally appeared on Level Up Coding - Medium and was authored by Kasper Groes Albin Ludvigsen
Kasper Groes Albin Ludvigsen | Sciencx (2022-09-08T14:57:30+00:00) How to install an Nvidia GPU driver on an AWS EC2 instance. Retrieved from https://www.scien.cx/2022/09/08/how-to-install-an-nvidia-gpu-driver-on-an-aws-ec2-instance/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.