【发布时间】:2023-03-14 19:43:01
【问题描述】:
文档说,当使用 TensorFlow 后端时,如果检测到 Keras 会自动在 GPU 上运行。我登录到远程 GPU,并尝试运行 Keras 程序,但出于某种原因我只使用 CPU。如何强制我的 Keras 程序在 GPU 上运行以加快速度?
如果有帮助,模型如下所示:
model = Sequential()
model.add(SimpleRNN(out_dim, input_shape = (X_train.shape[1], X_train.shape[2]), return_sequences = False))
model.add(Dense(num_classes, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer = "adam", metrics = ['accuracy'])
hist = model.fit(X_train, dummy_y, validation_data=(X_test, dummy_y_test), nb_epoch = epochs, batch_size = b_size)
这是which python 的输出以及 Keras 正在使用 TensorFlow 后端的证明:
user@GPU6:~$ which python
/mnt/data/user/pkgs/anaconda2/bin/python
user@GPU6:~$ python
Python 2.7.12 |Anaconda custom (64-bit)| (default, Jul 2 2016, 17:42:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import keras
Using TensorFlow backend.
这是nvidia-smi 的输出。我有几个类似上面的进程正在运行,但它们只使用 CPU:
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 367.57 Driver Version: 367.57 |
|-------------------------------+----------------------+----------------------+
| 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 TIT... Off | 0000:03:00.0 Off | N/A |
| 26% 27C P8 13W / 250W | 9MiB / 6082MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 1 GeForce GTX TIT... Off | 0000:83:00.0 Off | N/A |
| 26% 31C P8 13W / 250W | 9MiB / 6082MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 2 GeForce GTX TIT... Off | 0000:84:00.0 Off | N/A |
| 26% 31C P8 14W / 250W | 9MiB / 6082MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 2408 G Xorg 9MiB |
| 1 2408 G Xorg 9MiB |
| 2 2408 G Xorg 9MiB |
+-----------------------------------------------------------------------------+
我的所有进程都没有在 GPU 上运行。我该如何解决这个问题?
【问题讨论】:
标签: tensorflow keras