zoukankan      html  css  js  c++  java
  • TensorFlow 分布式实践

    此wiki主要介绍分布式环境使用的一些条件,一直所要注意的内容;

    确保在此之前阅读过TensorFlow for distributed

    1.集群描述

       当前tensorflow 的版本(0.8.0),并没有提供统一的资源管理器,所以若要启动处理节点需要手动完成,并且要每个节点一份完整的集群描述,目的是让该节点能够找到其他的节点

       例如:启动Server的命令如下

       python ./tensorflow/tools/dist_test/server/grpc_tensorflow_server.py  --cluster_spec='ps|10.100.208.23:22222,worker|10.100.208.23:22223;10.100.208.23:22224'  --job_name=ps --task_index=0

       --cluster_spec:描述集群的所有Server的ip:port,并形成一个dictionary,上边的命令最后形成

                                 "ps":[0.100.208.23:22222]

                                 "worker":[10.100.208.23:22223;10.100.208.23:22224]

       --job_name --task_index  : 通过这两个参数能够确定,这个当前进程使用dictionary里的哪个ip:port.

      NOTE:实际上"ps","worker"并不含有什么实际意义,在启动server时可以自行指定名称,以便后续业务代码识别即可。

    2.进行计算:

       进行分布式计算可以将某些计算分派给某个Server的某个资源(cpu,gpu)来执行。

       例如

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    import tensorflow as tf
     
    def main() :
            with tf.device("/job:ps/task:0/cpu:0"):
                    = tf.Variable(1)
                    = tf.Variable(1)
            with tf.device("/job:worker/task:0/gpu:1"):
                    = + b
            with tf.Session("grpc://localhost:22223",config=tf.ConfigProto(allow_soft_placement=True,log_device_placement=True)) as sess:
                    result = sess.run(c)
                    print(result)
    if __name__ == '__main__':
        main()

      

    其中 两个变量a,b的声明工作在ps进程的cpu0上完成; a+b的操作在worker进程的gpu1上完成

    NOTE:若要指定运行的device,必须使用源码编译后的启动方式

    bazel-bin/tensorflow/core/distributed_runtime/rpc/grpc_tensorflow_server 

    NOTE:如果在不同的进程里生命的变量进行运算可能会报错

                 tensorflow.python.framework.errors.FailedPreconditionError: Attempting to use uninitialized value

                 需要先初始化变量

                 sess.run(tf.initialize_all_variables())

                具体可参考 https://www.tensorflow.org/versions/r0.8/how_tos/variable_scope/index.html#sharing-variables

    NOTE:创建tf.Session时,需要制定到worker地址否则会报错

                 tensorflow.python.framework.errors.InternalError: Blas SGEMM launch failed 

                 并且导致进程退出

  • 相关阅读:
    spring和mybatis整合
    mybatis(二)
    Django-model基础
    用户用户组管理:用户配置文件-组信息文件
    第一章:编译程序概论
    软件包管理:脚本安装包
    软件包管理:源码包管理-源码包安装过程
    软件包管理:源码包管理-源码包与RPM包的区别
    软件包管理:yum在线管理-yum命令
    软件包管理:rpm包管理-yum在线管理-IP地址配置和网络yum源
  • 原文地址:https://www.cnblogs.com/xuchenCN/p/5888651.html
Copyright © 2011-2022 走看看