code: def _prob_chain_rule_model_flatten(named_makers):
      """Creates lists of callables suitable for JDSeq."""
  
      def _make(dist_fn, args):
          if args is None:
              return lambda *_: dist_fn
          if not args:
              return lambda *_: dist_fn()
  
          def _fn(*xs):
              kwargs = dict(
                  [
                      (k, v)
                      for k, v in zip(dist_fn_name, xs)
                      if k in args
                  ]
              )
              return dist_fn(**kwargs)
  
          return _fn
  
      named_makers = _convert_to_dict(named_makers)
  
      previous_keys = []
      parents = type(named_makers)()
      for key, dist_fn in named_makers.items():
          if distribution_util.is_distribution_instance(dist_fn):
              parents[key] = None  # pylint: disable=g-long-lambda
          else:
              parents[
                  key
              ] = joint_distribution_sequential._get_required_args(  # pylint: disable=protected-access
                  dist_fn,
                  # To ensure an acyclic dependence graph, a dist_fn that takes
                  # `**kwargs` is treated as depending on all distributions that were
                  # defined above it, but not any defined below it.
                  previous_args=previous_keys,
              )
          previous_keys.append(key)
  
      g = _best_order(parents)
      dist_fn_name, dist_fn_args = zip(*g)
      dist_fn_args = tuple(
          None if a is None else tuple(a) for a in dist_fn_args
      )
      dist_fn_wrapped = tuple(
          _make(named_makers[name], parents) for (name, parents) in g
      )
      dist_fn = tuple(named_makers.get(n) for n in dist_fn_name)
      return dist_fn, dist_fn_wrapped, dist_fn_args, dist_fn_name
  
imports: import collections
  import functools
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import joint_distribution_sequential
  from tensorflow_probability.python.internal import auto_composite_tensor
  from tensorflow_probability.python.internal import distribution_util
label_desc: Use image node_id 3 for calling a global function with example usage: _prob_chain_rule_model_flatten(named_makers) and returns: dist_fn,  dist_fn_wrapped,  dist_fn_args,  dist_fn_name, _fn, function, function, dist_fn