分布式训练与模型部署实战
1. 模型加载与策略选择
在使用特定设备时,若要加载模型,需在分布上下文内调用 keras.models.load_model() 函数,示例如下:
with distribution.scope():
mirrored_model = keras.models.load_model("my_mnist_model.h5")
若只想使用部分可用的 GPU 设备,可将设备列表传递给 MirroredStrategy 的构造函数:
distribution = tf.distribute.MirroredStrategy(["/gpu:0", "/gpu:1"])
默认情况下, MirroredStrategy 类使用 NVIDIA 集合通信库(NCCL)进行 AllReduce 均值操作。不过,可通过将 cross_device_ops 参数设置为 tf.distribute.HierarchicalCopyAllReduce 类的实例或 tf.distribute.ReductionToOneDevice 类的实例来更改此设置。默认的 NCCL 选项基于 tf.distribute.NcclAllReduce 类,通常速度更快,但这取决于 G
超级会员免费看
订阅专栏 解锁全文
16

被折叠的 条评论
为什么被折叠?



