code: def assert_no_excessive_var_usage(name, max_permissible=2):
      """Fails if a tagged DeferredTensor is convert_to_tensor'd too much.
  
      To set this up, wrap some Variables in `defer_and_count_usage`.  Then, if any
      of them is accessed more than `max_permissible` times in the wrapped block,
      this will signal an informative error.
  
      Args:
        name: Python `str` naming this var usage counter.
        max_permissible: Python `int` giving the maximum OK number of times
          each tagged DeferredTensor may be read.
  
      Yields:
        Nothing (it's a context manager).
      """
      VAR_USAGES.clear()
      yield
      # TODO(jvdillon): Reduce max_permissible to 1?
      var_nusages = {
          var_id_and_name: len(usages)
          for var_id_and_name, usages in VAR_USAGES.items()
      }
      if any(
          len(usages) > max_permissible
          for usages in VAR_USAGES.values()
      ):
          for (_, var_name), usages in VAR_USAGES.items():
              if len(usages) > max_permissible:
                  print(
                      "While executing {}, saw {} Tensor conversions of {}:".format(
                          name, len(usages), var_name
                      )
                  )
                  for i, usage in enumerate(usages):
                      print(
                          "Conversion {} of {}:\n{}".format(
                              i + 1, len(usages), "".join(usage)
                          )
                      )
          raise AssertionError(
              "More than {} tensor conversions detected for {}: {}".format(
                  max_permissible, name, var_nusages
              )
          )
  
imports: import contextlib
  import os
  import re
  import traceback
  import unittest
  import hypothesis
  from hypothesis.extra import numpy
  import hypothesis.strategies
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.util.deferred_tensor import DeferredTensor
label_desc: Use image node_id 11 for calling a global function with example usage: assert_no_excessive_var_usage(name, max_permissible) without return types