code: 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
  
imports: import collections
  import six
  import tensorflow
  from tensorflow.python.platform import tf_logging
  from tensorflow.core.framework import node_def_pb2
  from tensorflow.python.framework import device
  from tensorflow.python.training import basic_session_run_hooks
  from tensorflow.python.training import session_run_hook
  from tensorflow.python.training import training_util
  from tensorflow.python.training import device_setter
  from tensorflow.contrib.learn.python.learn import run_config
label_desc: Use image node_id 1 for calling a global function with example usage: local_device_setter(num_devices, ps_device_type, worker_device, ps_ops, ps_strategy) and returns: _local_device_chooser, ps_device_spec, worker_device_spec