TensorFlow-分布式计算

TensorFlow-分布式计算 (TensorFlow - Distributed Computing)

This chapter will focus on how to get started with distributed TensorFlow. The aim is to help developers understand the basic distributed TF concepts that are reoccurring, such as TF servers. We will use the Jupyter Notebook for evaluating distributed TensorFlow. The implementation of distributed computing with TensorFlow is mentioned below −

本章将重点介绍如何开始使用分布式TensorFlow。 目的是帮助开发人员了解重复出现的基本分布式TF概念,例如TF服务器。 我们将使用Jupyter Notebook评估分布式TensorFlow。 使用TensorFlow进行分布式计算的实现在下面提到-

Step 1 − Import the necessary modules mandatory for distributed computing −

步骤1-导入分布式计算必需的必要模块-


import tensorflow as tf

Step 2 − Create a TensorFlow cluster with one node. Let this node be responsible for a job that that has name "worker" and that will operate one take at localhost:2222.

第2步 -创建一个带有一个节点的TensorFlow集群。 让此节点负责一个名称为“ worker”的作业,该作业将在localhost:2222处执行一次操作。


cluster_spec = tf.train.ClusterSpec({'worker' : ['localhost:2222']})
server = tf.train.Server(cluster_spec)
server.target

The above scripts generate the following output −

上面的脚本生成以下输出-


'grpc://localhost:2222'
The server is currently running.

Step 3 − The server configuration with respective session can be calculated by executing the following command −

步骤3-可以通过执行以下命令来计算具有相应会话的服务器配置-


server.server_def

The above command generates the following output −

上面的命令生成以下输出-


cluster {
   job {
      name: "worker"
      tasks {
         value: "localhost:2222"
      }
   }
}
job_name: "worker"
protocol: "grpc"

Step 4 − Launch a TensorFlow session with the execution engine being the server. Use TensorFlow to create a local server and use lsof to find out the location of the server.

步骤4-启动以执行引擎为服务器的TensorFlow会话。 使用TensorFlow创建本地服务器,并使用lsof查找服务器的位置。


sess = tf.Session(target = server.target)
server = tf.train.Server.create_local_server()

Step 5 − View devices available in this session and close the respective session.

步骤5-查看此会话中可用的设备并关闭相应的会话。


devices = sess.list_devices()
for d in devices:
   print(d.name)
sess.close()

The above command generates the following output −

上面的命令生成以下输出-


/job:worker/replica:0/task:0/device:CPU:0

翻译自: https://www.tutorialspoint.com/tensorflow/tensorflow_distributed_computing.htm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值