code: def _compute_dice_factors(model_trace, guide_trace):
      """
      compute per-site DiCE log-factors for non-reparameterized proposal sites
      this logic is adapted from pyro.infer.util.Dice.__init__
      """
      log_probs = []
      for role, trace in zip(
          ("model", "guide"), (model_trace, guide_trace)
      ):
          for name, site in trace.nodes.items():
              if site["type"] != "sample" or site["is_observed"]:
                  continue
              if role == "model" and name in guide_trace:
                  continue
  
              log_prob, log_denom = compute_site_dice_factor(site)
              if not is_identically_zero(log_denom):
                  dims = log_prob._pyro_dims
                  log_prob = log_prob - log_denom
                  log_prob._pyro_dims = dims
              if not is_identically_zero(log_prob):
                  log_probs.append(log_prob)
  
      return log_probs
  
imports: import queue
  import warnings
  import torch
  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 compute_site_dice_factor, is_validation_enabled, torch_item
  from pyro.ops import packed
  from pyro.ops.contract import einsum
  from pyro.poutine.enum_messenger import EnumMessenger
  from pyro.util import check_traceenum_requirements, warn_if_nan
label_desc: Use image node_id 1 for calling a global function with example usage: _compute_dice_factors(model_trace, guide_trace) and returns: log_probs