code: def testSoftPlacement(self):
      if context.executing_eagerly():
          self.assertTrue(config.get_soft_device_placement())
      else:
          self.assertFalse(config.get_soft_device_placement())
  
      def test_attr():
          with ops.device("/device:GPU:0"):
              return test_ops.test_attr(
                  T=dtypes.float32, name="test_attr"
              )
  
      config.set_soft_device_placement(True)
      self.assertEqual(config.get_soft_device_placement(), True)
      self.assertEqual(
          config.get_soft_device_placement(),
          context.context().soft_device_placement,
      )
  
      # Since soft placement is enabled, the test_attr operation should fallback
      # to CPU with pure eager execution as well as functions
      test_attr()
      def_function.function(test_attr)()
  
      config.set_soft_device_placement(False)
      self.assertEqual(config.get_soft_device_placement(), False)
      self.assertEqual(
          config.get_soft_device_placement(),
          context.context().soft_device_placement,
      )
  
      # Since soft placement is disabled, the test_attr operation should fail on
      # GPU with pure eager execution as well as functions
      with self.assertRaises(errors.InvalidArgumentError):
          test_attr()
      with self.assertRaises(errors.InvalidArgumentError):
          def_function.function(test_attr)()
  
imports: from absl.testing import parameterized
  from tensorflow.core.protobuf import cluster_pb2
  from tensorflow.core.protobuf import config_pb2
  from tensorflow.core.protobuf import rewriter_config_pb2
  from tensorflow.core.protobuf import tensorflow_server_pb2
  from tensorflow.python.eager import context
  from tensorflow.python.eager import def_function
  from tensorflow.python.framework import config
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.platform import test
  from tensorflow.python.util import compat
label_desc: Use image node_id 5 for calling the ConfigTest obj's underlying member method code with example usage: obj.testSoftPlacement() and returns: test_ops