前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >tensorflow学习笔记(十八):Multiple GPUs

tensorflow学习笔记(十八):Multiple GPUs

作者头像
ke1th
发布2019-05-26 12:30:21
1K0
发布2019-05-26 12:30:21
举报
文章被收录于专栏:漫漫深度学习路

Distribuited tensorflow

Multiple GPUs

Multiple GPUs
Multiple GPUs

如何设置训练系统

(1)每个GPU上都会有model的副本 (2)对模型的参数进行同步更新

抽象名词

  • 计算单个副本inferencegradients 的函数称之为tower,使用tf.name_scope()为tower中的每个op_name加上前缀
  • 使用tf.device('/gpu:0') 来指定tower中op的运算设备

框架:

代码语言:javascript
复制
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)

源码地址

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016年11月11日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Distribuited tensorflow
    • Multiple GPUs
      • 如何设置训练系统
      • 抽象名词
      • 框架:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档