code: def _find_valid_initial_params(
      model,
      model_args,
      model_kwargs,
      transforms,
      potential_fn,
      prototype_params,
      max_tries_initial_params=100,
      num_chains=1,
      init_strategy=init_to_uniform,
      trace=None,
  ):
      params = prototype_params
  
      # For empty models, exit early
      if not params:
          return params
  
      params_per_chain = defaultdict(list)
      num_found = 0
      model = InitMessenger(init_strategy)(model)
      for attempt in range(num_chains * max_tries_initial_params):
          if trace is None:
              trace = poutine.trace(model).get_trace(
                  *model_args, **model_kwargs
              )
          samples = {
              name: trace.nodes[name]["value"].detach()
              for name in params
          }
          params = {k: transforms[k](v) for k, v in samples.items()}
          pe_grad, pe = potential_grad(potential_fn, params)
  
          if torch.isfinite(pe) and all(
              map(torch.all, map(torch.isfinite, pe_grad.values()))
          ):
              for k, v in params.items():
                  params_per_chain[k].append(v)
              num_found += 1
              if num_found == num_chains:
                  if num_chains == 1:
                      return {
                          k: v[0] for k, v in params_per_chain.items()
                      }
                  else:
                      return {
                          k: torch.stack(v)
                          for k, v in params_per_chain.items()
                      }
          trace = None
      raise ValueError(
          "Model specification seems incorrect - cannot find valid initial params."
      )
  
imports: import functools
  import traceback
  import warnings
  from collections import OrderedDict, defaultdict
  from functools import partial, reduce
  from itertools import product
  import torch
  from opt_einsum import shared_intermediates
  from torch.distributions import biject_to
  import pyro
  import pyro.poutine
  from pyro.distributions.util import broadcast_shape, logsumexp
  from pyro.infer import config_enumerate
  from pyro.infer.autoguide.initialization import InitMessenger, init_to_uniform
  from pyro.infer.util import is_validation_enabled
  from pyro.ops import stats
  from pyro.ops.contract import contract_to_tensor
  from pyro.ops.integrator import potential_grad
  from pyro.poutine.subsample_messenger import _Subsample
  from pyro.poutine.util import prune_subsample_sites
  from pyro.util import check_site_shape, ignore_jit_warnings
label_desc: Use image node_id 2 for calling a global function with example usage: _find_valid_initial_params(model, model_args, model_kwargs, transforms, potential_fn, prototype_params, max_tries_initial_params, num_chains, init_strategy, trace) and returns: params, unknown, unknown