How to install an Nvidia GPU driver on an AWS EC2 instance

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.Photo by Christian Wiediger on UnsplashSuppose you have launched an AWS EC2 p2.xlarge instance w…


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.

Photo by Christian Wiediger on Unsplash

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:

  1. 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”
  2. Run sudo apt-get update
  3. Run sudo apt-get upgrade (notice the difference between 2 and 3)
  4. 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.
  5. Run sudo apt-get install xorg
  6. Run sudo apt-get install nvidia-driver-460
  7. Reboot again: sudo reboot
  8. Run nvidia-smi to verify that the GPU is now installed.
  9. 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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » How to install an Nvidia GPU driver on an AWS EC2 instance." Kasper Groes Albin Ludvigsen | Sciencx - Thursday September 8, 2022, https://www.scien.cx/2022/09/08/how-to-install-an-nvidia-gpu-driver-on-an-aws-ec2-instance/
HARVARD
Kasper Groes Albin Ludvigsen | Sciencx Thursday September 8, 2022 » How to install an Nvidia GPU driver on an AWS EC2 instance., viewed ,<https://www.scien.cx/2022/09/08/how-to-install-an-nvidia-gpu-driver-on-an-aws-ec2-instance/>
VANCOUVER
Kasper Groes Albin Ludvigsen | Sciencx - » How to install an Nvidia GPU driver on an AWS EC2 instance. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/09/08/how-to-install-an-nvidia-gpu-driver-on-an-aws-ec2-instance/
CHICAGO
" » How to install an Nvidia GPU driver on an AWS EC2 instance." Kasper Groes Albin Ludvigsen | Sciencx - Accessed . https://www.scien.cx/2022/09/08/how-to-install-an-nvidia-gpu-driver-on-an-aws-ec2-instance/
IEEE
" » How to install an Nvidia GPU driver on an AWS EC2 instance." Kasper Groes Albin Ludvigsen | Sciencx [Online]. Available: https://www.scien.cx/2022/09/08/how-to-install-an-nvidia-gpu-driver-on-an-aws-ec2-instance/. [Accessed: ]
rf:citation
» How to install an Nvidia GPU driver on an AWS EC2 instance | Kasper Groes Albin Ludvigsen | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.