code: def testPS2TasksWithDevice(self):
      cluster_spec = server_lib.ClusterSpec(
          {
              "sun": ["sun0:2222", "sun1:2222", "sun2:2222"],
              "moon": ["moon0:2222", "moon1:2222"],
          }
      )
  
      with ops.device(
          device_setter.replica_device_setter(
              ps_device="/job:moon",
              worker_device="/job:sun",
              cluster=cluster_spec.as_cluster_def(),
          )
      ):
          v = variables.Variable([1, 2])
          w = variables.Variable([2, 1])
          a = v + w
          self.assertDeviceEqual("/job:moon/task:0", v.device)
          self.assertDeviceEqual(
              "/job:moon/task:0", v.initializer.device
          )
          self.assertDeviceEqual("/job:moon/task:1", w.device)
          self.assertDeviceEqual(
              "/job:moon/task:1", w.initializer.device
          )
          self.assertDeviceEqual("/job:sun", a.device)
  
file_path: tensorflow/tensorflow/python/training/device_setter_test.py
imports: from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import resource_variable_ops
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import test
  from tensorflow.python.training import device_setter
  from tensorflow.python.training import server_lib
label_desc: Use image node_id 9 for calling the DeviceSetterTest obj's underlying member method code with example usage: obj.testPS2TasksWithDevice() without return types