This post is meant to serve as a tutorial for building a deep learning computer capable of paying for itself. This post covers:
- A computer build that works for both deep learning and cryptocurrency mining
- How to determine which cryptocurrency to mine
- A docker file to start mining Zcash on Flypool (or Zclassic on Supernova)
- How to think about the economics and risks of mining cryptocurrencies
I first heard about deep learning while reading the winner’s interview for Kaggle’s Merck Molecular Activity Challenge. Prior to this result, Kaggle competitions were primarily won by random forests, gradient boosting machines, feature engineering, and a heavy dosage of ensembling. Despite this seemingly miraculous result I procrastinated adding deep learning to my machine learning toolbox. Partly because Theano and Torch, popular deep learning libraries at the time, had steep learning curves and because GPUs were (and still are) expensive. Deep learning was not accessible from a time or money standpoint.
The field is growing and deep learning is more accessible than ever. Libraries like Keras and fastai take the verbosity out of coding and MOOC courses such as Jeremy Howard and Rachel Thomas’ fast.ai have made getting started quick and painless. GPUs can now be purchased on-demand from a variety of cloud providers (Google Cloud, Azure, AWS, Crestle, FloydHub, Paperspace, etc.) and as competition increases the prices decrease.
Having access to GPUs in the cloud is convenient but the costs are still high relative to building a computer yourself. Aside from cost savings, building a computer is going to have superior performance and it is fun. For me, I wasn’t sure if I would run enough deep learning experiments to justify the up-front cost. Luckily, the current economics of cryptocurrency mining are so good that you can build a computer that will likely pay for itself and may even turn a profit. If you have been thinking about building a computer, or already have and are interested in recouping your costs, I hope this post will help you.
How to Mine Cryptocurrencies with Your Deep Learning Machine
Step 1. Build a computer.
There are many guides online covering how to build a deep learning computer which I followed to design my build. I initially intended to get a single GPU but the current economics of cryptocurrency mining (more on that later) pushed me to get two. I decided on a pair of 1080tis from Corsair that aren’t on my parts list. Pro Tip: If Corsair is out-of-stock then send a nice email asking when more will be available and start checking the website each day. Corsair GPUs come with built-in water cooling which is nice considering the GPUs are running 100% of the time.
My build is not optimized for mining cryptocurrencies (e.g. six GPUs in an open-air case with a cheap motherboard, small hard drive, and minimal RAM), but it is optimized for deep learning while still being a profitable miner. To make it useful for deep learning (and data science in general) I picked a good CPU with water cooling (CPU water cooling is unnecessary but why not!) a Samsung 960 M.2–2280 SSD for quickly reading and writing data sets , and 32 GB of RAM.
The most time-consuming aspect of the build was placing the radiators and fans. Researching fan placement turned up conflicting suggestions so I stuck with the rule-of-thumb that air should move from front to back and bottom to top. The CPU radiator is on the front and pulls air in along with a fan on the bottom. The GPU radiators are located on the top and back and configured to push air out (image below). The GPU water cooling fans (different from the fans on the actual GPU) are not controlled according to the GPU temperature and had to be manually set to 100%. The fans are noisy, so I keep the computer in a different room and access it via SSH. The GPUs have stayed below 50 C with no issues.
I prefer Linux for data science and installed Ubuntu for my OS. This script provided by fast.ai can be followed to get up and running for deep learning.
Step 2. Decide on a cryptocurrency to mine.
Your computer can be used for mining cryptocurrencies when not running deep learning experiments because the GPUs used in deep learning are efficient at computing the Equihash algorithm. Pro Tip: Don’t try to mine cryptocurrencies and perform deep learning simultaneously. It will work but the performance of deep learning will drop by as much as 90%.
Any cryptocurrency using the Equihash algorithm is a candidate for mining. Determine which currency to mine by checking whattomine.com, select the Equihash algorithm and for a 1080ti set the hash rate to ~720 h/s and the power to 250 W. Check your power bill to see what you pay per KWh. If using a different GPU, then check these benchmarks for the hash rate and power usage. At the time of writing Zclassic is the best option for Equihash mining.
When I began, in July 2017, Zcash (ZEC) was the most profitable to mine but that has changed to Zclassic (ZCL). I occasionally switch between currencies as the profitability changes. Be sure the cryptocurrency you select is supported by an exchange or will it be difficult to sell.
Step 3. Setup an address/wallet to mine to.
Mining requires having an address to send the rewards to. For Zcash, an address can be set up by hosting a node, downloading a wallet, or mining directly to an exchange. I mine directly to exchanges, Kraken and Bittrex, because it is simple — not because I trust them or think it is the safest option. Warning: crypto exchanges have been hacked in the past resulting in stolen balances. If you plan to store coins then please do your homework!
Step 4. Start Mining!
Mining cryptocurrencies is like a lottery. Simplistically, computers guess random numbers and when one finds a suitable number a “block is mined” and the finder gets a reward. The more guesses the better the odds. More and better GPUs results in more guesses. A currency like Bitcoin or Zcash automatically adjusts the “difficulty” of the lottery so someone mines a block every 10 minutes (checkout the original Bitcoin paper to learn how it actually works). As more miners join the network the difficulty goes up causing your share of future rewards to go down and vice versa. With two 1080tis it will take, on average, over a year to mine a Zcash block.
Mining pools, for a fee of ~1%, allow you to earn a portion of each reward won by the pool according to your contribution thereby drastically reducing the variance of receiving rewards. For Zcash I use flypool and for Zclassic I use supernova. Warning: mining pools have been known to steal your coins or not distribute a fair share of the reward — I haven’t rigorously vetted these pools, but their reviews are generally positive.
I use a simple Docker image for mining. Be sure to change the addresses in the Makefile otherwise mining rewards will be sent to me!
Results and Risks
The economics of cryptocurrency mining are driven by the price of the currency (higher is better) and the difficulty of the network (lower is better). The cost of power is also important but electricity costs are predictable and simple to account for. If the price of Zcash drops, or difficulty increases, mining may no longer be profitable. The primary risk is owning rapidly depreciating hardware without a profitable cryptocurrency to mine. Building a single 2 GPU computer has low risk — the worst-case scenario is having a nice workstation. Building several 6 GPU miners increases your risk (and also your profit). Due to the current profit margins, we should expect some combination of higher difficulties (thanks to posts like this), lower prices, and higher electricity costs in the future.
If we assume the price and difficulty never change then the payback time was 18 months in July 2017. In reality, the price and difficulty change constantly. If mined rewards are sold immediately the average price and difficulty is realized. Rewards can also be held or exchanged for the currency of a different project. The decision to hold, exchange, or sell mined cryptocurrencies can make or break the profitability. In July 2017, I spent $3000 on my deep learning computer and engaged in a mix of holding, exchanging, and selling rewards. Thanks to some luck, my machine paid for itself in six months. I prefer to sell enough of the mined rewards to cover liabilities. In the US, mining cryptocurrencies is taxable — please consult a tax professional.
I hope I have encouraged a few people to build their own deep learning/mining computers. Post your stories in the comments!
Source: Deep Learning on Medium