code: def _compute_marginals(model_trace, guide_trace):
      args = _compute_model_factors(model_trace, guide_trace)
      marginal_costs, log_factors, ordering, sum_dims, scale = args
  
      marginal_dists = OrderedDict()
      with shared_intermediates() as cache:
          for name, site in model_trace.nodes.items():
              if (
                  site["type"] != "sample"
                  or name in guide_trace.nodes
                  or site["infer"].get("_enumerate_dim") is None
              ):
                  continue
  
              enum_dim = site["infer"]["_enumerate_dim"]
              enum_symbol = site["infer"]["_enumerate_symbol"]
              ordinal = _find_ordinal(model_trace, site)
              logits = contract_to_tensor(
                  log_factors,
                  sum_dims,
                  target_ordinal=ordinal,
                  target_dims={enum_symbol},
                  cache=cache,
              )
              logits = packed.unpack(logits, model_trace.symbol_to_dim)
              logits = logits.unsqueeze(-1).transpose(-1, enum_dim - 1)
              while logits.shape[0] == 1:
                  logits = logits.squeeze(0)
              marginal_dists[name] = _make_dist(site["fn"], logits)
      return marginal_dists
  
imports: import queue
  import warnings
  import weakref
  from collections import OrderedDict
  import torch
  from opt_einsum import shared_intermediates
  import pyro
  import pyro.distributions
  import pyro.ops.jit
  import pyro.poutine
  from pyro.distributions.util import is_identically_zero
  from pyro.infer.elbo import ELBO
  from pyro.infer.enum import get_importance_trace, iter_discrete_escape, iter_discrete_extend
  from pyro.infer.util import Dice, is_validation_enabled
  from pyro.ops import packed
  from pyro.ops.contract import contract_tensor_tree, contract_to_tensor
  from pyro.ops.rings import SampleRing
  from pyro.poutine.enum_messenger import EnumMessenger
  from pyro.util import check_traceenum_requirements, ignore_jit_warnings, warn_if_nan
label_desc: Use image node_id 8 for calling a global function with example usage: _compute_marginals(model_trace, guide_trace) and returns: marginal_dists