code: def testLazyCompilation(self):
      @function.Defun(compiled=True)
      def CompiledFunction(x):
          return math_ops.log(x)
  
      with session_lib.Session(config=NoRewriteSessionConfig()) as sess:
          x = array_ops.placeholder(dtypes.float32)
          y = CompiledFunction(x)
  
          # The very first run of the cluster is always compiled (non-lazily).
          run_metadata_for_first_run = config_pb2.RunMetadata()
          sess.run(
              y,
              feed_dict={x: [2.0, 10.0, 19.0, 77.0, 100.0]},
              run_metadata=run_metadata_for_first_run,
              options=config_pb2.RunOptions(
                  trace_level=config_pb2.RunOptions.FULL_TRACE
              ),
          )
          self.assertTrue(
              InLabels(
                  RunMetadataLabels(run_metadata_for_first_run),
                  "_XlaCompile",
              )
          )
          self.assertTrue(
              InLabels(
                  RunMetadataLabels(run_metadata_for_first_run),
                  "_XlaRun",
              )
          )
  
          run_metadata_before_warmup = config_pb2.RunMetadata()
          sess.run(
              y,
              feed_dict={x: [2.0, 10.0]},
              run_metadata=run_metadata_before_warmup,
              options=config_pb2.RunOptions(
                  trace_level=config_pb2.RunOptions.FULL_TRACE
              ),
          )
          self.assertTrue(
              InLabels(
                  RunMetadataLabels(run_metadata_before_warmup),
                  "_XlaCompile",
              )
          )
          self.assertFalse(
              InLabels(
                  RunMetadataLabels(run_metadata_before_warmup),
                  "_XlaRun",
              )
          )
  
          # We compile when we see the same shape a second time.
  
          run_metadata_after_warmup = config_pb2.RunMetadata()
          sess.run(
              y,
              feed_dict={x: [2.0, 10.0]},
              run_metadata=run_metadata_after_warmup,
              options=config_pb2.RunOptions(
                  trace_level=config_pb2.RunOptions.FULL_TRACE
              ),
          )
          self.assertTrue(
              InLabels(
                  RunMetadataLabels(run_metadata_after_warmup),
                  "_XlaCompile",
              )
          )
          self.assertTrue(
              InLabels(
                  RunMetadataLabels(run_metadata_after_warmup),
                  "_XlaRun",
              )
          )
  
          run_metadata_for_new_shape = config_pb2.RunMetadata()
          sess.run(
              y,
              feed_dict={x: [2.0, 10.0, 12.0]},
              run_metadata=run_metadata_for_new_shape,
              options=config_pb2.RunOptions(
                  trace_level=config_pb2.RunOptions.FULL_TRACE
              ),
          )
          self.assertTrue(
              InLabels(
                  RunMetadataLabels(run_metadata_for_new_shape),
                  "_XlaCompile",
              )
          )
          self.assertFalse(
              InLabels(
                  RunMetadataLabels(run_metadata_for_new_shape),
                  "_XlaRun",
              )
          )
  
imports: import os
  import numpy
  from tensorflow.compiler.tests import test_utils
  from tensorflow.core.protobuf import config_pb2
  from tensorflow.core.protobuf import rewriter_config_pb2
  from tensorflow.python.client import session
  from tensorflow.python.compiler.xla import jit
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import function
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import cond
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.ops import gradients_impl
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import nn_ops
  from tensorflow.python.ops import while_loop
  from tensorflow.python.platform import test
label_desc: Use image node_id 1 for calling the LazyCompilationTest obj's underlying member method code with example usage: obj.testLazyCompilation() and returns: math_ops