4.6 GPU计算
到目前为止,我们一直在使用CPU计算。对复杂的神经网络和大规模的数据来说,使用CPU来计算可能不够高效。在本节中,我们将介绍如何使用单块NVIDIA GPU来计算。所以需要确保已经安装好了PyTorch GPU版本。准备工作都完成后,下面就可以通过nvidia-smi
命令来查看显卡信息了。
!nvidia-smi # 对Linux/macOS用户有效
Copy to clipboardErrorCopied
输出:
Sun Mar 17 14:59:57 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.48 Driver Version: 390.48 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 1050 Off | 00000000:01:00.0 Off | N/A |
| 20% 36C P5 N/A / 75W | 1223MiB / 2000MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
±----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1235 G /usr/lib/xorg/Xorg 434MiB |
| 0 2095 G compiz 163MiB |
| 0 2660 G /opt/teamviewer/tv_bin/TeamViewer 5MiB |
| 0 4166 G /proc/self/exe 416MiB |
| 0 13274 C /home/tss/anaconda3/bin/python 191MiB |
±----------------------------------------------------------------------------+Copy to clipboardErrorCopied
可以看到我这里只有一块GTX 1050,显存一共只有2000M(太惨了😭)。