当前位置: 首页>>代码示例>>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;未经允许,请勿转载。