code: def test_copy_gradient_multiple_gpus(self):
      model = model_helper.ModelHelper(name="copy_test")
  
      with core.DeviceScope(core.DeviceOption(caffe2_pb2.CPU, 0)):
          x_cpu = model.net.AddExternalInputs("x_cpu")
  
      with core.DeviceScope(
          core.DeviceOption(workspace.GpuDeviceType, 0)
      ):
          x_gpu_1 = model.CopyCPUToGPU(x_cpu, "x_gpu_1")
  
      with core.DeviceScope(
          core.DeviceOption(workspace.GpuDeviceType, 1)
      ):
          x_gpu_2 = model.Copy(x_gpu_1, "x_gpu_2")
          loss = model.AveragedLoss(x_gpu_2, "loss")
          gradient_map = model.AddGradientOperators([loss])
  
      workspace.FeedBlob("x_cpu", np.random.rand(32).astype(np.float32))
      workspace.RunNetOnce(model.param_init_net)
      workspace.RunNetOnce(model.net)
  
      self.assertTrue(
          np.array_equal(
              workspace.FetchBlob("x_gpu_1"),
              workspace.FetchBlob("x_gpu_2"),
          )
      )
      self.assertTrue(
          np.array_equal(
              workspace.FetchBlob(gradient_map["x_gpu_1"]),
              workspace.FetchBlob(gradient_map["x_gpu_2"]),
          )
      )
  
      def get_op_with_output(model, output_blob_name):
          for op in model.net.Proto().op:
              if (
                  len(op.output) == 1
                  and op.output[0] == output_blob_name
              ):
                  return op
          return None
  
      self.assertEqual(
          get_op_with_output(model, "x_gpu_2_grad").device_option,
          core.DeviceOption(workspace.GpuDeviceType, 1),
      )
      self.assertEqual(
          get_op_with_output(model, "x_cpu_grad").device_option,
          core.DeviceOption(workspace.GpuDeviceType, 0),
      )
  
file_path: pytorch/caffe2/python/operator_test/copy_ops_test.py
imports: import numpy
  import unittest
  from caffe2.proto import caffe2_pb2
  from caffe2.python import workspace, core, model_helper, brew, test_util
label_desc: Use image node_id 5 for calling the CopyOpsTest obj's underlying member method code with example usage: obj.test_copy_gradient_multiple_gpus() and returns: None, op