A Mining and Machine Learning PC for $500

In my never-ending quest for the “next big thing” in technology, I’ve been dividing my time between cryptocurrency and machine learning. I’m still not sure about the long-term value of Bitcoin and other altcoins, but the tech they’re built on, such as blockchain and smart contracts, is fascinating.

At the same time, it seems like machine learning is set to take over the world. I’ve been working my way through a couple of online data science / machine learning / deep learning courses. I’m particularly interested in learning more about TensorFlow, Google’s machine learning library.

In order to speed up processing with TensorFlow, I decided to build a PC with a decent graphics card. When I’m not using this PC to run machine learning programs, I could use the video card to mine a few altcoins. Finally, worst case scenario, if both of these technologies fail I’ll have a decent computer for gaming.

The Hardware

My first step was finding a video card. TensorFlow uses the CUDA Toolkit from NVIDIA so that seemed like a good place to start. I also knew that to mine Ethereum, I needed at least 4GB of memory on the card. With that in mind, I ended up choosing the EVGA GeForce GTX 1050ti Video Card for $157.99. Not exactly top-of-the-line, but good enough to get started on a budget.

Now I needed a PC to hold this card. Again, I was trying to go cheap so I looked into refurbished computers. There’s an off-lease, refurbished computer store near my house. I was able to pick up a Dell computer there with a keyboard, mouse, and monitor for about $350.

I went with the Dell Optiplex 7010. The 3.2 GHz i5 processor is plenty fast for my needs, and the mini-tower case provides plenty of room for the video card. I also bought a TP-Link N150 USB Wireless Adapter since this computer didn’t have built-in wireless.

The Software

The computer came with Windows 10 (which is actually not terrible), but I knew I wanted to run Linux for my purposes. So, I shrank the primary partition on the hard drive and downloaded a copy of Ubuntu Desktop 16.04.3 LTS and created a bootable USB flash drive.

There are already plenty of resources online explaining how to set up a dual-boot Windows / Ubuntu system so I won’t cover that here. Let me know if you run into trouble and I’ll try to point you in the right direction.

Once Ubuntu is installed, make sure the video card is using the proprietary drivers. The open-source drivers won’t cut it for mining or machine learning. To check, go to System Settings, then Software & Updates, and click the Additional Drivers tab. After the tab loads, you should see that your video card is using the NVIDIA binary driver. If not, select it and click the Apply Changes button.

Ethereum Mining

Now that the operating systems are installed, I was ready to start setting up the rest of the software. I decided to test mining first. You can’t mine Bitcoin on a regular computer, so it was out of the question, but you can mine Ethereum.

With that in mind, first install Ethereum. This is easy to do on Ubuntu using the Ethereum PPA (Personal Package Archive). These instructions are from the Go Ethereum Wiki. First, open a terminal and enter these commands:

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum

This adds the Ethereum PPA to your system, updates the list of available packages, and installs the Ethereum software. Once that’s complete, enter the following command to create a new Ethereum account:

geth account new

Be sure to write down your password and keep it in a safe place. This account holds all of your ether. Without the password you won’t be able to access your money. Also, make a note of your address. That’s the number returned by the command between curly braces.

Now it’s time to install the miner. There are several choices for mining on the Ethereum network. After trying a few different options, I chose Claymore.

First, download the Claymore Dual Miner v10.0 from their releases page on GitHub. Make a new directory named claymore for the miner inside your home directory. Now move the downloaded file from your Downloads directory to the claymore directory and extract it by double clicking it.

Rather than try to mine solo, I decided to join a mining pool. Again, there are many choices available, but after some research I went with nanopool.org. Their 1% fee seemed reasonable, and you can get payouts after mining as little as 0.05 ether.

The nanopool.org getting started guide includes instructions for setting up Claymore on Linux. After correcting a few typos everything worked perfectly. First, I replaced the contents of the file start.bash with this:

export GPU_FORCE_64BIT_PTR=0
export GPU_MAX_HEAP_SIZE=100
export GPU_USE_SYNC_OBJECTS=1
export GPU_MAX_ALLOC_PERCENT=100
export GPU_SINGLE_ALLOC_PERCENT=100

~/claymore/ethdcrminer64 -epool eth-us-east1.nanopool.org:9999 -ewal 0xa375d885105db5df1f2452ef9e347f261eb3f690/Atone01/me@anthonylewis.com -mode 1

The number starting with 0xa375... is my Ethereum address. You should replace this with your own, unless you want me to get all the ether you mine. Following that is my worker name and then my email address. nanopool.org will use this to email you if your worker goes. It’s also used as a password to update settings.

Next, update the file epools.txt to setup failover servers:

POOL: eth-eu1.nanopool.org:9999, WALLET: 0xa375d885105db5df1f2452ef9e347f261eb3f690.Atone01/me@anthonylewis.com, PSW: x, WORKER: , ESM: 0, ALLPOOLS: 0
POOL: eth-eu2.nanopool.org:9999, WALLET: 0xa375d885105db5df1f2452ef9e347f261eb3f690.Atone01/me@anthonylewis.com, PSW: x, WORKER: , ESM: 0, ALLPOOLS: 0
POOL: eth-us-east1.nanopool.org:9999, WALLET: 0xa375d885105db5df1f2452ef9e347f261eb3f690.Atone01/me@anthonylewis.com, PSW: x, WORKER: , ESM: 0, ALLPOOLS: 0
POOL: eth-us-west1.nanopool.org:9999, WALLET: 0xa375d885105db5df1f2452ef9e347f261eb3f690.Atone01/me@anthonylewis.com, PSW: x, WORKER: , ESM: 0, ALLPOOLS: 0
POOL: eth-asia1.nanopool.org:9999, WALLET: 0xa375d885105db5df1f2452ef9e347f261eb3f690.Atone01/me@anthonylewis.com, PSW: x, WORKER: , ESM: 0, ALLPOOLS: 0

The format is similar to start.bash but slightly different. These servers will be used if the server you entered in start.bash goes down.

Now that these files are updated, you can open a terminal and start the miner by entering this command:

~/claymore/start.bash

The command will first build a DAG on your video card which takes a few seconds, then it will start getting jobs from nanopool.org and attempting to mine ether. Occasionally, you will see text in green on your terminal that says “SHARE FOUND” and then “Share accepted”. This means your mining worked and you just earned a little ether.

You can see my results by looking at my worker on nanopool.org. At around 12 Mh/second I’m certainly not going to get rich off of this miner, but $10-15 USD per month is better than nothing. It’s not often that I actually get paid to learn about a new technology.

Machine Learning with TensorFlow

Now that Ethereum mining is working, I moved on to installing TensorFlow. The TensorFlow website has great documentation for Installing TensorFlow on Ubuntu, but there a few gotcha’s in the documentation.

Install NVIDIA Requirements

The first requirement for using TensorFlow with a GPU is the CUDA Toolkit from NVIDIA. The current required version is 8.0, but the latest version on NVIDIA’s site is 9.0. TensorFlow currently will not work with the latest version.

Once I had the versions worked out, CUDA is easy to install. The first step is to add the CUDA repository to your system. Rather than doing it manually as with Ethereum, CUDA provides a .deb package to do this for you.

You can download the base installer by going to CUDA Toolkit 8.0 Download Page and answering a few questions, or skip the questions and click this link to get the CUDA Repo for Ubuntu 16.04.

Once you download the file, open a terminal, go to the Downloads directory, and enter these commands:

sudo dpkg -i cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda

The next requirement is the CUDA Deep Neural Network library. This download requires a membership in the NVIDA Developer Program. Thankfully, it’s free. Go to the cuDNN Download page, and signup or login as required.

Click to expand the section labeled “Download cuDNN v6.0 (April 27, 2017), for CUDA 8.0”. In that section are three .deb files to download for Ubuntu 16.04:

  1. cuDNN v6.0 Runtime Library for Ubuntu16.04
  2. cuDNN v6.0 Developer Library for Ubuntu16.04
  3. cuDNN v6.0 Code Samples and User Guide for Ubuntu16.04

After downloading those three files, open a terminal, go to the Downloads directory, and enter these commands:

sudo dpkg -i libcudnn6_6.0.20-1+cuda8.0_amd64-deb
sudo dpkg -i libcudnn6-dev_6.0.20-1+cuda8.0_amd64-deb
sudo dpkg -i libcudnn6-doc_6.0.20-1%2Bcuda8.0_amd64-deb

Finally, install the NVIDIA CUDA Profile Tools Interface:

sudo apt-get install libcupti-dev

Now that CUDA is installed, edit the ~/.profile file to update the PATH and LD_LIBRARY_PATH environment variables with new paths. The last two lines of the file should look something like this:

# set PATH so it includes user's private bin directories
PATH="$HOME/bin:$HOME/.local/bin:/usr/local/cuda/bin:$PATH"

# add CUDA to LD_LIBRARY_PATH
export LD_LIBRARY_PATH="/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"

If you’ve been following along, just add /usr/local/cuda/bin between colons to the PATH, and add the line with export LD_LIBRARY_PATH=... at the end of the file.

Install TensorFlow

With all of the NVIDIA requirements in place, it’s finally time to install and test TensorFlow. I decided to use the recommended virtualenv installation method.

First, install pip and virtualenv for Python 3 with this command:

sudo apt-get install python3-pip python3-dev python-virtualenv

Once the installation is done, create a virtualenv for TensorFlow with this command:

virtualenv --system-site-packages -p python3 ~/tensorflow

Then activate the newly created virtualenv.

source /tensorflow/bin/activate

The prompt should now start with (tensorflow). Remember to activate this virtualenv every time you want to work with TensorFlow.

Now ensure that pip is installed inside the virtualenv:

easy_install -U pip

And finally, install TensorFlow with GPU support:

pip3 install --upgrade tensorflow-gpu

Note that you don’t need to use sudo in front of the commands inside the virtualenv since these installations only affect the current user.

Now run a short program to verify TensorFlow is working. Launch the python interactive interpreter:

python

Then enter this short program:

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

If everything is setup correctly, this should simply print Hello, TensorFlow!.

And with that you have a $500 PC ready for learning about Ethereum mining and using TensorFlow for machine learning.

You Are the Product

I’m becoming more disillusioned with social media every day. I recently came across this article on the London Review of Books thanks to Longform.org. It does a great job of capturing and reenforcing many of my thoughts. Here are a few choice quotes:

… anyone on Facebook is in a sense working for Facebook, adding value to the company. In 2014, the New York Times did the arithmetic and found that humanity was spending 39,757 collective years on the site, every single day.

Everyone actively using Facebook provides content. Facebook makes money by selling ads next to content.

Since the Facebook button is pretty much ubiquitous on the net, this means that Facebook sees you, everywhere.

Search for something on Amazon, then visit Facebook. But maybe the targeted ads don’t bother you or you feel that it’s worth it to stay in touch with friends and family.

… researchers found quite simply that the more people use Facebook, the more unhappy they are. A 1 per cent increase in ‘likes’ and clicks and status updates was correlated with a 5 to 8 per cent decrease in mental health.

So, in an effort to maintain my mental health, I did this:

If you can’t join me, it might already be too late for you…

» You Are the Product

Chris Cornell

What a tragic loss for music fans everywhere. Especially fans around my age.

Here’s an acoustic performance by Chris Cornell of the U2 song One while he sings the lyrics from the Metallica song One. Amazing.

I came across this video while browsing some of the live tributes to Chris Cornell performed by other bands. Unfortunately, most of these are low-quality bootlegs, but he obviously touched and inpired a lot of other musicians.

Seveneves

I finally finished Seveneves last night. I’ve been a fan of Neal Stephenson’s writing for years, going all the way back to Snow Crash. Seveneves did not disappoint.

If you’re familiar with Stephenson’s other work then you already know this is a dense, thick book. It’s 850+ pages filled with dizzying details about current and future technology. Stephenson does his homework. He deals with everything from robotics and orbital mechanics to nuclear power and even genetics. All of these complex subjects are seamlessly interwoven with a compelling story.

The book is divided into three parts. It might be better to think of it as a trilogy rather than a single book. Especially when you learn that part three starts with “Five thousand years later.” It’s here that Stephenson’s imagination runs wild and his talent really shines. His vision of the far future is fantastical, but explained so precisely and thoroughly that it is somehow still believable.

This is not a book to be undertaken lightly. It will take a while to finish, even for the fastest readers. But if the idea of an adventure spanning generations with a believable cast of characters and amazing settings sounds intriguing, you can’t go wrong with Seveneves.

The Vanishing Middle Class

A few days ago Jason Kottke linked to this review of a new book on the growing economic divide.

As someone who worked full time through college and financed classes and books with the help of my wife and our credit cards, I can relate. Passages like this bring back memories:

Here, the world of possibility is shrinking, often dramatically. People are burdened with debt and anxious about their insecure jobs if they have a job at all. Many of them are getting sicker and dying younger than they used to. They get around by crumbling public transport and cars they have trouble paying for. Family life is uncertain here; people often don’t partner for the long-term even when they have children. If they go to college, they finance it by going heavily into debt. They are not thinking about the future; they are focused on surviving the present. The world in which they reside is very different from the one they were taught to believe in. While members of the first country act, these people are acted upon.

Thankfully, that was almost 14 years ago and my family has moved on. For others, the situation is only getting worse.

I believe there are those in the “first country” who are willing to help (I like to think I’m one of them), but the current political climate makes this almost impossible.

» America is Regressing into a Developing Nation for Most People

Interesting Reads

I’m paid to spend my days staring at a softly glowing LCD. In the midst of writing code and attending meetings, I also browse the web. Most people would consider me an old-school web surfer. I still follow blogs and read posts in an RSS reader (Feedly if you must know).

I realize that long-form writing has mostly fallen out of favor, but I still enjoy it. As a matter of fact, I frequently come across articles that I feel need to be shared with the world. In the past, I’ve posted these articles on Facebook or Twitter, but I find that the less time I spend in the social media cesspool, the better I feel.

Having said all that, I plan to start adding links to articles that I particularly enjoy to this site. I’ll probably include a pithy comment along with a qoute or two. My interests are fairly varied — I still read a lot about programming, but trending towards more Python for data science and machine learning. I’m also interested in the current political situation and its effect on economics and the world.

If your interests overlap mine, you might enjoy some of the same articles. If not, feel free to keep on scrolling.

Hello Jekyll

If you’re reading this, then the migration from WordPress to Jekyll is complete. WordPress is a great blogging platform, but it just doesn’t fit the way I work anymore. I spend my days using git and GitHub and everything I write is plain text in Markdown.

With Jekyll I can write posts using Markdown in my favorite text editor, Byword on iOS or Atom on everything else, then commit to GitHub to update the blog. Hopefully this will result in more frequent updates, but no promises…

Where Are The Comments?

I’m very grateful for all of the awesome comments I’ve received over the years. Unfortunately, comment spam is still a big problem. Even with tools like Akismet to filter comments, some manual labor is still required. Here are the numbers for my blog as of today:

Wordpress Spam

That’s right – there are 123 comments on the site and 170,348 were blocked as spam. There are also 94 comments that might be spam. Those need my attention. I exported all of the non-spam comments from the old WordPress blog. Those may come back someday, but probably not. In the mean time, you can find my contact information at the bottom of every page.

Unfollowing Users

A few readers have also asked me to add an Unfollow button for the sample social network in Rails Crash Course. Here’s how I made that happen:

I created a new branch called unfollow-user and added the Unfollow button.

Here are the steps I followed:

  1. Update config/routes.rb to include a route for unfollow_user. Since this removes a row from the database, I used the DELETE HTTP verb.
  2. Add an unfollow! method to app/models/user.rb, similar to the follow! method.
  3. Add an unfollow action to app/controllers/users_controller.rb, similar to the follow action.
  4. Add a Unfollow button to the view at app/views/users/show.html.erb. I also added some logic to show the correct button.

The changes are in this commit: 29fa67a

Hope this helps!

Destroying Comments

A reader asked if I could add the destroy action to CommentsController for the sample blog in Rails Crash Course. The changes are summarized below.

I created a new branch called comments-destroy and then added the destroy action.

Here are the steps I followed:

  1. Update config/routes.rb to include a route for comments destroy
  2. Add a destroy method to app/controllers/comments_controller.rb
  3. Add a Destroy link to the comment partial at app/views/comments/_comment.html.erb

The changes are in this commit: f410496

Note this is the same as Exercise 3 at the end of Chapter 5. The answers for all exercises are in the back of the book.

Hope this helps!

No “Getting Started” Tonight

The Getting Started with Ruby on Rails workshop has been cancelled due to lack of signups. That’s a shame, I was really looking forward to this one. Obviously I didn’t do the best job of getting the word out about this event.

Let me know if you were also looking forward to it and I’ll see if I can set up another session in the future. Another alternative might be something like a screencast or Google Hangout.