本文整理汇总了Python中tensorflow.contrib.learn.python.learn.estimators.estimator._get_replica_device_setter函数的典型用法代码示例。如果您正苦于以下问题:Python _get_replica_device_setter函数的具体用法?Python _get_replica_device_setter怎么用?Python _get_replica_device_setter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_get_replica_device_setter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testMutableHashTableIsLocal
def testMutableHashTableIsLocal(self):
with tf.device(estimator._get_replica_device_setter(tf.contrib.learn.RunConfig(num_ps_replicas=0))):
default_val = tf.constant([-1, -1], tf.int64)
table = tf.contrib.lookup.MutableHashTable(tf.string, tf.int64, default_val)
input_string = tf.constant(["brain", "salad", "tank"])
output = table.lookup(input_string)
self.assertDeviceEqual("", table._table_ref.device)
self.assertDeviceEqual("", output.device)
示例2: testMutableHashTableIsLocal
def testMutableHashTableIsLocal(self):
with ops.device(
estimator._get_replica_device_setter(run_config.RunConfig())):
default_val = constant_op.constant([-1, -1], dtypes.int64)
table = lookup.MutableHashTable(dtypes.string, dtypes.int64,
default_val)
input_string = constant_op.constant(['brain', 'salad', 'tank'])
output = table.lookup(input_string)
self.assertDeviceEqual('', table._table_ref.device)
self.assertDeviceEqual('', output.device)
示例3: testVariablesAreLocal
def testVariablesAreLocal(self):
with tf.device(estimator._get_replica_device_setter(tf.contrib.learn.RunConfig(num_ps_replicas=0))):
v = tf.Variable([1, 2])
w = tf.Variable([2, 1])
a = v + w
self.assertDeviceEqual("", v.device)
self.assertDeviceEqual("", v.initializer.device)
self.assertDeviceEqual("", w.device)
self.assertDeviceEqual("", w.initializer.device)
self.assertDeviceEqual("", a.device)
示例4: testVariablesAreLocal
def testVariablesAreLocal(self):
with tf.device(estimator._get_replica_device_setter(num_ps_replicas=0)):
v = tf.Variable([1, 2])
w = tf.Variable([2, 1])
a = v + w
self.assertDeviceEqual('', v.device)
self.assertDeviceEqual('', v.initializer.device)
self.assertDeviceEqual('', w.device)
self.assertDeviceEqual('', w.initializer.device)
self.assertDeviceEqual('', a.device)
示例5: testMutableHashTableIsLocal
def testMutableHashTableIsLocal(self):
with tf.device(estimator._get_replica_device_setter(num_ps_replicas=0)):
default_val = tf.constant([-1, -1], tf.int64)
table = tf.contrib.lookup.MutableHashTable(tf.string,
tf.int64,
default_val)
input_string = tf.constant(['brain', 'salad', 'tank'])
output = table.lookup(input_string)
self.assertDeviceEqual('', table._table_ref.device)
self.assertDeviceEqual('', output.device)
示例6: testVariablesAreOnPs
def testVariablesAreOnPs(self):
with tf.device(estimator._get_replica_device_setter(num_ps_replicas=1)):
v = tf.Variable([1, 2])
w = tf.Variable([2, 1])
a = v + w
self.assertDeviceEqual('/job:ps/task:0', v.device)
self.assertDeviceEqual('/job:ps/task:0', v.initializer.device)
self.assertDeviceEqual('/job:ps/task:0', w.device)
self.assertDeviceEqual('/job:ps/task:0', w.initializer.device)
self.assertDeviceEqual('/job:worker', a.device)
示例7: testVariablesAreLocal
def testVariablesAreLocal(self):
with ops.device(
estimator._get_replica_device_setter(run_config.RunConfig())):
v = variables_lib.Variable([1, 2])
w = variables_lib.Variable([2, 1])
a = v + w
self.assertDeviceEqual('', v.device)
self.assertDeviceEqual('', v.initializer.device)
self.assertDeviceEqual('', w.device)
self.assertDeviceEqual('', w.initializer.device)
self.assertDeviceEqual('', a.device)
示例8: testMutableHashTableIsOnPs
def testMutableHashTableIsOnPs(self):
tf_config = {"cluster": {tf.contrib.learn.TaskType.PS: ["fake_ps_0"]}}
with tf.test.mock.patch.dict("os.environ", {"TF_CONFIG": json.dumps(tf_config)}):
config = tf.contrib.learn.RunConfig()
with tf.device(estimator._get_replica_device_setter(config)):
default_val = tf.constant([-1, -1], tf.int64)
table = tf.contrib.lookup.MutableHashTable(tf.string, tf.int64, default_val)
input_string = tf.constant(["brain", "salad", "tank"])
output = table.lookup(input_string)
self.assertDeviceEqual("/job:ps/task:0", table._table_ref.device)
self.assertDeviceEqual("/job:ps/task:0", output.device)
示例9: testTaskIsSetOnWorkerWhenJobNameIsSet
def testTaskIsSetOnWorkerWhenJobNameIsSet(self):
with tf.device(
estimator._get_replica_device_setter(
tf.contrib.learn.RunConfig(
num_ps_replicas=1, job_name='worker', task=3))):
v = tf.Variable([1, 2])
w = tf.Variable([2, 1])
a = v + w
self.assertDeviceEqual('/job:ps/task:0', v.device)
self.assertDeviceEqual('/job:ps/task:0', v.initializer.device)
self.assertDeviceEqual('/job:ps/task:0', w.device)
self.assertDeviceEqual('/job:ps/task:0', w.initializer.device)
self.assertDeviceEqual('/job:worker/task:3', a.device)
示例10: testMutableHashTableIsOnPs
def testMutableHashTableIsOnPs(self):
tf_config = {'cluster': {run_config.TaskType.PS: ['fake_ps_0']}}
with test.mock.patch.dict('os.environ',
{'TF_CONFIG': json.dumps(tf_config)}):
config = run_config.RunConfig()
with ops.device(estimator._get_replica_device_setter(config)):
default_val = constant_op.constant([-1, -1], dtypes.int64)
table = lookup.MutableHashTable(dtypes.string, dtypes.int64,
default_val)
input_string = constant_op.constant(['brain', 'salad', 'tank'])
output = table.lookup(input_string)
self.assertDeviceEqual('/job:ps/task:0', table._table_ref.device)
self.assertDeviceEqual('/job:ps/task:0', output.device)
示例11: testVariablesAreOnPs
def testVariablesAreOnPs(self):
tf_config = {"cluster": {tf.contrib.learn.TaskType.PS: ["fake_ps_0"]}}
with tf.test.mock.patch.dict("os.environ", {"TF_CONFIG": json.dumps(tf_config)}):
config = tf.contrib.learn.RunConfig()
with tf.device(estimator._get_replica_device_setter(config)):
v = tf.Variable([1, 2])
w = tf.Variable([2, 1])
a = v + w
self.assertDeviceEqual("/job:ps/task:0", v.device)
self.assertDeviceEqual("/job:ps/task:0", v.initializer.device)
self.assertDeviceEqual("/job:ps/task:0", w.device)
self.assertDeviceEqual("/job:ps/task:0", w.initializer.device)
self.assertDeviceEqual("/job:worker", a.device)
示例12: testVariablesAreOnPs
def testVariablesAreOnPs(self):
tf_config = {'cluster': {run_config.TaskType.PS: ['fake_ps_0']}}
with test.mock.patch.dict('os.environ',
{'TF_CONFIG': json.dumps(tf_config)}):
config = run_config.RunConfig()
with ops.device(estimator._get_replica_device_setter(config)):
v = variables_lib.Variable([1, 2])
w = variables_lib.Variable([2, 1])
a = v + w
self.assertDeviceEqual('/job:ps/task:0', v.device)
self.assertDeviceEqual('/job:ps/task:0', v.initializer.device)
self.assertDeviceEqual('/job:ps/task:0', w.device)
self.assertDeviceEqual('/job:ps/task:0', w.initializer.device)
self.assertDeviceEqual('/job:worker', a.device)
示例13: testTaskIsSetOnWorkerWhenJobNameIsSet
def testTaskIsSetOnWorkerWhenJobNameIsSet(self):
tf_config = {
"cluster": {tf.contrib.learn.TaskType.PS: ["fake_ps_0"]},
"task": {"type": tf.contrib.learn.TaskType.WORKER, "index": 3},
}
with tf.test.mock.patch.dict("os.environ", {"TF_CONFIG": json.dumps(tf_config)}):
config = tf.contrib.learn.RunConfig()
with tf.device(estimator._get_replica_device_setter(config)):
v = tf.Variable([1, 2])
w = tf.Variable([2, 1])
a = v + w
self.assertDeviceEqual("/job:ps/task:0", v.device)
self.assertDeviceEqual("/job:ps/task:0", v.initializer.device)
self.assertDeviceEqual("/job:ps/task:0", w.device)
self.assertDeviceEqual("/job:ps/task:0", w.initializer.device)
self.assertDeviceEqual("/job:worker/task:3", a.device)
示例14: __init__
def __init__(self, model_fn, model_dir=None, config=None, params=None):
# Create a run configuration.
if config is None:
self._config = RunConfig()
logging.info("Using default config.")
else:
if not isinstance(config, RunConfig):
raise ValueError("config must be an instance of RunConfig, "
"received {}.".format(config))
self._config = config
if(model_dir is not None) and (self._config.model_dir is not None):
if model_dir != self._config.model_dir:
# pylint: disable=g-doc-exception
raise ValueError(
"model_dir are set both in constructor and RunConfig, but with "
"different values. In constructor: '{}', in RunConfig: "
"'{}' ".format(model_dir, self._config.model_dir))
self._model_dir = model_dir or self._config.model_dir or generate_model_dir()
if self._config.model_dir is None:
self._config = self._config.replace(model_dir=self._model_dir)
logging.info("Using config: {}".format(vars(self._config)))
if self._config.session_config is None:
self._session_config = config_pb2.ConfigProto(allow_soft_placement=True)
else:
self._session_config = self._config.session_config
# Set device function depending if there are replicas or not.
self._device_fn = _get_replica_device_setter(self._config)
self._graph = None
self._verify_model_fn_args(model_fn, params)
self._model_fn = model_fn
self._params = params or {}
示例15: testTaskIsSetOnWorkerWhenJobNameIsSet
def testTaskIsSetOnWorkerWhenJobNameIsSet(self):
tf_config = {
'cluster': {
run_config.TaskType.PS: ['fake_ps_0']
},
'task': {
'type': run_config.TaskType.WORKER,
'index': 3
}
}
with test.mock.patch.dict('os.environ',
{'TF_CONFIG': json.dumps(tf_config)}):
config = run_config.RunConfig()
with ops.device(estimator._get_replica_device_setter(config)):
v = variables_lib.Variable([1, 2])
w = variables_lib.Variable([2, 1])
a = v + w
self.assertDeviceEqual('/job:ps/task:0', v.device)
self.assertDeviceEqual('/job:ps/task:0', v.initializer.device)
self.assertDeviceEqual('/job:ps/task:0', w.device)
self.assertDeviceEqual('/job:ps/task:0', w.initializer.device)
self.assertDeviceEqual('/job:worker/task:3', a.device)