tensorflow - 没有 NCCL 的 MirroredStrategy
问题描述
- 我是否编写了自定义代码(而不是使用 TensorFlow 中提供的股票示例脚本):否
- 操作系统平台和发行版(例如,Linux Ubuntu 16.04):Windows 10 x64
- TensorFlow 安装自(源代码或二进制):二进制
- TensorFlow 版本(使用下面的命令):1.8.0
- Python版本:3.6
- Bazel 版本(如果从源代码编译):-
- GCC/编译器版本(如果从源代码编译): -
- CUDA/cuDNN 版本:9.0
- GPU型号和内存:3.5
- 重现的确切命令:simple_tfkeras_example.py
我想使用 MirroredStrategy 在同一台机器上使用多个 GPU。我尝试了其中一个示例: https ://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/distribute/python/examples/simple_tfkeras_example.py
结果是:ValueError:操作类型未在 RAID 上运行的二进制文件中注册“NcclAllReduce”。确保在此进程中运行的二进制文件中注册了 Op 和 Kernel。在构建 NodeDef 'NcclAllReduce' 时
我使用的是 Windows,因此 Nccl 不可用。是否可以强制 TensorFlow 不使用该库?
解决方案
Windows 上有一些用于 NCCL 的二进制文件,但处理起来很烦人。
作为替代方案,Tensorflow 在 MirroredStrategy 中为您提供了与 Windows 原生兼容的其他三个选项。它们是分层复制、归约到第一个 GPU 和归约到 CPU。您最有可能寻找的是分层副本,但您可以测试它们中的每一个,看看什么能给您带来最好的结果。
如果您使用 tensorflow 2.0 之前的版本,您将使用 tf.contrib.distribute:
# Hierarchical Copy
cross_tower_ops = tf.contrib.distribute.AllReduceCrossTowerOps(
'hierarchical_copy', num_packs=number_of_gpus))
strategy = tf.contrib.distribute.MirroredStrategy(cross_tower_ops=cross_tower_ops)
# Reduce to First GPU
cross_tower_ops = tf.contrib.distribute. ReductionToOneDeviceCrossTowerOps()
strategy = tf.contrib.distribute.MirroredStrategy(cross_tower_ops=cross_tower_ops)
# Reduce to CPU
cross_tower_ops = tf.contrib.distribute. ReductionToOneDeviceCrossTowerOps(
reduce_to_device="/device:CPU:0")
strategy = tf.contrib.distribute.MirroredStrategy(cross_tower_ops=cross_tower_ops)
2.0以后只需要使用tf.distribute即可!下面是一个使用 2 个 GPU 设置 Xception 模型的示例:
strategy = tf.distribute.MirroredStrategy(devices=["/gpu:0", "/gpu:1"],
cross_device_ops=tf.distribute.HierarchicalCopyAllReduce())
with strategy.scope():
parallel_model = Xception(weights=None,
input_shape=(299, 299, 3),
classes=number_of_classes)
parallel_model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
推荐阅读
- node.js - 为什么没有将数据写入我的 Amazon DynamoDB 表?
- sql - SQL 中 ')' 附近的语法不正确
- r - 如何将变量传递给ggplot aes / ..y ..函数的一部分
- javascript - 如何使用javascript将回调添加到函数中?
- javascript - 使用 Babel 创建单个 JavaScript 包的最佳方式
- c++ - 以十六进制生成随机 16 字节数组
- svn - svn:如何将分支的工作副本与主干的特定修订版进行比较
- sharepoint - 事件接收器(范围到网络),部署时,它附加到列表,但它也附加到站点
- java - 为什么我的计算不正确?
- python - Django - 在 form.py Meta 类中添加小部件选项?