code: def _compute_tmc_factors(model_trace, guide_trace):
      """
      compute per-site log-factors for all observed and unobserved variables
      log-factors are log(p / q) for unobserved sites and log(p) for observed sites
      """
      log_factors = []
      for name, site in guide_trace.nodes.items():
          if site["type"] != "sample" or site["is_observed"]:
              continue
          log_proposal = site["packed"]["log_prob"]
          log_factors.append(packed.neg(log_proposal))
      for name, site in model_trace.nodes.items():
          if site["type"] != "sample":
              continue
          if (
              site["name"] not in guide_trace
              and not site["is_observed"]
              and site["infer"].get("enumerate", None) == "parallel"
              and site["infer"].get("num_samples", -1) > 0
          ):
              # site was sampled from the prior
              log_proposal = packed.neg(site["packed"]["log_prob"])
              log_factors.append(log_proposal)
          log_factors.append(site["packed"]["log_prob"])
      return log_factors
  
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 2 for calling a global function with example usage: _compute_tmc_factors(model_trace, guide_trace) and returns: log_factors