{"id":564,"date":"2021-04-30T15:38:45","date_gmt":"2021-04-30T13:38:45","guid":{"rendered":"https:\/\/nubisoft.io\/blog\/?p=564"},"modified":"2021-04-30T15:38:45","modified_gmt":"2021-04-30T13:38:45","slug":"setting-ubuntu-gpu-ec2-aws-ml-pytorch-2","status":"publish","type":"post","link":"https:\/\/nubisoft.io\/blog\/setting-ubuntu-gpu-ec2-aws-ml-pytorch-2\/","title":{"rendered":"Setting up Ubuntu on GPU EC2  in AWS for ML with PyTorch &#8211; part 2"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">In the first part of this post, we showed you how to set up a G2 class EC2 host in the AWS cloud and how to install Tesla GPU drivers for the Ubuntu operating system on it. Now all that&#8217;s left to do is to configure the PyTorch environment and run it on the interactive Jupyter Notebook platform.<\/h2>\n\n\n\n<p>One of the easiest, but also more productive methods is to use the dedicated data science package &#8211; Anaconda. At the time of writing this post, the most recent version is Anaconda3 (2020.11). Let&#8217;s download it as an archive file and install it.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">wget https:\/\/repo.anaconda.com\/archive\/Anaconda3-2020.11-Linux-x86_64.sh\nchmod +x .\/Anaconda3-2020.11-Linux-x86_64.sh\n.\/Anaconda3-2020.11-Linux-x86_64.sh<\/pre>\n\n\n\n<p>During the installation, we will be asked to accept the license conditions and specify the package installation location &#8211; stay with the default destination: <strong>\/home\/ubuntu\/anaconda3<\/strong><\/p>\n\n\n\n<p>Finally, let&#8217;s confirm that we want the installer to initialize Anaconda3<br>by running <strong>conda init<\/strong> automatically.<\/p>\n\n\n\n<p>Now, for the configuration to take effect, we need to reboot the Ubuntu 18.04 operating system or execute the command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">source ~\/.bashrc<\/pre>\n\n\n\n<p>With Anaconda installed, we can now focus on the PyTorch package. In addition, we will show here how to install the recently gaining popularity FastAI package &#8211; an overlay for PyTorch enabling faster prototyping:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git clone https:\/\/github.com\/fastai\/fastai2\ncd fastai2\nconda env create -f environment.yml<\/pre>\n\n\n\n<p>The above commands will prepare the FastAI environment to be installed. Now, let&#8217;s install in newly configured environment the latest version of the FastAI platform.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip install fastai2\npip install nbdev\nnbdev_install_git_hooks\nconda install pyarrow\npip install pydicom kornia opencv-python scikit-image<\/pre>\n\n\n\n<p>If we would like to additionally download the latest FastAI user manual, we can do it by executing the command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git clone https:\/\/github.com\/fastai\/fastbook<\/pre>\n\n\n\n<p>Now all that&#8217;s left to do is start the Jupyter notebook server:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">jupyter notebook<\/pre>\n\n\n\n<p>This will start the Jupyter server on localhost on the default port 8888. To be able to use Notebooks in the browser of our workstation, we only need to configure the tunnel and enter <code>localhost: 8888<\/code> in the browser&#8217;s address bar, and when prompted for a token, copy it from the EC2 host console.<\/p>\n\n\n\n<p>Now you can check if the PyTorch library is properly configured and can communicate with the GPU.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">torch.cuda.is_available()<\/pre>\n\n\n\n<p>Now you are ready for your exciting deep learning adventure!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the first part of this post, we showed you how to set up a G2 class EC2 host in the AWS cloud and how to install Tesla GPU drivers for the Ubuntu operating system on it. Now all that&#8217;s left to do is to configure the PyTorch environment and run it on the interactive [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":570,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_case_study_excerpt":"","footnotes":""},"categories":[2,104,55,5],"tags":[32,106,107,11,105,54],"class_list":["post-564","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-science","category-deep-learning","category-devops","category-infrastructure","tag-aws","tag-google-colab","tag-gpu","tag-jupyter","tag-pytorch","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/posts\/564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/comments?post=564"}],"version-history":[{"count":7,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/posts\/564\/revisions"}],"predecessor-version":[{"id":585,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/posts\/564\/revisions\/585"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/media\/570"}],"wp:attachment":[{"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/media?parent=564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/categories?post=564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/tags?post=564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}