當前位置: 首頁>>代碼示例>>Python>>正文


Python device_setter._RoundRobinStrategy方法代碼示例

本文整理匯總了Python中tensorflow.python.training.device_setter._RoundRobinStrategy方法的典型用法代碼示例。如果您正苦於以下問題:Python device_setter._RoundRobinStrategy方法的具體用法?Python device_setter._RoundRobinStrategy怎麽用?Python device_setter._RoundRobinStrategy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.python.training.device_setter的用法示例。


在下文中一共展示了device_setter._RoundRobinStrategy方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: local_device_setter

# 需要導入模塊: from tensorflow.python.training import device_setter [as 別名]
# 或者: from tensorflow.python.training.device_setter import _RoundRobinStrategy [as 別名]
def local_device_setter(num_devices=1,
                        ps_device_type='cpu',
                        worker_device='/cpu:0',
                        ps_ops=None,
                        ps_strategy=None):
    if ps_ops is None:
        ps_ops = ['Variable', 'VariableV2', 'VarHandleOp']

    if ps_strategy is None:
        ps_strategy = device_setter._RoundRobinStrategy(num_devices)
    if not six.callable(ps_strategy):
        raise TypeError("ps_strategy must be callable")

    def _local_device_chooser(op):
        current_device = pydev.DeviceSpec.from_string(op.device or "")

        node_def = op if isinstance(op, node_def_pb2.NodeDef) else op.node_def
        if node_def.op in ps_ops:
            ps_device_spec = pydev.DeviceSpec.from_string(
                '/{}:{}'.format(ps_device_type, ps_strategy(op)))

            ps_device_spec.merge_from(current_device)
            return ps_device_spec.to_string()
        else:
            worker_device_spec = pydev.DeviceSpec.from_string(worker_device or "")
            worker_device_spec.merge_from(current_device)
            return worker_device_spec.to_string()

    return _local_device_chooser 
開發者ID:bzhangGo,項目名稱:zero,代碼行數:31,代碼來源:parallel.py

示例2: local_device_setter

# 需要導入模塊: from tensorflow.python.training import device_setter [as 別名]
# 或者: from tensorflow.python.training.device_setter import _RoundRobinStrategy [as 別名]
def local_device_setter(num_devices=1,
                        ps_device_type='cpu',
                        worker_device='/cpu:0',
                        ps_ops=None,
                        ps_strategy=None):
  if ps_ops == None:
    ps_ops = ['Variable', 'VariableV2', 'VarHandleOp']

  if ps_strategy is None:
    ps_strategy = device_setter._RoundRobinStrategy(num_devices)
  if not six.callable(ps_strategy):
    raise TypeError("ps_strategy must be callable")

  def _local_device_chooser(op):
    current_device = pydev.DeviceSpec.from_string(op.device or "")

    node_def = op if isinstance(op, node_def_pb2.NodeDef) else op.node_def
    if node_def.op in ps_ops:
      ps_device_spec = pydev.DeviceSpec.from_string(
          '/{}:{}'.format(ps_device_type, ps_strategy(op)))

      ps_device_spec.merge_from(current_device)
      return ps_device_spec.to_string()
    else:
      worker_device_spec = pydev.DeviceSpec.from_string(worker_device or "")
      worker_device_spec.merge_from(current_device)
      return worker_device_spec.to_string()
  return _local_device_chooser 
開發者ID:rky0930,項目名稱:yolo_v2,代碼行數:30,代碼來源:cifar10_utils.py

示例3: local_device_setter

# 需要導入模塊: from tensorflow.python.training import device_setter [as 別名]
# 或者: from tensorflow.python.training.device_setter import _RoundRobinStrategy [as 別名]
def local_device_setter(num_devices=1,
                        ps_device_type='cpu',
                        worker_device='/cpu:0',
                        ps_ops=None,
                        ps_strategy=None):
    if ps_ops == None:
        ps_ops = ['Variable', 'VariableV2', 'VarHandleOp']

    if ps_strategy is None:
        ps_strategy = device_setter._RoundRobinStrategy(num_devices)
    if not six.callable(ps_strategy):
        raise TypeError("ps_strategy must be callable")

    def _local_device_chooser(op):
        current_device = pydev.DeviceSpec.from_string(op.device or "")

        node_def = op if isinstance(op, node_def_pb2.NodeDef) else op.node_def
        if node_def.op in ps_ops:
            ps_device_spec = pydev.DeviceSpec.from_string(
                '/{}:{}'.format(ps_device_type, ps_strategy(op)))

            ps_device_spec.merge_from(current_device)
            return ps_device_spec.to_string()
        else:
            worker_device_spec = pydev.DeviceSpec.from_string(worker_device or "")
            worker_device_spec.merge_from(current_device)
            return worker_device_spec.to_string()

    return _local_device_chooser 
開發者ID:alexlee-gk,項目名稱:video_prediction,代碼行數:31,代碼來源:tf_utils.py

示例4: local_device_setter

# 需要導入模塊: from tensorflow.python.training import device_setter [as 別名]
# 或者: from tensorflow.python.training.device_setter import _RoundRobinStrategy [as 別名]
def local_device_setter(num_devices=1,
                        ps_device_type='cpu',
                        worker_device='/cpu:0',
                        ps_ops=None,
                        ps_strategy=None):
    if ps_ops == None:
        ps_ops = ['Variable', 'VariableV2', 'VarHandleOp']

    if ps_strategy is None:
        ps_strategy = device_setter._RoundRobinStrategy(num_devices)
    if not six.callable(ps_strategy):
        raise TypeError("ps_strategy must be callable")

    def _local_device_chooser(op):
        current_device = pydev.DeviceSpec.from_string(op.device or "")

        node_def = op if isinstance(op, node_def_pb2.NodeDef) else op.node_def
        if node_def.op in ps_ops:
            ps_device_spec = pydev.DeviceSpec.from_string(
                  '/{}:{}'.format(ps_device_type, ps_strategy(op)))

            ps_device_spec.merge_from(current_device)
            return ps_device_spec.to_string()
        else:
            worker_device_spec = pydev.DeviceSpec.from_string(worker_device or "")
            worker_device_spec.merge_from(current_device)
            return worker_device_spec.to_string()
    return _local_device_chooser 
開發者ID:ucloud,項目名稱:uai-sdk,代碼行數:30,代碼來源:train_shadownet_multi.py

示例5: local_device_setter

# 需要導入模塊: from tensorflow.python.training import device_setter [as 別名]
# 或者: from tensorflow.python.training.device_setter import _RoundRobinStrategy [as 別名]
def local_device_setter(num_devices: int = 1,
                        ps_device_type: str = 'cpu',
                        worker_device: str = '/cpu:0',
                        ps_ops: List[str] = None,
                        ps_strategy: Optional[str] = None) -> Callable:
    """
    Setter for variable placement

    Parameters
    ----------
    num_devices
        number of devices
    ps_device_type
        device type for setting of the variables, e.g. cpu or gpu
    worker_device
        name of worker device
    ps_ops
        names of parameter server operations
    ps_strategy
        strategy of parameter server

    Returns
    -------
    local_device_chooser
        callable to pass to tf.device

    References
    ----------
    source
        https://github.com/tensorflow/models/blob/master/tutorials/image/
        cifar10_estimator/cifar10_utils.py
    """

    if ps_ops is None:
        ps_ops = ['Variable', 'VariableV2', 'VarHandleOp']

    if ps_strategy is None:
        ps_strategy = device_setter._RoundRobinStrategy(num_devices)
    if not six.callable(ps_strategy):
        raise TypeError("ps_strategy must be callable")

    def _local_device_chooser(op):
        current_device = pydev.DeviceSpec.from_string(op.device or "")

        node_def = op if isinstance(op, node_def_pb2.NodeDef) else op.node_def
        if node_def.op in ps_ops:
            ps_device_spec = pydev.DeviceSpec.from_string(
                '/{}:{}'.format(ps_device_type, ps_strategy(op)))

            ps_device_spec.merge_from(current_device)
            return ps_device_spec.to_string()
        else:
            worker_device_spec = pydev.DeviceSpec.from_string(
                worker_device or "")
            worker_device_spec.merge_from(current_device)
            return worker_device_spec.to_string()

    return _local_device_chooser 
開發者ID:audi,項目名稱:nucleus7,代碼行數:60,代碼來源:cifar10_utils.py


注:本文中的tensorflow.python.training.device_setter._RoundRobinStrategy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。