在“战略范围”内,我使用循环来构建 Keras 模型:
strategy = tf.distribute.MultiWorkerMirroredStrategy()
with strategy.scope():
input_shape = (8, 900, 1)
inputs = keras.Input(shape=(8, 900))
x = layers.Reshape((8,900,1))(inputs)
x = layers.BatchNormalization()(x)
for i, arr in enumerate(cells_array):
x = cell.generateCell( num_cell=i )(x)
x = layers.Flatten()(x)
x = layers.BatchNormalization()(x)
outputs = layers.Dense(10)(x)
model = keras.Model(inputs=inputs, outputs=outputs)
model.compile(loss=loss, optimizer=keras.optimizers.Adam(1e-3), metrics=["accuracy"])
但是我收到了这样的错误:
<块引用>Collective ops is aborted by: cluster check alive failed, /job:worker/replica:0/task:1 is down 错误可能来自 之前的操作。重新启动您的程序以进行重置。 [Op:CollectiveBcastSend]
它对应于 for 循环中的“x = cell.generateCell( num_cell=i )(x)”行。
我认为这是由于变量 i 没有在不同的工人之间同步,但我不知道如何解决这个问题。
谢谢!