Run AllenNLP on AWS P2 with ArchLinux

Quest: Run AllenNLP with GPU support on an AWS p2/p3 instances with ArchLinux.

Steps:

  1. Go to https://www.uplinklabs.net/projects/arch-linux-on-ec2/

  2. Start a new EC2 instance by clicking on the "ebs hvm x86_64 lts"-link for your prefered region.

  3. Choose p2.xlarge as instance type (all other p2 and p3 will work the same)

  4. Configure the stuff you need (allow ssh, storage, ...)

  5. Launch instance (save the pem-certificate!)

  6. Get the IP address from the ec2 instances view

  7. Connect to server

ssh -i certificate.pem root@<IP-ADDRESS>

Yay! We have a shell on archlinux.

  1. First you may have to repopulate the archlinux-keyring

pacman-key --init
  1. Next update the already installed packages

pacman --noconfirm -Syu
  1. Install a few packages (we need nvidia-dkms and not nvidia because the kernel is a custom one and not default archlinux)

pacman --noconfirm -S git cudnn cuda python-virtualenvwrapper nvidia-dkms nvidia-utils htop tmux
  1. Reboot server to load new kernel with nvidia module

reboot
  1. After the reboot, connect to server again

ssh -i certificate.pem root@<IP-ADDRESS>
  1. Test if nvidia module is loaded

nvidia-smi
  1. Add virtualenvwrapper to your shell

source /usr/bin/virtualenvwrapper.sh
  1. And create a virtualenv

mkvirtualenv testing
  1. Install allennlp

pip install allennlp
  1. And test if PyTorch/AllenNLP finds the gpu

python -c "import torch; print('cuda:', torch.cuda.is_available())"
  1. (Optional) run the AllenNLP testsuite

allennlp test-install

Now you can use AllenNLP with GPU on AWS!