code: def _generate_tfdbg_v2_data(
      logdir, tensor_debug_mode="NO_TENSOR", logarithm_times=None
  ):
      """Generate a simple dump of tfdbg v2 data by running a TF2 program.
  
      The run is instrumented by the enable_dump_debug_info() API.
  
      The instrumented program is intentionally diverse in:
        - Execution paradigm: eager + tf.function
        - Control flow (TF while loop)
        - dtype and shape
      in order to faciliate testing.
  
      Args:
        logdir: Logdir to write the debugger data to.
        tensor_debug_mode: Mode for dumping debug tensor values, as an optional
          string. See the documentation of
          `tf.debugging.experimental.enable_dump_debug_info()` for details.
        logarithm_times: Optionally take logarithm of the final `x` file _ times
          iteratively, in order to produce nans.
      """
      x = tf.constant([1, 3, 3, 7], dtype=tf.float32)
      writer = tf.debugging.experimental.enable_dump_debug_info(
          logdir,
          circular_buffer_size=-1,
          tensor_debug_mode=tensor_debug_mode,
      )
      try:
  
          @tf.function
          def unstack_and_sum(x):
              elements = tf.unstack(x)
              return (
                  elements[0] + elements[1] + elements[2] + elements[3]
              )
  
          @tf.function
          def repeated_add(x, times):
              sum = tf.constant(0, dtype=x.dtype)
              i = tf.constant(0, dtype=tf.int32)
              while tf.less(i, times):
                  sum += x
                  i += 1
              return sum
  
          @tf.function
          def my_function(x):
              times = tf.constant(3, dtype=tf.int32)
              return repeated_add(unstack_and_sum(x), times)
  
          for i in range(3):
              assert my_function(x).numpy() == 42.0
  
          logarithm_times = (
              0 if logarithm_times is None else logarithm_times
          )
          for i in range(logarithm_times):
              x = tf.math.log(x)
          # Expected iteration results:
          #   [0.        1.0986123 1.0986123 1.9459102]
          #   [-inf 0.09404784 0.09404784 0.6657298 ]
          #   [nan -2.3639517  -2.3639517  -0.40687138]
          #   [nan nan nan nan]
          #   [nan nan nan nan]
          #   [nan nan nan nan]
          #   ...
  
          writer.FlushNonExecutionFiles()
          writer.FlushExecutionFiles()
      finally:
          tf.debugging.experimental.disable_dump_debug_info()
  
imports: import collections
  import json
  import os
  import socket
  import threading
  import tensorflow
  from werkzeug import test
  from werkzeug import wrappers
  from tensorboard.backend import application
  from tensorboard.plugins import base_plugin
  from tensorboard.plugins.debugger_v2 import debug_data_multiplexer
  from tensorboard.plugins.debugger_v2 import debugger_v2_plugin
label_desc: Use image node_id 1 for calling a global function with example usage: _generate_tfdbg_v2_data(logdir, tensor_debug_mode, logarithm_times) and returns: unknown, sum, repeated_add