- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是分布式tensorflow的新手,正在寻找一个在CPU上进行同步训练的好例子。
我已经尝试过Distributed Tensorflow Example,它可以在1个参数服务器(1个具有1个CPU的机器)和3个工作器(每个工作= 1个具有1个CPU的机器)上成功地执行异步训练。但是,关于同步训练,尽管我遵循了以下内容的教程,但我仍无法正确运行它。
SyncReplicasOptimizer(V1.0 and V2.0)。
我已经将正式的SyncReplicasOptimizer代码插入正在工作的异步培训示例中,但是培训过程仍然是异步的。我的详细代码如下。与同步训练有关的任何代码都在******块内。
import tensorflow as tf
import sys
import time
# cluster specification ----------------------------------------------------------------------
parameter_servers = ["xx1.edu:2222"]
workers = ["xx2.edu:2222", "xx3.edu:2222", "xx4.edu:2222"]
cluster = tf.train.ClusterSpec({"ps":parameter_servers, "worker":workers})
# input flags
tf.app.flags.DEFINE_string("job_name", "", "Either 'ps' or 'worker'")
tf.app.flags.DEFINE_integer("task_index", 0, "Index of task within the job")
FLAGS = tf.app.flags.FLAGS
# start a server for a specific task
server = tf.train.Server(cluster, job_name=FLAGS.job_name, task_index=FLAGS.task_index)
# Parameters ----------------------------------------------------------------------
N = 3 # number of replicas
learning_rate = 0.001
training_epochs = int(21/N)
batch_size = 100
# Network Parameters
n_input = 784 # MNIST data input (img shape: 28*28)
n_hidden_1 = 256 # 1st layer number of features
n_hidden_2 = 256 # 2nd layer number of features
n_classes = 10 # MNIST total classes (0-9 digits)
if FLAGS.job_name == "ps":
server.join()
print("--- Parameter Server Ready ---")
elif FLAGS.job_name == "worker":
# Import MNIST data
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
# Between-graph replication
with tf.device(tf.train.replica_device_setter(
worker_device="/job:worker/task:%d" % FLAGS.task_index,
cluster=cluster)):
# count the number of updates
global_step = tf.get_variable('global_step', [],
initializer = tf.constant_initializer(0),
trainable = False,
dtype = tf.int32)
# tf Graph input
x = tf.placeholder("float", [None, n_input])
y = tf.placeholder("float", [None, n_classes])
# Create model
def multilayer_perceptron(x, weights, biases):
# Hidden layer with RELU activation
layer_1 = tf.add(tf.matmul(x, weights['h1']), biases['b1'])
layer_1 = tf.nn.relu(layer_1)
# Hidden layer with RELU activation
layer_2 = tf.add(tf.matmul(layer_1, weights['h2']), biases['b2'])
layer_2 = tf.nn.relu(layer_2)
# Output layer with linear activation
out_layer = tf.matmul(layer_2, weights['out']) + biases['out']
return out_layer
# Store layers weight & bias
weights = {
'h1': tf.Variable(tf.random_normal([n_input, n_hidden_1])),
'h2': tf.Variable(tf.random_normal([n_hidden_1, n_hidden_2])),
'out': tf.Variable(tf.random_normal([n_hidden_2, n_classes]))
}
biases = {
'b1': tf.Variable(tf.random_normal([n_hidden_1])),
'b2': tf.Variable(tf.random_normal([n_hidden_2])),
'out': tf.Variable(tf.random_normal([n_classes]))
}
# Construct model
pred = multilayer_perceptron(x, weights, biases)
# Define loss and optimizer
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(pred, y))
# ************************* SyncReplicasOpt Version 1.0 *****************************************************
''' This optimizer collects gradients from all replicas, "summing" them,
then applying them to the variables in one shot, after which replicas can fetch the new variables and continue. '''
# Create any optimizer to update the variables, say a simple SGD
opt = tf.train.AdamOptimizer(learning_rate=learning_rate)
# Wrap the optimizer with sync_replicas_optimizer with N replicas: at each step the optimizer collects N gradients before applying to variables.
opt = tf.train.SyncReplicasOptimizer(opt, replicas_to_aggregate=N,
replica_id=FLAGS.task_index, total_num_replicas=N)
# Now you can call `minimize()` or `compute_gradients()` and `apply_gradients()` normally
train = opt.minimize(cost, global_step=global_step)
# You can now call get_init_tokens_op() and get_chief_queue_runner().
# Note that get_init_tokens_op() must be called before creating session
# because it modifies the graph.
init_token_op = opt.get_init_tokens_op()
chief_queue_runner = opt.get_chief_queue_runner()
# **************************************************************************************
# Test model
correct = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1))
accuracy = tf.reduce_mean(tf.cast(correct, "float"))
# Initializing the variables
init_op = tf.initialize_all_variables()
print("---Variables initialized---")
# **************************************************************************************
is_chief = (FLAGS.task_index == 0)
# Create a "supervisor", which oversees the training process.
sv = tf.train.Supervisor(is_chief=is_chief,
logdir="/tmp/train_logs",
init_op=init_op,
global_step=global_step,
save_model_secs=600)
# **************************************************************************************
with sv.prepare_or_wait_for_session(server.target) as sess:
# **************************************************************************************
# After the session is created by the Supervisor and before the main while loop:
if is_chief:
sv.start_queue_runners(sess, [chief_queue_runner])
# Insert initial tokens to the queue.
sess.run(init_token_op)
# **************************************************************************************
# Statistics
net_train_t = 0
# Training
for epoch in range(training_epochs):
total_batch = int(mnist.train.num_examples/batch_size)
# Loop over all batches
for i in range(total_batch):
batch_x, batch_y = mnist.train.next_batch(batch_size)
# ======== net training time ========
begin_t = time.time()
sess.run(train, feed_dict={x: batch_x, y: batch_y})
end_t = time.time()
net_train_t += (end_t - begin_t)
# ===================================
# Calculate training accuracy
# acc = sess.run(accuracy, feed_dict={x: mnist.train.images, y: mnist.train.labels})
# print("Epoch:", '%04d' % (epoch+1), " Train Accuracy =", acc)
print("Epoch:", '%04d' % (epoch+1))
print("Training Finished!")
print("Net Training Time: ", net_train_t, "second")
# Testing
print("Testing Accuracy = ", accuracy.eval({x: mnist.test.images, y: mnist.test.labels}))
sv.stop()
print("done")
最佳答案
我认为您的问题可以作为 tensorflow 的#9596问题中的注释来回答。
此问题是由新版本的tf.train.SyncReplicasOptimizer()的错误引起的。您可以使用此API的旧版本来避免此问题。
另一个解决方案是来自Tensorflow Distributed Benchmarks。看一下源代码,您会发现它们通过 tensorflow 中的队列手动同步工作程序。通过实验,该基准测试的运行完全符合您的预期。
希望这些评论和资源可以帮助您解决问题。谢谢!
关于tensorflow - 分布式Tensorflow : good example for synchronous training on CPUs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41293576/
我正在编写一个使用“top”命令的脚本。 当我使用 top 时,我可以看到平均 CPU 使用率: Cpu(s): 41.9%us, 9.4%sy, 0.0%ni, 48.8%id, 0.0%wa, 0
我正在使用 gRPC 库并且有很多“无法处理热插拔 CPU”日志。我很困惑,因为此日志的条件 ( https://github.com/grpc/grpc/blob/master/src/core/l
我有大量数据文件需要通过函数 A 处理。假设有 1000 个文件,每个文件的每个处理时间不到 15 分钟,内存为 6GB。我的电脑有 32GB 和 8 个 CPU,所以为了安全起见,我一次最多可以使用
我是分布式tensorflow的新手,正在寻找一个在CPU上进行同步训练的好例子。 我已经尝试过Distributed Tensorflow Example,它可以在1个参数服务器(1个具有1个CPU
首先我在独立模式下运行! 我一直试图找到任何配置,但我还没有找到任何相关信息。 在 Spark 中有一些配置可以让你限制在每个从属中使用的 CPU 数量: SPARK_WORKER_CORES(工作人
我知道在对称多处理器 (SMP) 系统中,由于每个内核中的单独缓存,可能会发生错误共享,对于以下代码:http://software.intel.com/en-us/articles/avoiding
我正在使用 appjs 开发一个聊天应用程序,该应用程序使用 node.js 作为平台。我一直在检测计算机何时处于空闲状态(当用户离开计算机或不使用计算机时)。 node.js中有一个os模 bl
当您使用命令运行 perf 实用程序时,您获得的输出行之一如下所示: 2.088031 task-clock (msec) # 0.700 CPUs
在我的 mapPartition 部分,有多线程工作要做,我使用线程池并希望并行运行任务。但我无法区分这两个参数。 我想我可以设置 --executor-cores 到 5,我在我的任务中运行了 4
考虑 x86 CPU 上的单次内存访问(单次读取或单次写入,而不是读取+写入)SSE 指令。该指令正在访问 16 字节(128 位)的内存,并且访问的内存位置与 16 字节对齐。 文档“英特尔® 64
从 eclipse 内部启动 android 模拟器时出现问题。我收到错误消息:PANIC:缺少“x86_64”CPUS 的模拟器引擎程序 我可以从命令行启动模拟器: ./emulator64-x86
我正在尝试将我的微型计算引擎从 us-central2-a 移至 us-central1-a,因为 Google 将在一周内对第一个区域进行维护。我正在我的 Windows 计算机上通过 Cygwin
我遇到了与以下链接中提到的相同的问题。但是这个问题已被搁置,我仍在寻求解决方案。 https://stackoverflow.com/questions/27146511/panic-missing-
简单的多线程 c++11 程序,其中所有线程在紧密循环中锁定相同的互斥量。 当它使用8个线程时(作为逻辑cpu的数量)可以达到500万锁/秒 但是只添加一个额外的线程 - 性能会下降到 200,000
我知道 JVM 内存模型是为 CPU 的最低公分母设计的,因此它必须假设 JVM 可以在其上运行的 cpu 的最弱模型(例如 ARM)。 现在,考虑到 x64 具有相当强大的内存模型,假设我知道我的程
在 linux 内核 smp 中,pen_release 标识符用于启动辅助 cpu,我还发现它也在其他地方使用。 我已经在 sysdump 中检查了它的值,还尝试通过 lauterbach 设置来理
我需要更新一些旧代码以使用最新版本的 OpenMPI,但我对新的 --map-by 系统感到非常困惑。特别是,我不确定如何替换 --cpus-per-proc N。 几个网站建议使用 --map-by
sbatch 中使用的术语手册页可能有点困惑。因此,我想确保我正确设置了选项。假设我有一个任务要在具有 N 个线程的单个节点上运行。我假设我会使用 --nodes=1 是否正确?和 --ntasks=
我想使用以下资源分配来运行两个容器: 容器“C1”:保留 cpu1,共享 cpu2(具有 20 个 cpu 份额) 容器“C2”:保留 cpu3,共享 cpu2(具有 80 个 cpu 份额) 如果我
当 NMI 看门狗被“禁用”时,它仍然喋喋不休。 有谁知道这些消息的文档在哪里?我想看看到底发生了什么。 例如,验证其已禁用: $ cat /proc/sys/kernel/nmi_watchdog
我是一名优秀的程序员,十分优秀!