The world’s leading publication for data science, AI, and ML professionals.

PlaidML: Deep Learning on a Budget

PlaidML allows people to utilize their Intel and AMD hardware the same way you would if you had a Nvidia graphics card

In the world of deep learning and artificial neural networks (ANN), hardware has always been a major topic of discussion. Thanks to packages such as TensorFlow, GPUs have been able to accelerate training and offer more precise accuracy scores; however, they often come with a hefty price tag. In this blog, I hope to outline the world of graphics cards as well as offer alternatives for people trying to learn ANNs on a budget.


Before I get into installing and using PlaidML, I want to discuss the importance of graphics cards and why they are widely used in Deep Learning. In every dedicated graphics card, there is a board (similar to a motherboard), dedicated cooling fans, and a processing unit (similar to a CPU). The reason this is so helpful for deep learning is that it offers researchers the ability to run multiple processes at once, while simultaneously freeing CPU workloads – which in turn allows for faster computations and more efficient CPU cycles. Today, a popular name that often follows deep learning is Nvidia, a company that specializes in GPU hardware. One reason Nvidia is so popular in the field of deep learning is that the company offers software that allows for this type of training. For example, traditional uses for GPUs tend to be for graphic processing, such as gaming, graphic design, and video editing. The issue when it comes to neural networks is that most graphics cards are created so they can be given instructions for how to process video. Nvidia has become a big player here because they have created their hardware so that it can be given various different instructions that don’t only have to do with how a video or game is being processed. Although Nvidia is a leader for providing software for deep learning, they also have more expensive products than their competitors for this same reason.

RTX & GTX Graphics Card (Photo Credit: Nana Dua)
RTX & GTX Graphics Card (Photo Credit: Nana Dua)

I might just be a typical fanboy, but I am AMD all the way. If you’ve never heard of AMD, they are a company that specializes not only in CPUs, but GPUs as well. In the last few years they have been able to scale their products to outperform big players such as Intel, and in some cases Nividia as well. The only problem here is AMD has not focused on deep learning, and focuses more on computer performance for things such as gaming and graphic design.

The reason I love AMD so much is that I am a gamer at heart. Before I started learning about deep learning and neural networks, I was really into computer hardware in order to increase my performance in games such as Fortnite and League of Legends. The problem I had, like many other gamers, is that gaming computers are often priced much higher than traditional computers and gaming consoles due to the hardware they pack inside. That being said, I was a little discouraged considering modern Intel CPUs can cost between $200–$1000 while Nividia GPUs cost between $500–$1200. And remember, these are just 2 of the 6 or 7 parts you would need to build a computer. However, as I did more and more research, I started learning more about how AMD uses its competitor’s prices to their advantage. AMD offers hardware that is identical, if not better in performance then these other leading brands, but for a fraction of the price. After doing months of research, I ended up buying the Ryzen 7 2700x 8-core CPU ($200) and the RX 580 8gb GPU ($220). To compare these with their competitors, Intel offers an 8-core CPU that is priced at $350+ while Nvidia offers GPUs with an almost identical performance for $400+. Because of AMD, I was able to build my very own computer that is powerful and costed much less than if I had gone with Intel or Nvidia.

However, once I started getting into deep learning and data science in general, I was very disappointed to read that TensorFlow and other popular packages are only capable of working with CUDA cores – Nvidia’s technology. This made no sense to me because performances between Nvidia and AMD are so minuscule that you can barely feel the difference when playing computationally-intensive video games, so why can’t you do deep learning on AMD GPUs? The answer here is not because they are not capable or lesser than their competitors, but because AMD has not really spent the money nor manpower into developing these types of software like Nvidia has done.

This brings me to PlaidML, the best open-source library I have ever used. PlaidML allows people to utilize their Intel and AMD hardware the same way you would if you had a Nvidia Graphics Card. Like TensorFlow, PlaidML sits as a backend for Keras, allowing for computations to take place on your graphics card rather than your CPU. In this tutorial, I will show you how to set up PlaidML, and how it can speed up training by almost 4x or more than compared to using just your CPU.

PlaidML Logo (Github)
PlaidML Logo (Github)

Before typing in the code below, I recommend creating a virtual environment so that you can isolate these changes in case you want to revert back to the old version.

In your terminal, install PlaidML using:

pip install -U plaidml-Keras

After installing PlaidML, you must configure the hardware in your computer by typing the following into your terminal:

plaidml-setup

When being prompted with this message, type in y (yes) and press enter. You will then be prompted with another screen showing the different options you have to choose from. It should look like this:

The graphics card on my current machine is Intel HD Graphics 4000. This may look different then what you see in your terminal but either way, select the option with OpenCL then press enter.

And that’s it!!

After you have PlaidML installed, run the following code:

After running the cell above, you should see the following:

Using PlaidML as Keras backend
Using PlaidML as Keras backend

As you can see, instead of showing TensorFlow as the backend, we successfully changed it to PlaidML. Now, whenever you run a cell with a neural network it will utilize the graphics card you specified during setup instead of your CPU.

I want to note that this tutorial was done on Mac OS. On my gaming computer which runs on Windows 10, this was a little bit trickier to accomplish. If you are using a Windows machine, follow the same steps as you would with Mac. If you run the cell above and it still says TensorFlow backend, then you must find the keras.json file and change the backend from "TensorFlow" to "plaidml.keras.backend".

Although this package will help speed up training by 4x or more, you still might run into memory issues depending on what graphics card you are using. I also want to point out that a lot of laptops and desktops are not made to handle such computations, so I would recommend installing third-party software that monitors temperatures within your computer. If you are training for more than 30 minutes and see either your CPU or GPU go above 90–100 degrees, I would stop the training and find an alternative method as you do not want to damage your computer (especially with macs…. the worst cooling in the industry).


Related Articles