{"id":470,"date":"2017-01-22T23:56:12","date_gmt":"2017-01-22T21:56:12","guid":{"rendered":"http:\/\/log.or.cz\/?p=470"},"modified":"2017-01-23T17:15:25","modified_gmt":"2017-01-23T15:15:25","slug":"modern-cuda-cudnn-ami-on-aws","status":"publish","type":"post","link":"https:\/\/log.or.cz\/?p=470","title":{"rendered":"Modern CUDA + CuDNN Theano\/Keras AMI on AWS"},"content":{"rendered":"<p>Wow, what a jargon-filled post title.  Basically, we do a lot of our deep learning currently on the AWS EC2 cloud &#8211; but to use the GPU there with all the goodies (up to CuDNN that supports modern Theano&#8217;s batch normalization) is a surprisingly arduous process which you basically need to do manually, with a lot of trial and error and googling and hacking.  This is awful, mind-boggling and I hate that everyone has to go through this.  So, to fix this bad situation, <b>I just released a community AMI<\/b> that:<\/p>\n<ul>\n<li> &#8230;is based on Ubuntu 16.04 LTS (as opposed to 14.04)\n<li> &#8230;comes with CUDA + CuDNN drivers and toolkit already set up to work on g2.2xlarge instances\n<li> &#8230;has Theano and Keras preinstalled and preconfigured so that you can run the Keras ResNet model on a GPU right away (or anything else you desire)\n<\/ul>\n<p>To get started, just <b>spin up a GPU (g2.2xlarge) instance from community AMI ami-f0bde196<\/b> (1604-cuda80-cudnn5110-theano-keras), ssh in as the ubuntu@ user and get going! No hassles. But of course, EC2 charges apply.<\/p>\n<hr>\n<p>Edit (errata): Actually, there&#8217;s a bug &#8211; sorry about that! Out of the box, the nvidia kernel driver is not loaded properly on boot.  I might update the AMI later, for now to fix it manually:<\/p>\n<ol>\n<li> Edit <code>\/etc\/modprobe.d\/blacklist.conf<\/code> (using for example <code>sudo nano<\/code>) and append the line <code>blacklist nouveau<\/code> to the end of that file\n<li> Run <code>sudo update-initramfs -u<\/code>\n<li> Reboot.  Now, everything should finally work.\n<\/ol>\n<hr>\n<p>This AMI was created like this:<\/p>\n<ul>\n<li> The stock Ubuntu 16.04 LTS AMI\n<li> NVIDIA driver 367.57 (older drivers do not support CUDA 8.0, while this is the last driver version to support the K520 GRID GPU used in AWS)\n<li> To make the driver setup go through, the <a href=\"https:\/\/gist.github.com\/albertstartup\/9619faab6a2f6afdf4dc13f897d48a05\">trick<\/a> to install <code>apt-get install linux-image-extra-`uname -r`<\/code> per\n<li> CUDA 8.0 and CuDNN 8.0 set up from the official though unannounced NVIDIA Debian packages by replaying the <a href=\"https:\/\/github.com\/NVIDIA\/nvidia-docker\/tree\/master\/ubuntu-16.04\/cuda\/8.0\">nvidia-docker recipes<\/a>\n<li> bashrc modified to include cuda in the path\n<li> Theano and Keras from latest Git as of writing this blogpost (feel free to git pull and reinstall), and some auxiliary python-related etc. packages\n<li> Theano configured to use GPU and Keras configured to use Theano (and the &#8220;th&#8221; image dim ordering rather than &#8220;tf&#8221; &#8211; this is currently non-default in Keras!)\n<li> <a href=\"https:\/\/github.com\/fchollet\/deep-learning-models\">Example Keras deep learning models<\/a>, even an elephant.jpg!  Just run <code>python resnet50.py<\/code>\n<li> Exercise: Install TensorFlow on the system as well, release your own AMI and post its id in the comments!\n<li> Tip: Use nvidia-docker based containers to package your deep learning software; combine it with docker-machine to easily provision GPU instances in AWS and execute your models as needed.  Using this for development is a hassle, though.\n<\/ul>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wow, what a jargon-filled post title. Basically, we do a lot of our deep learning currently on the AWS EC2 cloud &#8211; but to use the GPU there with all the goodies (up to CuDNN that supports modern Theano&#8217;s batch normalization) is a surprisingly arduous process which you basically need to do manually, with a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[150,3,6],"tags":[176,175,177,179,158,178],"class_list":["post-470","post","type-post","status-publish","format-standard","hentry","category-ailao","category-linux","category-software","tag-aws","tag-cuda","tag-ec2","tag-gpu","tag-keras","tag-theano"],"_links":{"self":[{"href":"https:\/\/log.or.cz\/index.php?rest_route=\/wp\/v2\/posts\/470","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/log.or.cz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/log.or.cz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/log.or.cz\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/log.or.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=470"}],"version-history":[{"count":11,"href":"https:\/\/log.or.cz\/index.php?rest_route=\/wp\/v2\/posts\/470\/revisions"}],"predecessor-version":[{"id":481,"href":"https:\/\/log.or.cz\/index.php?rest_route=\/wp\/v2\/posts\/470\/revisions\/481"}],"wp:attachment":[{"href":"https:\/\/log.or.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/log.or.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/log.or.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}