tensorflow学习笔记(十八):Multiple GPUs
2016-11-11 10:33
183 查看
Distribuited tensorflow
Multiple GPUs
如何设置训练系统
(1)每个GPU上都会有model的副本(2)对模型的参数进行同步更新
抽象名词
计算单个副本inference和
gradients的函数称之为
tower,使用tf.name_scope()为tower中的每个op_name加上前缀
使用
tf.device('/gpu:0')来指定tower中op的运算设备
框架:
with tf.Graph().as_default(), tf.device('/cpu:0'): # Create an optimizer that performs gradient descent. opt = tf.train.GradientDescentOptimizer(lr) tower_grads=[] for i in xrange(FLAGS.num_gpus): with tf.device('/gpu:%d' % i): with tf.name_scope('%s_%d' % (TOWER_NAME, i)) as scope: #这里定义你的模型 #ops,variables #损失函数 loss = yourloss # Reuse variables for the next tower. tf.get_variable_scope().reuse_variables() # Calculate the gradients for the batch of data on this tower. grads = opt.compute_gradients(loss) # Keep track of the gradients across all towers. tower_grads.append(grads) # We must calculate the mean of each gradient. Note that this is the # synchronization point across all towers. grads = average_gradients(tower_grads) # Apply the gradients to adjust the shared variables. apply_gradient_op = opt.apply_gradients(grads)
源码地址
相关文章推荐
- John Carmack on Raytracing, Sparse voxel octree, Larrabee, Hybrid approach, Multiple GPUs, Physics card and id tech 6
- tensorflow:Multiple GPUs
- TensorFlow学习笔记(十八)tf.reshape矩阵变形
- CreateThread WaitForMultipleObjects
- Spring Boot教程(十八)使用Spring StateMachine框架实现状态机
- 解决Unable to execute dex: Multiple dex files define Landroid/support/v7/appcompat/R$anim;
- [置顶] 2017IT十八掌徐培成大数据全套教程 人工智能 机器学习 深入学习 AI 云计算
- 十八、运算符重载(二)++运算符重载、!运算符重载、赋值运算符重载、Integer和String的初步实现
- [LIBGDX学习]LibGDX代码详解(十八)Box2D
- Java编程思想(十八) —— 再谈反射
- 【十八掌●武功篇】第十一掌:HUE简介、基本安装配置
- Leetcode: Read N Characters Given Read4 II - Call multiple times
- Android Eclipse项目迁移到Studio时报错: com.android.dex.DexException: Multiple dex files define(重复引用包)
- 网络基本功(十八):细说tcpdump的妙用(下)
- Least Common Multiple
- (十八)TableView实践(多组汽车品牌展示)
- springboot干货——(十八)AOP
- POJ 1426 Find The Multiple(同余模定理优化双入口BFS)
- 我的tensorflow学习笔记(9):tf中的CNN
- com.android.dx.util.DexException: Multiple dex files define之谜