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.
在深度学习和人工神经网络(ANN)的世界中,硬件一直是讨论的主要主题。 由于使用了TensorFlow之类的软件包,GPU能够加快训练速度并提供更精确的准确性得分; 但是,它们通常带有很高的价格标签。 在此博客中,我希望概述图形卡的世界,并为尝试在预算内学习ANN的人们提供替代方法。
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.
在开始安装和使用PlaidML之前,我想讨论一下图形卡的重要性以及它们为什么在深度学习中得到广泛使用。 在每个专用的图形卡中,都有一块板(类似于母板),专用的冷却风扇和一个处理单元(类似于CPU)。 之所以对深度学习如此有用,是因为它为研究人员提供了一次运行多个进程的能力,同时释放了CPU的工作负载-从而可以更快地进行计算并提高CPU周期的效率。 如今,经常在深度学习之后流行的一个名字是Nvidia,这是一家专门从事GPU硬件的公司。 Nvidia在深度学习领域如此受欢迎的一个原因是,该公司提供了可以进行此类培训的软件。 例如,GPU的传统用途往往是用于图形处理,例如游戏,图形设计和视频编辑。 关于神经网络的问题是大多数图形卡都是创建的,因此可以为它们提供有关如何处理视频的说明。 英伟达已经在这里成为了一个重要的参与者,因为他们已经创建了自己的硬件,因此可以向其提供各种不同的指令,这些指令不仅与视频或游戏的处理方式有关。 尽管Nvidia在提供用于深度学习的软件方面处于领先地位,但出于同样的原因,它们还拥有比竞争对手更昂贵的产品。
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.
我可能只是一个典型的狂热分子,但我一直都是AMD。 如果您从未听说过AMD,那么这家公司不仅专注于CPU,还专注于GPU。 在过去的几年中,他们已经能够扩展其产品,使其表现超越英特尔等大型企业,甚至在某些情况下还超越了Nividia。 这里唯一的问题是AMD并没有将重点放在深度学习上,而是将重点更多地放在了诸如游戏和图形设计之类的计算机性能上。
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.
我之所以如此热爱AMD是因为我是一名内心的游戏玩家。 在开始学习深度学习和神经网络之前,我真的很喜欢计算机硬件,以便提高在Fortnite和League of Legends等游戏中的性能。 与其他许多游戏玩家一样,我遇到的问题是,由于游戏计算机内置的硬件,价格通常比传统计算机和游戏机高得多。 话虽这么说,但考虑到现代Intel CPU的价格在200-1000美元之间,而Nividia GPU的价格在500-1200美元之间,我有些灰心。 请记住,这些只是构建计算机所需的6或7部分中的2部分。 但是,随着我进行越来越多的研究,我开始更多地了解AMD如何利用其竞争对手的价格来获得优势。 AMD公司提供的硬件是相同的,如果没有更好的性能,那么这些领先其他品牌,但对于价格的一小部分 。 经过几个月的研究,我最终购买了Ryzen 7 2700x 8核CPU(200美元)和RX 580 8gb GPU(220美元)。 为了将它们与竞争对手进行比较,英特尔提供了一个8核CPU,价格为$ 350 +,而Nvidia提供了具有几乎相同性能的GPU,价格为$ 400 +。 因为有了AMD,我才能够制造出自己的计算机,该计算机功能强大且成本大大低于使用Intel或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.
但是,一旦我开始全面学习深度学习和数据科学,我就很失望地看到TensorFlow和其他流行的软件包只能与NVIDIA的技术CUDA内核一起使用。 这对我来说毫无意义,因为Nvidia和AMD之间的性能如此之小,以至于您在玩计算密集型视频游戏时几乎感觉不到差异,那么为什么不能在AMD GPU上进行深度学习呢? 答案不是因为他们没有能力或没有竞争对手,而是因为AMD并没有像Nvidia那样真正花费金钱或人力来开发这类软件。
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,这是我使用过的最好的开源库。 PlaidML允许人们像使用Nvidia显卡一样,以相同的方式利用其Intel和AMD硬件。 与TensorFlow一样,PlaidML也是Keras的后端,允许在您的图形卡而不是CPU上进行计算。 在本教程中,我将向您展示如何设置PlaidML,以及与仅使用CPU相比,它如何可以将训练速度提高近四倍或更多。
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:
在您的终端中,使用以下命令安装PlaidML:
pip install -U plaidml-keras
点安装-U plaidml-keras
After installing PlaidML, you must configure the hardware in your computer by typing the following into your terminal:
安装PlaidML之后,您必须通过在终端中键入以下内容来配置计算机中的硬件:
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:
当出现此消息提示时,键入y(是),然后按Enter。 然后,将提示您另一个屏幕,该屏幕显示您必须选择的不同选项。 它看起来应该像这样:
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.
我当前计算机上的图形卡是Intel HD Graphics4000。这看起来可能与您在终端中看到的有所不同,但是无论哪种方式,请使用OpenCL选择选项,然后按Enter。
And that’s it!!
就是这样!!
After you have PlaidML installed, run the following code:
安装PlaidML之后,运行以下代码:
After running the cell above, you should see the following:
运行上面的单元格后,您应该看到以下内容:
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.
如您所见,我们没有将TensorFlow作为后端显示,而是成功将其更改为PlaidML。 现在,每当您使用神经网络运行单元时,它将使用您在设置过程中指定的图形卡而不是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”.
我想指出的是,本教程是在Mac OS上完成的。 在运行Windows 10的我的游戏计算机上,这有点棘手。 如果您使用的是Windows计算机,请按照与Mac相同的步骤进行操作。 如果您在上方运行该单元,但仍显示TensorFlow后端,则必须找到keras.json文件,并将后端从“ TensorFlow”更改为“ 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).
尽管此软件包可以帮助将培训速度提高4倍或更多,但是根据所使用的图形卡,您仍然可能会遇到内存问题。 我还想指出,很多笔记本电脑和台式机都不是用来处理此类计算的,因此,我建议安装用于监视计算机内部温度的第三方软件。 如果您训练超过30分钟,并且看到您的CPU或GPU超过90–100度,我将停止训练并寻找另一种方法,因为您不想损坏计算机(尤其是使用Mac…。工业冷却)。
翻译自: https://towardsdatascience.com/plaidml-deep-learning-on-a-budget-ce22b58ba8c2