code: def test_contract_tensor_tree(example):
      symbol_to_size = dict(zip("abcdij", [4, 5, 6, 7, 2, 3]))
      tensor_tree = OrderedDict()
      for t, shapes in example["shape_tree"].items():
          for dims in shapes:
              tensor = torch.randn(
                  tuple(symbol_to_size[s] for s in dims)
              )
              tensor._pyro_dims = dims
              tensor_tree.setdefault(t, []).append(tensor)
      sum_dims = example["sum_dims"]
  
      tensor_tree = assert_immutable(contract_tensor_tree)(
          tensor_tree, sum_dims
      )
      assert tensor_tree
      for ordinal, terms in tensor_tree.items():
          for term in terms:
              for frame in ordinal:
                  assert term.shape[frame.dim] == frame.size
  
imports: import itertools
  import numbers
  from collections import OrderedDict
  import opt_einsum
  import pytest
  import torch
  import pyro.ops.jit
  from pyro.distributions.util import logsumexp
  from pyro.ops.contract import _partition_terms, contract_tensor_tree, contract_to_tensor, einsum, naive_ubersum, ubersum
  from pyro.ops.einsum.adjoint import require_backward
  from pyro.ops.rings import LogRing
  from pyro.poutine.indep_messenger import CondIndepStackFrame
  from pyro.util import optional
  from tests.common import assert_equal
label_desc: Use image node_id 8 for calling a global function with example usage: test_contract_tensor_tree(example) without return types