code: def test_enqueue_with_outside_compilation_in_control_flow(
      self, use_mlir
  ):
      self.skip_if_oss()
      if use_mlir:
          config.enable_mlir_bridge()
  
      strategy, mid_level_api, _ = self._create_strategy_and_mid_level(
          "sgd"
      )
      dataset = self._create_sparse_dataset(strategy)
      dataset_iter = iter(
          strategy.experimental_distribute_dataset(
              dataset,
              options=distribute_lib.InputOptions(
                  experimental_fetch_to_device=False
              ),
          )
      )
  
      # This is one way to force the enqueue in some control flow. @tf.functions
      # aren't inlined in the calling tf.function. An alternative would be to
      # place the enqueue in a switch_v2 or something similar.
      @def_function.function
      def enqueue_fn(features):
          mid_level_api.enqueue(features, training=False)
  
      @def_function.function
      def enqueue_with_outside_compilation():
          def get_activations(features):
              enqueue_fn(features)
              return mid_level_api.dequeue()
  
          return strategy.run(
              get_activations, args=(next(dataset_iter),)
          )
  
      with self.assertRaisesRegex(
          RuntimeError,
          "does not match graph which contains TPUReplicateContext",
      ):
          enqueue_with_outside_compilation()
  
file_path: tensorflow-upstream/tensorflow/python/tpu/tests/tpu_embedding_v2_enqueue_mode_test.py
imports: from absl.testing import parameterized
  import numpy
  from tensorflow.python.compat import v2_compat
  from tensorflow.python.distribute import distribute_lib
  from tensorflow.python.eager import def_function
  from tensorflow.python.framework import config
  from tensorflow.python.framework.tensor_shape import TensorShape
  from tensorflow.python.ops import array_ops
  from tensorflow.python.platform import test
  from tensorflow.python.tpu.tests import tpu_embedding_base_test
  from tensorflow.python.util import nest
label_desc: Use image node_id 2 for calling the TPUEmbeddingTest obj's underlying member method code with example usage: obj.test_enqueue_with_outside_compilation_in_control_flow(use_mlir) and returns: strategy, mid_level_api