code: def _resolve_distribution_names(
      dist_fn_args, dist_names, leaf_name, instance_names
  ):
      """Uses arg names to resolve distribution names."""
      if dist_names is None:
          dist_names = []
      else:
          dist_names = dist_names.copy()
      n = len(dist_fn_args)
      dist_names.extend([None] * (n - len(dist_names)))
  
      # First, fill in distribution names by the function args used to refer
      # to them (e.g., in `[tfd.Normal(0., 1), lambda x: tfd.Normal(x, 1.)]`
      # the first distribution is named `x`.
      name_is_nontrivial = lambda name: name and name != "_"
      for i_, args in enumerate(reversed(dist_fn_args)):
          if not args:
              continue  # There's no args to analyze.
          i = n - i_ - 1
          for j, arg_name in enumerate(args):
              if name_is_nontrivial(arg_name):
                  existing_name = dist_names[i - j - 1]
                  if (
                      name_is_nontrivial(existing_name)
                      and existing_name != arg_name
                  ):
                      raise ValueError(
                          'Inconsistent names: component with name "{}" was '
                          'referred to by a different name "{}".'.format(
                              arg_name, existing_name
                          )
                      )
                  dist_names[i - j - 1] = arg_name
  
      # Then, fill in names using any user-provided `name` arguments (e.g.,
      # `tfd.Normal(0., 1., name='x')`.
      for i in range(len(dist_names)):
          if instance_names[i] is not None:
              if (
                  name_is_nontrivial(dist_names[i])
                  and dist_names[i] != instance_names[i]
              ):
                  raise ValueError(
                      'Inconsistent names: component with name "{}" was '
                      'referred to by a different name "{}".'.format(
                          instance_names[i], dist_names[i]
                      )
                  )
              else:
                  dist_names[i] = instance_names[i]
  
      # Finally generate unique dummy names for any remaining components.
      unavailable_names = set(dist_names)
      j = 0
      for i_ in range(len(dist_names)):
          i = n - i_ - 1
          if not name_is_nontrivial(dist_names[i]):
              # TODO(davmre): consider wrapping dummy names with `<>` to prevent them
              # from being passed as kwargs.
              dummy_name = "{}{}".format(leaf_name, j if j else "")
              while dummy_name in unavailable_names:
                  j += 1
                  dummy_name = "{}{}".format(leaf_name, j)
              dist_names[i] = dummy_name
              unavailable_names.add(dummy_name)
  
      return tuple(dist_names)
  
imports: import collections
  import functools
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import joint_distribution
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.internal import auto_composite_tensor
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow.python.util import tf_inspect
label_desc: Use image node_id 3 for calling a global function with example usage: _resolve_distribution_names(dist_fn_args, dist_names, leaf_name, instance_names) and returns: tuple