【问题标题】:What is partitioner parameter in Tensorflow variable_scope used for?Tensorflow variable_scope 中的 partitioner 参数是做什么用的?
【发布时间】:2018-04-20 14:51:31
【问题描述】:

tf.variable_scope 有一个partitioner 参数,如documentation 中所述。

据我了解,它用于分布式训练。谁能更详细地解释一下它的正确用法是什么?

【问题讨论】:

    标签: python tensorflow sharding partition


    【解决方案1】:

    巨大的张量流变量可以在多台机器上分片(参见this discussion)。 Partitioner 是一种机制,通过它 tensorflow 分配和组合回张量,因此程序的其余部分不知道这些实现细节并以通常的方式使用张量。

    您可以通过tf.get_variable为每个变量指定分区器:

    如果提供了分区器,则返回 PartitionedVariable。将此对象作为张量访问会返回沿分区轴连接的分片。

    或者您通过tf.variable_scope 为整个作用域定义默认分区器,这将影响其中定义的所有变量。

    this page 上查看 tensorflow 1.3 中可用分区器的列表。最简单的是tf.fixed_size_partitioner,它沿着指定的轴对张量进行分片。这是一个示例用法(来自this question):

    w = tf.get_variable("weights",                                        
                        weights_shape,                                    
                        partitioner=tf.fixed_size_partitioner(num_shards, axis=0), 
                        initializer=tf.truncated_normal_initializer(stddev=0.1))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-13
      • 1970-01-01
      • 2014-08-14
      • 2016-04-25
      • 1970-01-01
      • 1970-01-01
      • 2018-12-01
      • 1970-01-01
      相关资源
      最近更新 更多