-
Notifications
You must be signed in to change notification settings - Fork 175
AWS Setup Guide
If you have a Windows PC, but it lacks the hardware necessary to run the programs/projects you want to use (ex: neural-style-pt), then this guide will help you use an AWS server like many artists in your position do.
- What you need to do on your PC.
- Create an AWS account.
- Select an AMI in your desired region.
- Every time you boot it up after it's saved, it will be exactly as it was when you saved it. So don't worry about breaking thing once it's saved, because your mistakes aren't going to be saved.
Terminating/Stopping Your AMI From Running
- Always stop/terminate an AMI/server that's running, when you aren't using it! It costs money to keep it running!
First download and install WinSCP: https://winscp.net/eng/download.php
Open up this link to download PuTTY: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
Then scroll down to "putty.exe (the SSH and Telnet client itself)", and download either the 32bit or 64bit versions of PuTTY.exe (depending on your OS):
Navigate to:
C:\Program Files
And create a folder called PuTTY:
C:\Program Files\PuTTY`
Place putty.exe in this folder:
C:\Program Files\PuTTY\PuTTY.exe
It is possible to setup a Ubuntu AMI with a desktop GUI on AWS, and then you use some software that lets you use it like a normal home desktop PC remotely, but that is outside of the scope of this guide. A desktop GUI would also take away precious GPU resources from the projects you want to run. So, this is why we use WinSCP with the PuTTY terminal.
If you do not have an AWS already, go to https://aws.amazon.com/, and click on "My Account" on the top right, and then select "AWS Management Console". Then create an account and sign in.
REMEMBER TO MAKE SURE THAT YOU HAVE NOT LEFT YOUR AMI RUNNING WHEN NOT USING IT, BECAUSE YOU ARE PAYING BY THE MINUTE/HOUR!
Use this site to find the desired Ubuntu version in the region (zone) you want: https://cloud-images.ubuntu.com/locator/ec2/
Pick your region based on wherever you think is cheapest and not whatever is closest to you. Make sure the region you pick has "p2.xlarge" spot instance available!
-
p2.xlarge spot request instances have a single Tesla K80 GPU with 12GB of memory. They normally cost around $0.20-$0.30 per hour, depending on the region you pick.
-
p2.8xlarge spot request instances have 8 Tesla K80 GPUs with 12GB of memory each. They normally cost around $2-$5 per hour, depending on the region you pick.
If you make your AMI in one region and later find out it's cheaper in another region, you can just copy your completed AMI to that cheaper region.
Then click on the "AMI-ID" of the AMI you want and it will take you to AWS' site. You are looking for an AMI that has: hvm:ebs-ssd
under "Instance Type", and amd64
under "Arch".
I chose a Ubuntu 16.04 AMI for this guide (for compatibility reasons), but setup is the same for other Ubuntu versions.
When you click on the links under AMI-ID, you'll be taken to this page (if you are already signed into AWS):
Click on "all Instance types" from the top left and select "GPU instances":
You'll now be shown this screen:
Scroll down and select "p2.xlarge" and then click "Next: Configure Instance Details":
You'll now see this page:
Click on the "Request Spot instances" checkbox, and put some like $1 for the "Maximum price", then click "Next: Add Storage":
You'll now see this page:
Change 8GB to something higher, like 32GB or 64GB, then click "Next: Add Tags":
Ignore this page. Click "Next: Configure Security Group":
You'll now see this page:
Under "Source" change "custom" to "My IP", then hit "Review and Launch":
Make sure everything looks good, and the click "Launch":
If you don't have an existing Key Pair, now is the time to create a new one:
Give your new key pair a name, and then download it:
Open up WinSCP:
Add "ubuntu" to the "User name" section, and then select advanced:
You'll now see WinSCP's advanced settings window:
Navigate to "authentication" by clicking the option on the left side of the window. Then click the 3 dots under the private key input section:
Now navigate to and select your private key that you previously downloaded from AWS:
Select "Yes" for converting your private key to PuTTY's format:
Save the newly converted private key:
Click "Okay":
Click "Okay":
Now select "Save" and you'll see this screen:
Give your new session a name:
Now go back to AWS and make sure that you have selected the key pair that you made, then click "Request Spot Instances":
You'll now see this screen. Click "View Spot Requests" on the right:
You'll now see this screen:
Click on "Instances" on the right hand side:
You'll now see this screen. Click on your instance:
Scroll down and look at the information in the bottom bar:
Copy the public IPv4 address:
And put that IPv4 address in your WinSCP session's Hostname:
Now you'll see this screen. Click "Login":
Once your AMI is fully booted, WinSCP will give you this message. Click "Yes":
You'll now see this screen. You can easily move files back and fourth between your computer and the AMI/server by simply dragging them from the left/right window in WinSCP to the other window in WinSCP. WinSCP does not automatically check for new files and other changes, so you'll have to use the green arrows at the top to refresh it when creating new files like images:
Now click the two tiny PC screens with a lightning bolt in between them on the top left of WinSCP:
PuTTY should automatically boot up and login to your AMI. If there's a key warning message, click "Yes":
Sometimes AMIs can have issues when you first boot them, so I like to test for that with a simple and useless sudo apt-get install time
command:
This is the main issue I was checking for:
ubuntu@ip-Address:~$ sudo apt-get install time
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
Even if that command doesn't have any issues, it's still a good idea to reboot just encase. You should do this every time you boot up your AMI:
After you run the reboot command, PuTTY will stop working and give an error, letting you know it lost connection. Close the PuTTY window:
WinSCP will keep looking for the server until it's rebooted. If it stops, you can make it start again:
Now you can install whatever you want on your sever/AMI for later. If you wish to install neural-style-pt, check out the installation guide here: https://github.com/ProGamerGov/neural-style-pt/blob/master/INSTALL.md
I recommend the Github and pip or just simply the pip guide for installing neural-style-pt.
If you run into issues installing things, other people have probably run into those errors as well. So, use a search engine and see if anyone has posted how they fixed the issue.
Once you have installed everything that you want on your AMI, you now need to save it. Every time you load up the AMI, it will be exactly like it was when you saved it. Nothing is saved unless you create a new AMI from the current AMI.
On the AWS console page, right click on your instance and navigate to "Create Image":
You'll now see this page. Make sure there's enough storage space:
Give the Image a name and description, so that you will know what it contains in the future. Then click "Create Image" in the bottom right:
You'll now see this page. Click "Close":
Your AMI is now saved!
Click on "AMIs" on the left panel:
Right click on the AMI that you want to launch and select "Spot Requests":
Now, when you start up your saved instance, it's pretty much just like before, only you don't have to make a new key pair:
You do however have to replace the Hostname in your WinSCP session with the new IPv4 address from your newly launched spot request.
If your AMI has previously been saved, terminating it will not delete it. You will only loose whatever you have done since saving/booting up your AMI.
On the Instances page, right click on your currently running AMI and select "Terminate":
You'll now see this page. Select "Yes, Terminate":
If you ever end up on this AWS Console page:
Simply click on "EC2".
I found the CUDA driver installation guide from here to be useful for installing/updating drivers for PyTorch: https://askubuntu.com/questions/1077061/how-do-i-install-nvidia-and-cuda-drivers-into-ubuntu/1077063#1077063
There may be better or more applicable guides elsewhere for drivers, but you'll have to search for them.