使用多个 GPU 的任何可行方法,使用 tensorflow 进行多个进程?
any doable approach to use multiple GPUs, multiple process with tensorflow?
我正在使用 docker 容器来 运行 我的实验。我有多个可用的 GPU,我想将它们全部用于我的实验。我的意思是我想将所有 GPU 用于一个程序。为此,我使用了在 tensorflow 网站上建议的 tf.distribute.MirroredStrategy
,但它不起作用。这是 full error messages on gist.
这里有可用的 GPU 信息:
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.51.06 Driver Version: 450.51.06 CUDA Version: 11.1 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 Tesla T4 Off | 00000000:6A:00.0 Off | 0 |
| N/A 31C P8 15W / 70W | 0MiB / 15109MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
| 1 Tesla T4 Off | 00000000:6B:00.0 Off | 0 |
| N/A 31C P8 15W / 70W | 0MiB / 15109MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
| 2 Tesla T4 Off | 00000000:6C:00.0 Off | 0 |
| N/A 34C P8 15W / 70W | 0MiB / 15109MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
| 3 Tesla T4 Off | 00000000:6D:00.0 Off | 0 |
| N/A 34C P8 15W / 70W | 0MiB / 15109MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
我目前的尝试
这是我尝试使用 tf.distribute.MirroredStrategy
:
device_type = "GPU"
devices = tf.config.experimental.list_physical_devices(device_type)
devices_names = [d.name.split("e:")[1] for d in devices]
strategy = tf.distribute.MirroredStrategy(devices=devices_names[:3])
with strategy.scope():
model.compile(optimizer=opt, loss="categorical_crossentropy", metrics=["accuracy"])
以上尝试无效,并给出了上述要点中列出的错误。我找不到另一种使用多个 GPU 进行单个实验的方法。
有没有人有任何可行的方法来实现这一点?有什么想法吗?
MirrordStrategy 是分配工作负载的正确方法吗
方法是正确的,只要 GPU 在同一台主机上。 TensorFlow manual 有如何将 tf.distribute.MirroredStrategy
与 keras 结合使用来训练 MNIST 集的示例。
MirrordStrategy是不是唯一的策略
不,有多种策略可用于实现工作负载分配。例如,tf.distribute.MultiWorkerMirroredStrategy
也可用于通过多个工作人员在多个设备上分配工作。
TF documentation 解释了策略、与策略相关的限制并提供了一些示例来帮助启动工作。
策略出错
根据 github 的 issue,ValueError: SyncOnReadVariable does not support 'assign_add' .....
是 TensorFlow 中的一个错误,已在 TF 2.4
中修复
您可以尝试通过
升级tensorflow库
pip install --ignore-installed --upgrade tensorflow
实现不知道分布式策略的变量
如果您尝试了文档中的标准 example,并且它工作正常,但您的模型不工作,则您的变量可能设置不正确或者您正在使用 distributed variables
不支持分布式策略所需的聚合函数。
根据 TF 文档:
..."
A distributed variable is variables created on multiple devices. As discussed in the glossary, mirrored variable and SyncOnRead variable are two examples.
"...
为了更好地了解如何实现对分布式变量的自定义支持,请查看 documentation
中的以下页面
我正在使用 docker 容器来 运行 我的实验。我有多个可用的 GPU,我想将它们全部用于我的实验。我的意思是我想将所有 GPU 用于一个程序。为此,我使用了在 tensorflow 网站上建议的 tf.distribute.MirroredStrategy
,但它不起作用。这是 full error messages on gist.
这里有可用的 GPU 信息:
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.51.06 Driver Version: 450.51.06 CUDA Version: 11.1 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 Tesla T4 Off | 00000000:6A:00.0 Off | 0 |
| N/A 31C P8 15W / 70W | 0MiB / 15109MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
| 1 Tesla T4 Off | 00000000:6B:00.0 Off | 0 |
| N/A 31C P8 15W / 70W | 0MiB / 15109MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
| 2 Tesla T4 Off | 00000000:6C:00.0 Off | 0 |
| N/A 34C P8 15W / 70W | 0MiB / 15109MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
| 3 Tesla T4 Off | 00000000:6D:00.0 Off | 0 |
| N/A 34C P8 15W / 70W | 0MiB / 15109MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
我目前的尝试
这是我尝试使用 tf.distribute.MirroredStrategy
:
device_type = "GPU"
devices = tf.config.experimental.list_physical_devices(device_type)
devices_names = [d.name.split("e:")[1] for d in devices]
strategy = tf.distribute.MirroredStrategy(devices=devices_names[:3])
with strategy.scope():
model.compile(optimizer=opt, loss="categorical_crossentropy", metrics=["accuracy"])
以上尝试无效,并给出了上述要点中列出的错误。我找不到另一种使用多个 GPU 进行单个实验的方法。
有没有人有任何可行的方法来实现这一点?有什么想法吗?
MirrordStrategy 是分配工作负载的正确方法吗
方法是正确的,只要 GPU 在同一台主机上。 TensorFlow manual 有如何将 tf.distribute.MirroredStrategy
与 keras 结合使用来训练 MNIST 集的示例。
MirrordStrategy是不是唯一的策略
不,有多种策略可用于实现工作负载分配。例如,tf.distribute.MultiWorkerMirroredStrategy
也可用于通过多个工作人员在多个设备上分配工作。
TF documentation 解释了策略、与策略相关的限制并提供了一些示例来帮助启动工作。
策略出错
根据 github 的 issue,ValueError: SyncOnReadVariable does not support 'assign_add' .....
是 TensorFlow 中的一个错误,已在 TF 2.4
您可以尝试通过
升级tensorflow库pip install --ignore-installed --upgrade tensorflow
实现不知道分布式策略的变量
如果您尝试了文档中的标准 example,并且它工作正常,但您的模型不工作,则您的变量可能设置不正确或者您正在使用 distributed variables
不支持分布式策略所需的聚合函数。
根据 TF 文档:
..." A distributed variable is variables created on multiple devices. As discussed in the glossary, mirrored variable and SyncOnRead variable are two examples. "...
为了更好地了解如何实现对分布式变量的自定义支持,请查看 documentation
中的以下页面