code: def init_to_median(
      site=None,
      num_samples=15,
      *,
      fallback: Optional[Callable] = init_to_feasible,
  ):
      """
      Initialize to the prior median; fallback to ``fallback`` (defaults to
      :func:`init_to_feasible`) if mean is undefined.
  
      :param callable fallback: Fallback init strategy, for sites not specified
          in ``values``.
      :raises ValueError: If ``fallback=None`` and no value for a site is given
          in ``values``.
      """
      if site is None:
          return functools.partial(
              init_to_median, num_samples=num_samples, fallback=fallback
          )
  
      # The median undefined for multivariate distributions.
      if _is_multivariate(site["fn"]):
          return init_to_feasible(site)
      try:
          # Try to compute empirical median.
          samples = site["fn"].sample(sample_shape=(num_samples,))
          value = samples.median(dim=0)[0]
          if torch_isnan(value):
              raise ValueError
          if hasattr(site["fn"], "_validate_sample"):
              site["fn"]._validate_sample(value)
          value._pyro_custom_init = False
          return value
      except (RuntimeError, ValueError):
          pass
      if fallback is not None:
          return fallback(site)
      raise ValueError(
          f"No init strategy specified for site {repr(site['name'])}"
      )
  
imports: import functools
  from typing import Callable, Optional
  import torch
  from torch.distributions import transform_to
  from pyro.distributions.torch import Independent
  from pyro.distributions.torch_distribution import MaskedDistribution
  from pyro.infer.util import is_validation_enabled
  from pyro.poutine.messenger import Messenger
  from pyro.util import torch_isnan
  from .utils import helpful_support_errors
label_desc: Use image node_id 4 for calling a global function with example usage: init_to_median(site, num_samples) and returns: functools, init_to_feasible, value, fallback