code: def _prefer_static(original_fn, static_fn, disable_spec_check=False):
      """Wraps original_fn, preferring to call static_fn when inputs are static."""
      original_spec = tf_inspect.getfullargspec(original_fn)._replace(
          annotations={}
      )
      static_spec = tf_inspect.getfullargspec(static_fn)._replace(
          annotations={}
      )
      if not disable_spec_check and original_spec != static_spec:
          raise ValueError(
              "Arg specs do not match: original={}, static={}, fn={}".format(
                  original_spec, static_spec, original_fn
              )
          )
  
      @decorator.decorator
      def wrap(wrapped_fn, *args, **kwargs):
          """The actual wrapper."""
          del wrapped_fn
          flat_args = tf.nest.flatten([args, kwargs])
          # N.B.: This `get_static_value` is nontrivial even in Eager mode, because
          # Keras's symbolic Tensors can exist when executing eagerly, and their
          # static values can be `None`.
          flat_args_ = [tf.get_static_value(a) for a in flat_args]
          all_static = all(
              arg is None or arg_ is not None
              for arg, arg_ in zip(flat_args, flat_args_)
          )
          if all_static:
              [args_, kwargs_] = tf.nest.pack_sequence_as(
                  [args, kwargs], flat_args_
              )
              return static_fn(*args_, **kwargs_)
          return original_fn(*args, **kwargs)
  
      return wrap(original_fn)
  
imports: import decorator
  import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.internal.backend import numpy
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.ops import control_flow_case
  from tensorflow.python.util import tf_inspect
label_desc: Use image node_id 2 for calling a global function with example usage: _prefer_static(original_fn, static_fn, disable_spec_check) and returns: wrap, original_fn, static_fn