code: def _compute_dice_elbo(model_trace, guide_trace):
      # Accumulate marginal model costs.
      (
          marginal_costs,
          log_factors,
          ordering,
          sum_dims,
          scale,
      ) = _compute_model_factors(model_trace, guide_trace)
      if log_factors:
          dim_to_size = {}
          for terms in log_factors.values():
              for term in terms:
                  dim_to_size.update(zip(term._pyro_dims, term.shape))
  
          # Note that while most applications of tensor message passing use the
          # contract_to_tensor() interface and can be easily refactored to use ubersum(),
          # the application here relies on contract_tensor_tree() to extract the dependency
          # structure of different log_prob terms, which is used by Dice to eliminate
          # zero-expectation terms. One possible refactoring would be to replace
          # contract_to_tensor() with a RaggedTensor -> Tensor contraction operation, but
          # replace contract_tensor_tree() with a RaggedTensor -> RaggedTensor contraction
          # that preserves some dependency structure.
          with shared_intermediates() as cache:
              ring = SampleRing(cache=cache, dim_to_size=dim_to_size)
              log_factors = contract_tensor_tree(
                  log_factors, sum_dims, ring=ring
              )
              model_trace._sharing_cache = (
                  cache  # For TraceEnumSample_ELBO.
              )
          for t, log_factors_t in log_factors.items():
              marginal_costs_t = marginal_costs.setdefault(t, [])
              for term in log_factors_t:
                  term = packed.scale_and_mask(term, scale=scale)
                  marginal_costs_t.append(term)
      costs = marginal_costs
  
      # Accumulate negative guide costs.
      for name, site in guide_trace.nodes.items():
          if site["type"] == "sample":
              cost = packed.neg(site["packed"]["log_prob"])
              costs.setdefault(ordering[name], []).append(cost)
  
      return Dice(guide_trace, ordering).compute_expectation(costs)
  
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 6 for calling a global function with example usage: _compute_dice_elbo(model_trace, guide_trace) and returns: Dice