code: def no_tf_rank_errors():
      # TODO(axch): Instead of catching and `assume`ing away rank errors, could try
      # harder to avoid generating them in the first place.  For instance, could add
      # a parameter to `valid_slices` that limits how much the rank may increase
      # after the slice.  Trouble is, predicting what limits to set is difficult
      # because rank handling is non-uniform, and actually meeting them is also
      # non-trivial because in addition to the batch shape there is the event shape,
      # and at least one more dimention added by `sample`, and the parameters may
      # have larger "event" shapes than the distribution itself.
      input_dims_pat = r"Unhandled input dimensions (8|9|[1-9][0-9]+)"
      input_rank_pat = r"inputs rank not in \[0,([6-9]|[1-9][0-9]+)\]"
      is_not_implemented_pat = (
          r"is not implemented for tensors of "
          r"rank > (8|9|[1-9][0-9]+)."
      )
      does_not_work_pat = (
          r"does not work on tensors with "
          r"more than (8|9|[1-9][0-9]+) dimensions"
      )
      only_support_pat = r"only support up to 7 input dimensions"
      pat_1 = _rank_broadcasting_error_pattern(1, 6)
      pat_2 = _rank_broadcasting_error_pattern(6, 1)
      try:
          yield
      except tf.errors.UnimplementedError as e:
          # TODO(b/138385438): This really shouldn't be so complicated.
          # Bug requesting that TF increase the rank limit: b/137689241.
          # See also b/148230377.
          msg = str(e)
          if re.search(pat_1, msg) or re.search(pat_2, msg):
              # We asked some op to broadcast Tensors one of whose ranks >= 6.
              hp.assume(False)
          elif re.search(input_dims_pat, msg):
              # We asked some TF op (StridedSlice?) to operate on a Tensor of rank >= 8.
              hp.assume(False)
          elif re.search(input_rank_pat, msg):
              # We asked some TF op (PadV2?) to operate on a Tensor of rank >= 7.
              hp.assume(False)
          elif re.search(is_not_implemented_pat, msg):
              # We asked some different TF op (ReverseV2?) to operate on a Tensor of
              # rank >= 8.
              hp.assume(False)
          else:
              raise
      except tf.errors.InvalidArgumentError as e:
          msg = str(e)
          if re.search(only_support_pat, msg):
              # We asked some TF op (Argmin/Argmax/...) to operate on a Tensor of
              # rank >= 8.
              hp.assume(False)
          else:
              raise
      except ValueError as e:
          msg = str(e)
          if re.search(does_not_work_pat, msg):
              # We asked some yet different TF op (ReverseV2 in graph mode?) to operate
              # on a Tensor of rank >= 8.
              hp.assume(False)
          else:
              raise
  
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 29 for calling a global function with example usage: no_tf_rank_errors() without return types