使用分布式 tensorflow 运行 Alexnet 不会按每秒图像数量进行扩展。我在这里使用 alexnet 模型 alexnet_benchmark.py 对 EC2 G2(NVIDIA GRID K520)实例上的分布式训练进行了一些修改,我看到它可以在单个 GPU、单主机 上处理 5 6 个图像/秒,但是运行它 没有分布式代码可以在单个 GPU 上每秒处理 112 张图像 。这看起来很奇怪,你能不能检查一下这段代码中运行分布式的可能有什么问题?参数服务器不在 GPU 上运行,但工作人员使用 CUDA_VISIBLE_DEVICES 前缀运行ps_hosts = FLAGS.ps_hosts.split(",")
worker_hosts = FLAGS.worker_hosts.split(",")
# Create a cluster from the parameter server and worker hosts.
cluster = tf.train.ClusterSpec({"ps": ps_hosts, "worker": worker_hosts})
# Create and start a server for the local task.
server = tf.train.Server(cluster,
job_name=FLAGS.job_name,
task_index=FLAGS.task_index)
if FLAGS.job_name == "ps":
server.join()
elif FLAGS.job_name == "worker":
gpu = FLAGS.task_index % 4
# Assigns ops to the local worker by default.
with tf.device(tf.train.replica_device_setter(
#'/gpu:%d' % i
worker_device="/job:worker/task:%d" % FLAGS.task_index,
#worker_device='/gpu:%d' % gpu,
cluster=cluster)):
summary_op = tf.merge_all_summaries()
y, x = get_graph()
y_ = tf.placeholder(tf.float32, [None, NUM_LABELS])
cross_entropy = tf.reduce_mean( -tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]) )
global_step = tf.Variable(0)
gradient_descent_opt = tf.train.GradientDescentOptimizer(LEARNING_RATE)
num_workers = len(worker_hosts)
sync_rep_opt = tf.train.SyncReplicasOptimizer(gradient_descent_opt, replicas_to_aggregate=num_workers,
replica_id=FLAGS.task_index, total_num_replicas=num_workers)
train_op = sync_rep_opt.minimize(cross_entropy, global_step=global_step)
init_token_op = sync_rep_opt.get_init_tokens_op()
chief_queue_runner = sync_rep_opt.get_chief_queue_runner()
#saver = tf.train.Saver()
summary_op = tf.merge_all_summaries()
init_op = tf.initialize_all_variables()
saver = tf.train.Saver()
is_chief=(FLAGS.task_index == 0)
# Create a "supervisor", which oversees the training process.
sv = tf.train.Supervisor(is_chief=(FLAGS.task_index == 0),
#logdir="/tmp/train_logs",
init_op=init_op,
summary_op=summary_op,
saver=saver,
global_step=global_step)
#save_model_secs=600)
# The supervisor takes care of session initialization, restoring from
# a checkpoint, and closing when done or an error occurs.
with sv.managed_session(server.target) as sess:
if is_chief:
sv.start_queue_runners(sess, [chief_queue_runner])
sess.run(init_token_op)
num_steps_burn_in = 1000
total_duration = 0
total_duration_squared = 0
step = 0
while step <= 40000:
print('Iteration %d' % step)
sys.stdout.flush()
batch_xs, batch_ys = get_data(BATCH_SIZE)
train_feed = {x: batch_xs, y_: batch_ys}
start_time = time.time()
_, step = sess.run([train_op, global_step], feed_dict=train_feed)
duration = time.time() - start_time
if step > num_steps_burn_in:
total_duration += duration
total_duration_squared += duration * duration
if not step % 1000:
iterations = step - num_steps_burn_in
images_processed = BATCH_SIZE * iterations
print('%s: step %d, images processed: %d, images per second: %.3f, time taken: %.2f' %
(datetime.now(), iterations, images_processed, images_processed/total_duration, total_duration))
sys.stdout.flush()
sv.stop()
最佳答案
您的代码看起来不错 - 这里有几点需要牢记:
我的建议是尝试分布式 inception V3。与其单节点对应部分相比,这种拓扑应该表现出近乎完美的可扩展性。如果是,则您的硬件设置良好;如果它没有仔细检查您的硬件配置。
如果您进行可扩展性研究,我建议您从一个参数服务器和一个独立实例上的工作人员开始您的相对性能收集,与单节点运行相比会有其变化。
关于tensorflow - alexnet 分布式 tensorflow 性能,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39863039/