python - Tensorflow variable_scope 中的 partitioner 参数有什么用?

标签 python tensorflow sharding partition

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

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

最佳答案

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

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

If a partitioner is provided, a PartitionedVariable is returned. Accessing this object as a Tensor returns the shards concatenated along the partition axis.

或者您通过 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))

关于python - Tensorflow variable_scope 中的 partitioner 参数有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47170879/

相关文章:

python - 使用 Python 插入 Elasticsearch 数据

python - python完成后如何停止ffmpeg

tensorflow - 减少 CNN (Conv1D) 文本分类模型中的误报

scala - Akka Stateful Actor 跨节点复制

database - 按 user_id 与按 entity_id 分片数据库

python - 根据日期范围创建包含分类变量的新列

Python:不同的空集列表

tensorflow - 如何从 .cfg 文件加载 darknet YOLOv3 模型并从 .weights 文件加载权重,并将模型与权重保存到 .h5 文件?

machine-learning - 在 GPU 上运行 TensorFlow Textsum 模型

database - 跨分片搜索?