{"id":572,"date":"2020-03-08T16:47:51","date_gmt":"2020-03-08T20:47:51","guid":{"rendered":"http:\/\/brian.digitalmaddox.com\/blog\/?p=572"},"modified":"2020-03-08T16:47:51","modified_gmt":"2020-03-08T20:47:51","slug":"fun-with-linux-and-a-rtx-2060","status":"publish","type":"post","link":"https:\/\/brian.digitalmaddox.com\/blog\/?p=572","title":{"rendered":"Fun with Linux and a RTX 2060"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Or&#8230;. how to spend a day hitting your head into your desk.<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">Or&#8230;. machine learning is easy, right? \ud83d\ude42<\/h2>\n\n\n\n<p class=\"has-drop-cap wp-block-paragraph\">For a while now I have been wanting to upgrade my video card in my desktop so I could actually use it to do machine\/deep learning tasks (ML).  Since I put together a Frankenstein gaming computer for my daughters out of some older parts, I finally justified getting a new card by saying I would then give them my older nVidia card.  After a lot of research, I decided the <a href=\"https:\/\/www.nvidia.com\/en-us\/geforce\/graphics-cards\/rtx-2060\/\">RTX 2060<\/a> was a good balance of how much money I felt like spending versus something that would actually be useful (plus the series comes with dedicated Tensor Cores that work really fast with <a href=\"https:\/\/towardsdatascience.com\/rtx-2060-vs-gtx-1080ti-in-deep-learning-gpu-benchmarks-cheapest-rtx-vs-most-expensive-gtx-card-cd47cd9931d2\">fp16<\/a> data types).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So after buying the card and installing it, the first thing I wanted to do was to get <a href=\"https:\/\/github.com\/tensorflow\/tensorflow\/releases\/tag\/v2.1.0\">Tensorflow 2.1<\/a> to work with it.  Now, I already had <a href=\"https:\/\/developer.nvidia.com\/cuda-downloads\">CUDA<\/a> 10.2 and the most up-to-date version of <a href=\"https:\/\/developer.nvidia.com\/tensorrt\">TensorRT<\/a> installed, and knew that I&#8217;d have to custom compile Tensorflow&#8217;s pip version to work on my system.  What I did not know was just how annoying this would turn out to be.  My first attempt was to follow the <a href=\"https:\/\/www.tensorflow.org\/install\/source\">instructions<\/a> from the Tensorflow web site, including applying <a href=\"https:\/\/github.com\/tensorflow\/tensorflow\/pull\/34885\">this<\/a> patch that fixes the nccl bindings to work with CUDA 10.2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, all of my attempts failed.  I had random compiler errors crop up during the build that I have never had before and could not explain.  Tried building it with Clang.  Tried different versions of GCC.  Considered building with a Catholic priest present to keep the demons at bay.  No dice.  Never could complete a build successfully on my system.  This was a bit to be expected since a lot of people online have trouble getting Tensorflow 2.1 and CUDA 10.2 to play nice together.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I finally broke down and downgraded CUDA on my system to 10.1.  I also downgraded TensorRT so it would be compatible with the version of CUDA I now had.  Finally I could do a <code>pip install tensorflow-gpu<\/code> inside my virtual environment and and it worked and it ran and I could finally run my training on my GPU with fantastic results.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Almost.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I kept getting <code>CUDNN_STATUS_INTERNAL_ERROR<\/code> messages every time I tried to run a Keras application on the GPU.  Yay.  After some Googling, I found this <a href=\"https:\/\/github.com\/tensorflow\/tensorflow\/issues\/24496\">link<\/a> and apparently there&#8217;s an issue with Tensorflow and the RTX line.  To fix it, you have to add this to your Python code that uses Keras\/Tensorflow:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>from tensorflow.compat.v1 import ConfigProto<br>from tensorflow.compat.v1 import InteractiveSession<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>...<br> config = ConfigProto()<br> config.gpu_options.allow_growth = True<br> session = InteractiveSession(config=config)<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">FINALLY!  After several days of trying to custom compile Tensorflow for my system, giving up, downgrading so I could install via pip, running into more errors, etc, I now have a working GPU-accelerated Tensorflow!  As an example, running the simple <a href=\"https:\/\/github.com\/keras-team\/keras\/blob\/master\/examples\/addition_rnn.py\">additionrnn.py<\/a> example from Keras, I went from taking around 3.5 seconds per epoch on my Ryzen 7 2700X processor (where I had compiled Tensorflow for CPU only to take advantage of the additional CPU instructions) to taking under 0.5 seconds on the GPU.  I&#8217;m still experimenting, and modifying some things to use fp16 so I can take advantage of the Tensor Cores in the GPU.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Or&#8230;. how to spend a day hitting your head into your desk. Or&#8230;. machine learning is easy, right? \ud83d\ude42 For a while now I have been wanting to upgrade my video card in my desktop so I could actually use &hellip; <a href=\"https:\/\/brian.digitalmaddox.com\/blog\/?p=572\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[31,28,26,30,29,27,32],"class_list":["post-572","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-cuda","tag-keras","tag-machine-learning","tag-nvidia","tag-rtx-2060","tag-tensorflow","tag-tensorrt"],"_links":{"self":[{"href":"https:\/\/brian.digitalmaddox.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/572","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/brian.digitalmaddox.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/brian.digitalmaddox.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/brian.digitalmaddox.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/brian.digitalmaddox.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=572"}],"version-history":[{"count":9,"href":"https:\/\/brian.digitalmaddox.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/572\/revisions"}],"predecessor-version":[{"id":581,"href":"https:\/\/brian.digitalmaddox.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/572\/revisions\/581"}],"wp:attachment":[{"href":"https:\/\/brian.digitalmaddox.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/brian.digitalmaddox.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/brian.digitalmaddox.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}