當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。