<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Y.C Cheng / 鄭原真 on Medium]]></title>
        <description><![CDATA[Stories by Y.C Cheng / 鄭原真 on Medium]]></description>
        <link>https://medium.com/@ycheng-tw?source=rss-afb1f12e9c17------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*IknIV0Tj8KjIz0vd.</url>
            <title>Stories by Y.C Cheng / 鄭原真 on Medium</title>
            <link>https://medium.com/@ycheng-tw?source=rss-afb1f12e9c17------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 08:47:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ycheng-tw/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Batch/scripts (in typescript) to run with Next.JS code base.]]></title>
            <link>https://ycheng-tw.medium.com/batch-scripts-in-typescript-to-run-with-next-js-code-base-644987d8972f?source=rss-afb1f12e9c17------2</link>
            <guid isPermaLink="false">https://medium.com/p/644987d8972f</guid>
            <dc:creator><![CDATA[Y.C Cheng / 鄭原真]]></dc:creator>
            <pubDate>Mon, 24 Oct 2022 11:50:43 GMT</pubDate>
            <atom:updated>2022-10-24T13:08:27.185Z</atom:updated>
            <content:encoded><![CDATA[<p>Next.js is a wonderful and so powerful back-end engine. However, the default one does not provide a way for small-start / small development to run a batch job/script with the next.js code base.</p><p>Writing an individual source tree to run batch/type shall be pretty easy. However, it’s such a nature that we’d like to re-use existing code inside the src to do some logic. There will have those business logic/utility functions we’d like to re-use in the batch job. Using another way to do so needs a little bit more setup on code sync, maybe a script to sync two directories, which slows down a bit. So here is what I try.</p><p>Using ts-node:</p><p>The key to running ts-node is to add the following section into tsconfig.json:</p><pre>  ...<br>  &quot;ts-node&quot;: {<br>    &quot;compilerOptions&quot;: {<br>      &quot;module&quot;: &quot;CommonJS&quot;<br>    }<br>  },<br>  ...</pre><p>I got this from <a href="https://stackoverflow.com/questions/69870137/running-a-single-ts-file-in-a-next-js-project-with-ts-node-for-testing">Here</a>. Here are the full steps to run it (assume that you are installing ts-node locally):</p><p>1. npm install -D ts-node<br> 2. modify tsconfig.json and add the above section.<br> 3. modify the package.json file and add scripts like</p><pre>&quot;scripts&quot;: {<br>    &quot;dev&quot;: &quot;next dev&quot;,<br>    &quot;build&quot;: &quot;next build&quot;,<br>    &quot;start&quot;: &quot;next start&quot;,<br>    &quot;lint&quot;: &quot;next lint&quot;,<br>    &quot;ts-script&quot;: &quot;ts-node src/worker/mainasdf.ts&quot;<br> },</pre><p>4. run it by “npm run ts-script”.</p><p>Then you are done!</p><p>=&gt; WARNING: Below will break next build. Need more work.</p><p>Ok then, this may be less perfect, as we’d like to convert all typescript scripts to javascript and run those. It seems the way typescript is designed. I think the performance gain might be limited, however, there could be certain chances that you still want to gain a little bit of start-up time.</p><p>As for doing that, it’s quite a struggle since to run the converted script, we need to set “type” to “module” in the package.json. But next.js don’t like it.</p><p>Since most deployments are on the Unix-Like OS, so the result I found is to create a sub-directory for the batch jobs, use a symbolic link to link to key directories, and make a copy of the package.json, with the only modification of the type to the module. So here it is:</p><p>1. Directory structure like:</p><pre>Project/batchjob<br>  package.json <br>                1. add &quot;type&quot;: &quot;module&quot;<br>                2. add &quot;tscbuild&quot;: &quot;tsc -p tsconfig_batch.json&quot; to<br>                   scipts section.<br>  tsconfig.json<br>                1. remove &quot;noEmit&quot;: true, or it won&#39;t create js.<br>                2. you need to &quot;include&quot;: [&quot;src&quot;],<br>                               &quot;exclude&quot;: [<br>                                  &quot;node_modules&quot;, &quot;pages&quot;<br>                               ]<br>                3. add &quot;outDir&quot;: &quot;build&quot; in compilerOptions<br>  node_modules symblic link to ../node_modules<br>  src          symblic link to ../src</pre><p>Then you can “cd batchjob ; node build/xxxx.js”</p><p>I might miss some details and steps, if it does not work for you, provide your logs and I’ll try to update this document.</p><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=644987d8972f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cheatsheet for Ubuntu]]></title>
            <link>https://ycheng-tw.medium.com/cheatsheet-for-ubuntu-e7a8d5e8dc87?source=rss-afb1f12e9c17------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7a8d5e8dc87</guid>
            <dc:creator><![CDATA[Y.C Cheng / 鄭原真]]></dc:creator>
            <pubDate>Fri, 11 Feb 2022 07:53:27 GMT</pubDate>
            <atom:updated>2022-10-20T02:15:13.876Z</atom:updated>
            <content:encoded><![CDATA[<p>As a Linux developer and working in Canonical for years, there is some workflow that I found it’s might not be so trivial for one. I think an article to share will be useful and handy.</p><p>Given this will never end somewhere, I’ll start with something simple, and no-hard feeling to update incrementally.</p><p>Q: If something crash, and you load the error report, where does it go?<br>A: <a href="https://errors.ubuntu.com/">https://errors.ubuntu.com/</a></p><p>Q: How do find the package currently in the SRU testing?<br>A: For kernel, check <a href="https://kernel.ubuntu.com/sru/sru-report.html">https://kernel.ubuntu.com/sru/sru-report.html</a><br> For others, check <a href="https://people.canonical.com/~ubuntu-archive/pending-sru.html">https://people.canonical.com/~ubuntu-archive/pending-sru.html</a></p><p>Q: Jargons<br>A: SRU: <a href="https://wiki.ubuntu.com/StableReleaseUpdates">https://wiki.ubuntu.com/StableReleaseUpdates</a><br> MIR: <a href="https://wiki.ubuntu.com/MainInclusionProcess">https://wiki.ubuntu.com/MainInclusionProcess</a></p><p>Q: package flow? How to go main / restricted<br>A:<br> universe =&gt; MIR =&gt; main <br> multiverse =&gt; MIR =&gt; restricted</p><p>While:</p><p><strong>Main</strong> — Officially supported software.<br> <strong>Restricted</strong> — Supported software that is not available under a completely free license.<br> <strong>Universe</strong> — Community maintained software, i.e. not officially supported software.<br> <strong>Multiverse</strong> — Software that is not free.</p><p>Q: autopkgtest, if it failed, pkg can’t be released. Where’s it’s test result?<br>A: Note the Debian seems to use lxc to run the autopkgtest. ubuntu use juju, probably also lxc.<br> Debian: <a href="https://ci.debian.net/">https://ci.debian.net/</a><br> Ubuntu: <a href="https://people.canonical.com/~ubuntu-archive/proposed-migration/update_excuses.html">https://people.canonical.com/~ubuntu-archive/proposed-migration/update_excuses.html</a><br> ubuntu: …</p><p>Q: How pkg go to update?<br>A: <a href="https://wiki.ubuntu.com/ProposedMigration">https://wiki.ubuntu.com/ProposedMigration</a></p><p>Q: What will go into the images:<br>A: I believe it’s <a href="https://code.launchpad.net/~ubuntu-core-dev/ubuntu-seeds/+git/ubuntu">https://code.launchpad.net/~ubuntu-core-dev/ubuntu-seeds/+git/ubuntu</a>.</p><p>Q: How to attach machine info to a bug.<br>A: apport-collect bug_number # run on the target machine.</p><p>Q: phased update for ubuntu pkgs?<br>A: <a href="https://people.canonical.com/~ubuntu-archive/phased-updates.html">https://people.canonical.com/~ubuntu-archive/phased-updates.html</a><br> 20.04: via update-manager.<br> 22.04: apt also include.</p><p>Q: Canonical service status?<br>A: <a href="https://status.canonical.com/">https://status.canonical.com/</a></p><p>Q: ubuntu-gnome development git?<br>A: In Debian salsa: <a href="https://salsa.debian.org/gnome-team">https://salsa.debian.org/gnome-team</a><br> Ref: <a href="https://discourse.ubuntu.com/t/psa-ubuntu-gnome-packages-development-moved-to-debian-salsa/14900">https://discourse.ubuntu.com/t/psa-ubuntu-gnome-packages-development-moved-to-debian-salsa/14900</a></p><p>Q: debug symbols for ubuntu deb<br>A: Too long, refer to <a href="https://wiki.ubuntu.com/Debug%20Symbol%20Packages">https://wiki.ubuntu.com/Debug%20Symbol%20Packages</a></p><p>Q: Which release I can do-release-upgrade to?<br>A: Firt check your config file /etc/update-manager/release-upgrades, the value of Prompt could be nenvr, normal and lts.</p><p>As 22.04 released, it’s not exist in the meta-release-lts, but in meta-release-lts-development. You’ll need to command “do-release-upgrade -d” to upgrade from 20.04. (Ref: <a href="https://changelogs.ubuntu.com/">https://changelogs.ubuntu.com/</a>)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7a8d5e8dc87" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[tensorflow , pytorch + ubuntu focal 20.04 + conda]]></title>
            <link>https://ycheng-tw.medium.com/tensorflow-pytorch-ubuntu-focal-20-04-conda-42a086b36158?source=rss-afb1f12e9c17------2</link>
            <guid isPermaLink="false">https://medium.com/p/42a086b36158</guid>
            <dc:creator><![CDATA[Y.C Cheng / 鄭原真]]></dc:creator>
            <pubDate>Sat, 17 Apr 2021 13:45:06 GMT</pubDate>
            <atom:updated>2021-04-17T13:45:06.555Z</atom:updated>
            <content:encoded><![CDATA[<h3>tensorflow , pytorch + ubuntu focal 20.04 + conda</h3><p>I thought it’s trivial in the first place, but in the end, it’s not, but still simple if all parties do it right on compatibility!</p><p>There are so many combinations of NV card, driver, installation method, etc to make it maybe hopeless to just install. Well, then maybe it makes sense to have a place to just run and keep making sure it works. I believe it’s tested somewhere, maybe just not have one single place to have those all.</p><p>So, here it is:</p><p>Nvidia driver:</p><p>$ sudo apt-get install nvidia-driver-460 — no-install-recommends<br>$ sudo apt-get install nvidia-utils-460-server # to get nvidia-smi</p><p>For today, above install 460.56. Some previous versions might not work. I believe most new NV GPU can be supported by this one.</p><p>Conda: use python 3.8 miniconda</p><p>command to install PyTorch and TensorFlow</p><p>$ conda install pytorch torchvision torchaudio \<br> cudatoolkit=10.1 \<br> matplotlib jupyterlab ipywidgets \<br> tensorflow-gpu \<br> -c pytorch</p><p>That’s it.</p><p>Let me know if the above one does not work, I’ll try to see if I can do a test.</p><p>Some background:</p><p>PyTorch has a conda channel and supports many CUDA versions. For example, they have versions for cuda10 and cuda11 separately. For tensorflow, I check several conda channels but I simply can’t find any Tensorflow-gpu conda that consume cuda 11.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42a086b36158" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bug in Unicode output with R-4.0.4.pkg]]></title>
            <link>https://ycheng-tw.medium.com/bug-in-unicode-output-with-r-4-0-4-pkg-956f33a296dc?source=rss-afb1f12e9c17------2</link>
            <guid isPermaLink="false">https://medium.com/p/956f33a296dc</guid>
            <category><![CDATA[r-language]]></category>
            <dc:creator><![CDATA[Y.C Cheng / 鄭原真]]></dc:creator>
            <pubDate>Sun, 28 Mar 2021 04:45:46 GMT</pubDate>
            <atom:updated>2022-10-24T11:51:43.404Z</atom:updated>
            <content:encoded><![CDATA[<h3>[fixed] Bug in Unicode output with <a href="https://cran.csie.ntu.edu.tw/bin/macosx/R-4.0.4.pkg">R-4.0.4.pkg</a></h3><p>Note: this is fixed in R-4.0.5! Great!!!</p><p>This is a bug report against <a href="https://cran.csie.ntu.edu.tw/bin/macosx/R-4.0.4.pkg">R-4.0.4.pkg</a> downloaded from <a href="https://cran.csie.ntu.edu.tw/">https://cran.csie.ntu.edu.tw/</a></p><p>I install it on OSX 10.15.7. I found the Unicode character can’t be properly output unless use function like cat()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/0*neKbLZGp56nSaflb" /></figure><p>The Chinese character there means “good”. In this case, the default output is not ok. I also test the console mode, still can reproduce this issue.</p><p>I try to compile from source code with the Xcode on my machine, with</p><p>&gt; Apple clang version 12.0.0 (clang-1200.0.32.29)<br>&gt; Target: x86_64-apple-darwin19.6.0</p><p>&gt; + gfortran-8.2-Mojave.dmg<br>&gt; + pcre2–10.36.tar.bz2<br>&gt; + xz-5.2.5.tar.gz</p><p>run on the terminal, can’t reproduce this issue. Here is the screenshot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MK7q4LFnMPv8wiQW" /></figure><p>I also test this on Ubuntu 20.04, I can’t reproduce this issue.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=956f33a296dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Install 3 different tensorflow-gpu on the one Ubuntu machine.]]></title>
            <link>https://ycheng-tw.medium.com/install-3-different-tensorflow-gpu-on-the-one-ubuntu-machine-992190a13a42?source=rss-afb1f12e9c17------2</link>
            <guid isPermaLink="false">https://medium.com/p/992190a13a42</guid>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Y.C Cheng / 鄭原真]]></dc:creator>
            <pubDate>Sun, 26 May 2019 14:35:02 GMT</pubDate>
            <atom:updated>2019-09-27T08:19:17.909Z</atom:updated>
            <content:encoded><![CDATA[<h3>Install 3 different TensorFlow-GPU on the one Ubuntu machine.</h3><p>In this article, I’d like to share with you how to install TensorFlow 1.12, 1.13 and 2.x-nightly on the same Linux.</p><h3>Why?</h3><p>To run TensorFlow on Linux machine, you need to install</p><blockquote>nvidia driver<br>cuda toolkit library<br>cudnn library<br>tensorflow (with python)</blockquote><p>To get the maximum coverage, here are the supported versions:</p><blockquote>nvidia driver: 418</blockquote><blockquote>cuda toolkit 9.0 + cudnn 7.1.2 + python 3.6: tensorflow 1.12<br>cuda toolkit 10.0.130 + cudnn 7.6.0 + python 3.7: tensorflow 1.13<br>cuda toolkit 10.0.130 + cudnn 7.3.1+ python 3.7: tensorflow 2.x-nightly</blockquote><p>Ok, let’s deal with it.</p><h3>Install Nvidia driver on top of Ubuntu.</h3><p>Per writing this article, I am using Ubuntu 19.04 with Nvidia driver 418. I believe you can also use Ubuntu 18.04LTS with Nvidia driver 418. Please check the install Nvidia driver part in my article on <a href="https://medium.com/datadriveninvestor/install-tensorflow-gpu-to-use-nvidia-gpu-on-ubuntu-18-04-do-ai-71b0ce64ebc5">https://medium.com/datadriveninvestor/install-tensorflow-gpu-to-use-nvidia-gpu-on-ubuntu-18-04-do-ai-71b0ce64ebc5</a>.</p><p>The reason to use Nvidia driver 418 (or newer version) is to get the best Cuda compatibility. Check link <a href="https://docs.nvidia.com/deploy/cuda-compatibility/index.html#binary-compatibility__table-toolkit-driver">https://docs.nvidia.com/deploy/cuda-compatibility/index.html#binary-compatibility__table-toolkit-driver</a>.</p><p>You need to make sure the command nvidia-smi can properly output the status of your Nvidia GPU.</p><h3>Install anaconda</h3><p>Go</p><p><a href="https://www.anaconda.com/download/#linux">https://www.anaconda.com/download/#linux</a></p><p>And get the Python 3.7 version. I use this link</p><p><a href="https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh">https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh</a></p><p>Just run it, and accept it to change your ~/.bashrc so that adds the installation direction to your PATH. Re-login and then your environment will properly work.</p><h3>Conda environment</h3><p>We are going to install different tensorflow in their own conda environment. A conda environment is a standalone space that you can install a specific set of packages. In the case that you are going to install conflicting sets of packages, you need to create several environments. There are other tools can do similar things, however, from what I know, conda is the one that’s doing the best for now.</p><p>I am not going to dive into details on commands of conda environments. However here are what we will use:</p><blockquote>conda create env_name<br>conda activate env_name<br>conda deactivate env_name<br>conda env list<br>conda env remove — name env_name</blockquote><h3>Install tensorflow 1.12</h3><p>Fortunately, we can also install Cuda and cudnn via conda. The following is the command to install tensorflow 1.12 in conda environment with the name “tf12”. (I also add keras and h5py for convenient, you can remove it)</p><blockquote>$ conda create tf12<br>$ conda activate tf12<br>$ conda install -y \<br> cudatoolkit==9.0 \<br> cudnn==7.1.2 \<br> tensorflow-gpu==1.12 \<br> keras==2.2.4 \<br> h5py</blockquote><p>I think it’s fairly self-explain. Feel free to ask me questions if any.</p><h3>Tips for using conda</h3><p>You might want to put all commands into a script. If you try that, you will find the command “conda activate tf12” is not working properly there. Here is the solution. You need to put a command</p><blockquote>source $HOME/anaconda3/etc/profile.d/conda.sh</blockquote><p>before the “conda activate tf12” command, so it can work properly. The secret behind that is related to how the shell runs a command and how it can modify the shell environment it’s currently running.</p><p>Along the way of testing new environments, you might need to install the same package several times, and you might want to remove the $HOME/anaconda3 and do a clean re-install. You will find it very time-consuming because tensorflow, Cuda, and cudnn are quite large in size, it uses so much time to keep re-downloading those packages.</p><p>I create a directory $HOME/anaconda3-pkgs, and set environment variable by command:</p><blockquote>export CONDA_PKGS_DIRS=$HOME/anaconda3-pkgs</blockquote><p>before doing the installation. Without this change, the package tarball will be stored in $HOME/anaconda3/pkgs. So it’s hard for us to reuse it if we want to remove $HOME/anaconda3 and do the clean re-install again. With the above settings, the newly downloaded package will keep there. So you don’t need to re-download it the next time you want to use it.</p><h3>Put everything together</h3><p>To install tensorflow 1.12, use the following commands in your script:</p><blockquote>source $HOME/anaconda3/etc/profile.d/conda.sh<br>export CONDA_PKGS_DIRS=$HOME/anaconda3-pkgs</blockquote><blockquote>conda create tf12<br>conda activate tf12<br>conda install -y \<br> cudatoolkit==9.0 \<br> cudnn==7.1.2 \<br> tensorflow-gpu==1.12 \<br> keras==2.2.4 \<br> h5py</blockquote><p>To install tensorflow 1.13, use the following commands in your script:</p><blockquote>source $HOME/anaconda3/etc/profile.d/conda.sh<br>export CONDA_PKGS_DIRS=$HOME/anaconda3-pkgs</blockquote><blockquote>conda create tf13<br>conda activate tf13<br>conda install -y \<br> tensorflow-gpu==1.13.1</blockquote><p>To install tensorflow 2.x nightly, use the following commands in your script:</p><blockquote>source $HOME/anaconda3/etc/profile.d/conda.sh<br>export CONDA_PKGS_DIRS=$HOME/anaconda3-pkgs</blockquote><blockquote>conda create tf2x<br>conda activate tf2x</blockquote><blockquote>conda install -y \<br> pip \<br> cudatoolkit==10.0.130 \<br> cudnn=7.3.1</blockquote><blockquote># this need to install via pip<br>pip install tf-nightly-gpu-2.0-preview</blockquote><p>For tensorflow 2.x nightly, there still no conda package exists for it, so we need to use pip to install it.</p><h3>Conclusion</h3><p>Well, Python dependency is hard to manage, and conda makes it simple. Deep learning is hard, so let’s make it easier to setup.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=992190a13a42" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Install Tensorflow-gpu to use Nvidia GPU on Ubuntu 18.04 do AI !]]></title>
            <link>https://medium.datadriveninvestor.com/install-tensorflow-gpu-to-use-nvidia-gpu-on-ubuntu-18-04-do-ai-71b0ce64ebc5?source=rss-afb1f12e9c17------2</link>
            <guid isPermaLink="false">https://medium.com/p/71b0ce64ebc5</guid>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[nvidia]]></category>
            <category><![CDATA[gpu]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Y.C Cheng / 鄭原真]]></dc:creator>
            <pubDate>Wed, 03 Oct 2018 02:24:55 GMT</pubDate>
            <atom:updated>2019-06-05T10:28:59.652Z</atom:updated>
            <content:encoded><![CDATA[<h3>Install Tensorflow-GPU to use Nvidia GPU using anaconda on Ubuntu 18.04 / 19.04 do AI!</h3><p><strong>* Apr 29, 2019: updated for Tensorflow 1.13 released.<br>* </strong><a href="https://medium.com/@ycheng.tw/install-3-different-tensorflow-gpu-on-the-one-ubuntu-machine-992190a13a42">https://medium.com/@ycheng.tw/install-3-different-tensorflow-gpu-on-the-one-ubuntu-machine-992190a13a42</a> Install tensorflow-gpu 1.12/1.13/2.x on the same machine.</p><p>I will share the background of GPU and Deep Learning. Then how you install Nvidia driver and Tensorflow with GPU acceleration back-end on Ubuntu 18.04 LTS. The following steps also work for Ubuntu 19.04 with some tweak.</p><p>If you just want to know all the steps, you can skip to the section “Summary of steps”.</p><p>Deep Learning / Machine Learning is a big revolution in the computing world! The software today has not really changed too much compared to 10 years ago in it’s underlying design. It’s definitely more beautiful, faster and more convenient for us. However, Deep Learning/Machine Learning is changing the world in such a different way!</p><p>I found there are so many documents around explaining how to install Tensorflow-GPU on Ubuntu. There are good articles, and I learn from those, too. However, it seems none of those have wider enough coverage. That’s what I want to address this issue!</p><h3>Why GPU?</h3><p>GPU is one of the key components of this revolution that it can do without. Some scientists might say that there is nothing new in this AI revolution. Well, maybe partially. There are some theories that have been there for 10s of years, however, due to slow CPU and limited data, they won’t be as useful today.</p><p>You can install tensorflow without GPU as starting point to learn, however you will find that it takes too long to finish the computing, and then you want to use a machine with GPU or other HW acceleration.</p><p>Surely you may pay money so you can use GPU on the cloud server, but you could also want to have your own machine to do the proof of concept or smaller computing before you send it to cloud server.</p><p>Nvidia GPU has rather good cost-performance and rather lower entry price, etc. That’s why you will find lots of information about it.</p><h3>Why Tensorflow!</h3><p>Google is the company behind it, period. In the meantime, it’s the top choice among people doing AI. It has multiple back-ends. Nvidia GPU is the one that used most except people work for Google or using Google cloud server.</p><h3>Why Ubuntu!</h3><p>I’ll rather ask, why not? Ubuntu is the top choice on the public cloud server. It has a good Desktop/Laptop support. You can purchase a certificated machine that’s pre-install Ubuntu on the Market. One of the companies that sell lots of Pre-install Ubuntu is Dell, and Dell also contributes a lot to make sure their computer works well with Ubuntu, like push hardware vendor to provide drivers, etc.</p><h3>Get a machine with Nvidia GPU</h3><p>You might want to ask me how to choose one if you are going to buy a GPU card and plug-in to a PC. How big a memory should I choose?</p><p>IMHO, I’ll suggest you buy one entry-level GPU card with more memory. Why? Not all kind of Deep Learning algorithm can be effectively paralleled in a machine with multiple GPU cards. There will always be a computing/communication balance issue. For further information, you can check this article [1].</p><p>To know if your GPU is supported, check:</p><p><a href="https://developer.nvidia.com/cuda-gpus">https://developer.nvidia.com/cuda-gpus</a></p><p>Ok, here is the background: Tensorflow-GPU uses two software component from Nvidia to access Nvidia GPU. They are CUDA toolkit and cuDNN. If your GPU supports CUDA, then we shall be able to use it to do GPU accelerated tensorflow.</p><p>You could get a desktop machine that only has Nvidia GPU, however, if you get a laptop, usually you get a so-called “I+A” machine. An I+A machine is a design that you have both Intel GPU and Nvidia GPU installed on your machine. You can choose to use one of them by configuring your system.</p><h3>Install Ubuntu 18.04 / 19.04 on it!</h3><p>Finally, we are going to work on it… If you are using Ubuntu pre-install machine with Nvidia GPU, you can skip this part. Well, Dell Machine with Nvidia GPU that comes with 18.04 might not start to ship for today, believe me, it won’t take too long.</p><p>I think most people who read this article already know how to install Ubuntu, but if you don’t, check it in: <a href="https://www.ubuntu.com/">https://www.ubuntu.com/.</a> The steps are</p><p>1. Download the Ubuntu desktop iso image. For today it’s “ubuntu-18.04.1-desktop-amd64.iso”. Ubuntu 19.04 also works.<br>2. Either burn a CDROM or prepare a USB stick with the ISO file.<br>3. Boot your machine with it, and finish the installation. Usually, you won’t have trouble at this stage.<br>4. Reboot your machine!</p><p>Some people might have issues after reboot your machine. I have some tips that could help you out if you can’t properly login after reboot.</p><h3>Install Proprietary Nvidia Driver</h3><p>If you are using 19.04, just open a terminal, use the following command:</p><blockquote>sudo apt update<br>sudo ubuntu-drivers autoinstall<br>sudo reboot</blockquote><p>If it works well, you will install lots of deb packages, like “nvidia-driver-418”, etc. Then reboot your machine. If it successfully reboots, open a terminal and use command “nvidia-smi”. If it properly shows you the status of Nvidia GPU like below, then it’s already properly installed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*9s415TTXn403soyiQ5PDqw.png" /></figure><p>If you’ve been this far, you have finished the riskiest part of the installation process.</p><p>However, if the nvidia driver it installs is 390 (if you use 18.04), you need to manually install a newer version of nvidia driver. Why? Because we are going to use cuda 10.x, and it need newer nvidia driver.</p><blockquote>sudo add-apt-repository ppa:graphics-drivers<br>sudo apt-get update<br>sudo apt-get install nvidia-driver-418</blockquote><p>You can check the following link for the mapping of cuda and nvidia drivers.<br><a href="https://docs.nvidia.com/deploy/cuda-compatibility/index.html#binary-compatibility__table-toolkit-driver">https://docs.nvidia.com/deploy/cuda-compatibility/index.html#binary-compatibility__table-toolkit-driver</a></p><h3>Some troubleshooting tips</h3><p>There could be too many situations to handle. I’ll only share the most common one from my experience.</p><p>On an Intel GPU + Nvidia GPU (mostly this case when you use a Laptop with Nvidia GPU), sometime you just can’t log in after system installation, like system freeze after booting. If you are kind of Linux expert, I think the following step is enough for you, or we need another article to do a step by step guide.</p><ol><li>Add “module_blacklist=nouveau” to the Linux booting parameter as booting in GRUB. Usually, you will be able to login into the system with this.</li><li>Install the proprietary Nvidia driver mentioned in the previous section. Usually, after this, you can have properly working system after reboot. If not… well, you might have a special hardware combination that needs more work to make it work.</li></ol><h3>Make sure Nvidia is enable</h3><p>If you purchase an Ubuntu-pre-installed machine from a vendor like Dell, the Nvidia driver is already installed, but it’s not turned on by default.</p><p>Use the following command to make sure Nvidia GPU is enabled.</p><blockquote>$ sudo prime-select nvidia<br>$ sudo reboot</blockquote><p>After that, “nvidia-smi” will output the GPU status.</p><h3>We can install Tensorflow now!</h3><p>There are many ways to install tensorflow. If you are a heavy docker user, you might want the docker way:</p><p><a href="https://www.tensorflow.org/install/install_linux#InstallingDocker">https://www.tensorflow.org/install/install_linux#InstallingDocker</a></p><p>It’s fairly simple. Feel free to ask us questions if you have any.</p><p>Except that, I think the easiest way is using Anaconda. If you use Anaconda before, you must finish reading this article, or it won’t work. Why? Anaconda seems not so recommend in the tensorflow web site.</p><p>First, you need to install Anaconda. Go</p><p><a href="https://www.anaconda.com/download/#linux">https://www.anaconda.com/download/#linux</a></p><p>And get the Python 3.7 version. I use this link</p><p><a href="https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh">https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh</a></p><p>Just run it, and accept it to change your ~/.bashrc so that adds the installation direction to your PATH.</p><p>Previous we need to use the python 3.6. Tensorflow 1.13 upgrade to python 3.7. So we can just use the new one.</p><p>Here is the key part. Use the following command to install tensorflow-gpu 1.13:</p><blockquote>conda install \<br> tensorflow-gpu==1.13.1</blockquote><p>You might want to add other packages like keras, scikit-learn, panda or numpy. Just add it to the command line with or without version. Conda will let you review the operation as you doing the installation.</p><p>Previously, we also need to specify packages like cudatoolkit-10.0.130 and cudnn-7.3.1. For today, they will be installed automatically as a dependency.</p><h3>Verify installation</h3><p>Well, if you follow the step above, it works. However, you want to test it. On the tensorflow website, it suggests you use the following python code:</p><blockquote>import tensorflow as tf<br>hello = tf.constant(‘Hello, TensorFlow!’)<br>sess = tf.Session()<br>print(sess.run(hello))</blockquote><p>It works! However, it runs if you are using the CPU to do computing. How do you know if you are using the GPU? Try the following code:</p><blockquote>import tensorflow as tf<br>print(“tf version = “, tf.__version__)<br>with tf.device(‘/gpu:0’):<br> a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name=’a’)<br> b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name=’b’)<br> c = tf.matmul(a, b)</blockquote><blockquote>with tf.Session() as sess:<br> print (sess.run(c))</blockquote><p>The final result output will be</p><blockquote>tf version = 1.13.1<br>[[22. 28.]<br>[49. 64.]]</blockquote><p>plus lots of other tensorflow messages as tensorflow-GPU is doing internal initialization.</p><h3>Summary of steps</h3><ol><li>Install Ubuntu 18.04 / 19.04 Desktop.</li><li>Install Nvidia driver on a machine with a supported Nvidia card.</li></ol><blockquote>$ sudo apt update<br>$ sudo ubuntu-drivers autoinstall<br>$ sudo reboot</blockquote><p>If it installs nvidia-driver-390 (if you use 18.04), we need a driver version like 418. You can install via commands like</p><blockquote>sudo add-apt-repository ppa:graphics-drivers<br>sudo apt-get update<br>sudo apt-get install nvidia-driver-418</blockquote><p>3. You might need to switch to Nvidia GPU from Intel GPU by using</p><blockquote>$ sudo prime-select nvidia<br>$ sudo reboot</blockquote><p>4. Install Anaconda with python 3.7.</p><p><a href="https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh"><strong>https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh</strong></a></p><p>5. Install tensorflow-gpu</p><blockquote>$ conda install \<br> tensorflow-gpu==1.13.1</blockquote><p>6. You’re done.</p><h3>Conclusion</h3><p>There is so much to learn on the way of Machine Learning/Deep Learning. You need to have the domain knowledge to know your data. To know the mathematics behind so your trained model works and lots more. However, setting up a computer should be fairly easy. Hope this article gives you a quick way to prepare you Ubuntu to start with!</p><p>Reference:</p><p>[1] <a href="http://timdettmers.com/2018/08/21/which-gpu-for-deep-learning/">http://timdettmers.com/2018/08/21/which-gpu-for-deep-learning/</a></p><p>The old version of this article for reference:</p><p><a href="https://medium.com/@ycheng.tw/install-tensorflow-gpu-to-use-nvidia-gpu-using-anaconda-on-ubuntu-18-04-18-10-do-ai-ce4b5e2ae61b">https://medium.com/@ycheng.tw/install-tensorflow-gpu-to-use-nvidia-gpu-using-anaconda-on-ubuntu-18-04-18-10-do-ai-ce4b5e2ae61b</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71b0ce64ebc5" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/install-tensorflow-gpu-to-use-nvidia-gpu-on-ubuntu-18-04-do-ai-71b0ce64ebc5">Install Tensorflow-gpu to use Nvidia GPU on Ubuntu 18.04 do AI !</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>