当前位置: 首页>>代码示例>>Python>>正文


Python device_setter.replica_device_setter方法代码示例

本文整理汇总了Python中tensorflow.python.training.device_setter.replica_device_setter方法的典型用法代码示例。如果您正苦于以下问题:Python device_setter.replica_device_setter方法的具体用法?Python device_setter.replica_device_setter怎么用?Python device_setter.replica_device_setter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.python.training.device_setter的用法示例。


在下文中一共展示了device_setter.replica_device_setter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_replica_device_setter

# 需要导入模块: from tensorflow.python.training import device_setter [as 别名]
# 或者: from tensorflow.python.training.device_setter import replica_device_setter [as 别名]
def _get_replica_device_setter(config):
  """Creates a replica device setter if required.

  Args:
    config: A RunConfig instance.

  Returns:
    A replica device setter, or None.
  """
  ps_ops = [
      'Variable', 'VariableV2', 'AutoReloadVariable', 'MutableHashTable',
      'MutableHashTableOfTensors', 'MutableDenseHashTable'
  ]

  if config.task_type:
    worker_device = '/job:%s/task:%d' % (config.task_type, config.task_id)
  else:
    worker_device = '/job:worker'

  if config.num_ps_replicas > 0:
    return device_setter.replica_device_setter(
        ps_tasks=config.num_ps_replicas, worker_device=worker_device,
        merge_devices=True, ps_ops=ps_ops, cluster=config.cluster_spec)
  else:
    return None 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:27,代码来源:estimator.py

示例2: _get_replica_device_setter

# 需要导入模块: from tensorflow.python.training import device_setter [as 别名]
# 或者: from tensorflow.python.training.device_setter import replica_device_setter [as 别名]
def _get_replica_device_setter(config):
  """Creates a replica device setter if required.

  Args:
    config: A RunConfig instance.

  Returns:
    A replica device setter, or None.
  """
  ps_ops = [
      'Variable', 'AutoReloadVariable', 'MutableHashTable',
      'MutableHashTableOfTensors', 'MutableDenseHashTable'
  ]

  if config.job_name:
    worker_device = '/job:%s/task:%d' % (config.job_name, config.task)
  else:
    worker_device = '/job:worker'

  if config.num_ps_replicas > 0:
    return device_setter.replica_device_setter(
        ps_tasks=config.num_ps_replicas, worker_device=worker_device,
        merge_devices=False, ps_ops=ps_ops, cluster=config.cluster_spec)
  else:
    return None 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:27,代码来源:estimator.py

示例3: testVariableWithReplicaDeviceSetter

# 需要导入模块: from tensorflow.python.training import device_setter [as 别名]
# 或者: from tensorflow.python.training.device_setter import replica_device_setter [as 别名]
def testVariableWithReplicaDeviceSetter(self):
    with self.cached_session():
      with ops.device(device_setter.replica_device_setter(ps_tasks=2)):
        a = variables_lib2.variable('a', [])
        b = variables_lib2.variable('b', [])
        c = variables_lib2.variable('c', [], device='cpu:12')
        d = variables_lib2.variable('d', [])
        with ops.device('cpu:99'):
          e_init = constant_op.constant(12)
        e = variables_lib2.variable('e', initializer=e_init)
      # The values below highlight how the replica_device_setter puts initial
      # values on the worker job, and how it merges explicit devices.
      self.assertDeviceEqual(a.device, '/job:ps/task:0/cpu:0')
      self.assertEqual(a.initial_value.op.colocation_groups(),
                       a.op.colocation_groups())
      self.assertDeviceEqual(b.device, '/job:ps/task:1/cpu:0')
      self.assertEqual(b.initial_value.op.colocation_groups(),
                       b.op.colocation_groups())
      self.assertDeviceEqual(c.device, '/job:ps/task:0/cpu:12')
      self.assertEqual(c.initial_value.op.colocation_groups(),
                       c.op.colocation_groups())
      self.assertDeviceEqual(d.device, '/job:ps/task:1/cpu:0')
      self.assertEqual(d.initial_value.op.colocation_groups(),
                       d.op.colocation_groups())
      self.assertDeviceEqual(e.device, '/job:ps/task:0/cpu:0')
      self.assertDeviceEqual(e.initial_value.device, '/job:worker/cpu:99') 
开发者ID:google-research,项目名称:tf-slim,代码行数:28,代码来源:variables_test.py


注:本文中的tensorflow.python.training.device_setter.replica_device_setter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。