114、TensorFlow设备放置

# creates a variable named v and places it on the second GPU device
import tensorflow as tf
#with tf.device("/device:GPU:1"):
#    v = tf.get_variable("v", [1])

#it is particularly important for variables to be in the correct device
#in distributed settings . 
#Accidentally putting variables on workers instead of parameter servers
#Can severely slow down training or, in the worst case 
#let each worker blithely forge ahead with its own independent copy of each variable
#For this reason we provide tf.train.replica_device_setter 
#which can automatically place variables in parameter servers
cluster_spec = {"ps":["ps0:2222","ps1:2222"],
                        "worker":["worker0:2222","worker1:2222","worker2:2222"]}
with tf.device(tf.train.replica_device_setter(cluster=cluster_spec)):
    v = tf.get_variable("v",shape=[20,20]) #this variable is placed in the paramter server by the replica_device_setter

 

转载于:https://www.cnblogs.com/weizhen/p/8451471.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值