code: def test_cache():
      class MyModule(PyroModule):
          def forward(self):
              return [self.gather(), self.gather()]
  
          def gather(self):
              return {
                  "a": self.a,
                  "b": self.b,
                  "c": self.c,
                  "p.d": self.p.d,
                  "p.e": self.p.e,
                  "p.f": self.p.f,
              }
  
      module = MyModule()
      module.a = nn.Parameter(torch.tensor(0.0))
      module.b = PyroParam(
          torch.tensor(1.0), constraint=constraints.positive
      )
      module.c = PyroSample(dist.Normal(0, 1))
      module.p = PyroModule()
      module.p.d = nn.Parameter(torch.tensor(3.0))
      module.p.e = PyroParam(
          torch.tensor(4.0), constraint=constraints.positive
      )
      module.p.f = PyroSample(dist.Normal(0, 1))
  
      assert module._pyro_context is module.p._pyro_context
  
      # Check that results are cached with an invocation of .__call__().
      result1 = module()
      actual, expected = result1
      for key in ["a", "c", "p.d", "p.f"]:
          assert actual[key] is expected[key], key
  
      # Check that results are not cached across invocations of .__call__().
      result2 = module()
      for key in ["b", "c", "p.e", "p.f"]:
          assert result1[0] is not result2[0], key
  
imports: import io
  import warnings
  import pytest
  import torch
  from torch import nn
  from torch.distributions import constraints, transform_to
  import pyro
  import pyro.distributions
  from pyro import poutine
  from pyro.infer import SVI, Trace_ELBO
  from pyro.nn.module import PyroModule, PyroParam, PyroSample, clear, to_pyro_module_
  from pyro.optim import Adam
  from tests.common import assert_equal
label_desc: Use image node_id 13 for calling a global function with example usage: test_cache() and returns: list, dict