code: def as_stateless_builder(generator):
      """Wraps a generator to build a stateless init_fn/apply_fn pair."""
  
      @functools.wraps(generator)
      def build_stateless_trainable(*args, **kwargs):
          g = functools.partial(generator, *args, **kwargs)
          init_fn = lambda seed=None: _initialize_parameters(g, seed)
          apply_fn = lambda *parameters: _apply_parameters(
              g, *parameters
          )
          return init_fn, apply_fn
  
      # Replace `Yields` section of docstring with `Returns` init_fn/apply_fn.
      if generator.__doc__:
          doc = inspect.cleandoc(generator.__doc__)
          doc = re.sub(
              r"Yields:\n(.+\n)+\n",
              _STATELESS_RETURNS_DOCSTRING,
              doc + "\n\n",
          )
          build_stateless_trainable.__doc__ = doc
  
      return build_stateless_trainable
  
file_path: probability/tensorflow_probability/python/internal/trainable_state_util.py
imports: import collections
  import functools
  import inspect
  import re
  import types
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import structural_tuple
label_desc: Use image node_id 6 for calling a global function with example usage: as_stateless_builder(generator) and returns: build_stateless_trainable, init_fn,  apply_fn