code: def testOptimizerToggleOptionPinToHost(self):
      options = config.get_optimizer_experimental_options()
      self.assertIsNone(options.get("pin_to_host_optimization"))
  
      @def_function.function
      def fun():
          op = test_ops.device_placement_op()
          return op
  
      # Force optimizer to run for all graphs
      config.set_optimizer_experimental_options({"min_graph_nodes": -1})
      options["min_graph_nodes"] = -1
  
      # Since pin to host is disabled, the operation should go on GPU
      gpu = self.evaluate(fun())
      self.assertIn(compat.as_bytes("GPU"), gpu)
  
      config.set_optimizer_experimental_options(
          {"pin_to_host_optimization": True}
      )
      options["pin_to_host_optimization"] = True
      self.assertDictEqual(
          config.get_optimizer_experimental_options(), options
      )
      self.assertDictEqual(
          context.context().get_optimizer_experimental_options(),
          options,
      )
  
      # Since pin to host is enabled, the operation should go on CPU
      cpu = self.evaluate(fun())
      self.assertIn(compat.as_bytes("CPU"), cpu)
  
      config.set_optimizer_experimental_options(
          {"pin_to_host_optimization": False}
      )
      options["pin_to_host_optimization"] = False
      self.assertDictEqual(
          config.get_optimizer_experimental_options(), options
      )
      self.assertDictEqual(
          context.context().get_optimizer_experimental_options(),
          options,
      )
  
      # Since pin to host is disabled again, the operation should go on GPU
      gpu2 = self.evaluate(fun())
      self.assertIn(compat.as_bytes("GPU"), gpu2)
  
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 12 for calling the ConfigTest obj's underlying member method code with example usage: obj.testOptimizerToggleOptionPinToHost() and returns: op