code: def test_svi_elbomodule_interface(
      local_params, num_particles, vectorize_particles, Autoguide
  ):
      class Model(PyroModule):
          def __init__(self):
              super().__init__()
              self.loc = nn.Parameter(torch.zeros(2))
              self.scale = PyroParam(
                  torch.ones(2), constraint=constraints.positive
              )
              self.z = PyroSample(
                  lambda self: dist.Normal(
                      self.loc, self.scale
                  ).to_event(1)
              )
  
          def forward(self, data):
              loc, log_scale = self.z.unbind(-1)
              with pyro.plate("data"):
                  pyro.sample(
                      "obs", dist.Cauchy(loc, log_scale.exp()), obs=data
                  )
  
      with pyro.settings.context(module_local_params=local_params):
          data = torch.randn(5)
          model = Model()
          model(data)  # initialize
  
          guide = Autoguide(model)
          guide(data)  # initialize
  
          elbo = Trace_ELBO(
              vectorize_particles=vectorize_particles,
              num_particles=num_particles,
          )
          elbo = elbo(model, guide)
          assert isinstance(elbo, torch.nn.Module)
          assert set(
              k[: -len("_unconstrained")]
              if k.endswith("_unconstrained")
              else k
              for k, v in elbo.named_parameters()
          ) == set(
              "model." + k for k, v in model.named_pyro_params()
          ) | set(
              "guide." + k for k, v in guide.named_pyro_params()
          )
  
          adam = torch.optim.Adam(elbo.parameters(), lr=0.0001)
          for _ in range(3):
              adam.zero_grad()
              loss = elbo(data)
              loss.backward()
              adam.step()
  
          guide2 = Autoguide(model)
          guide2(data)  # initialize
          if local_params:
              assert set(pyro.get_param_store().keys()) == set()
              for (name, p), (name2, p2) in zip(
                  guide.named_parameters(), guide2.named_parameters()
              ):
                  assert name == name2
                  assert not torch.allclose(p, p2)
          else:
              assert set(pyro.get_param_store().keys()) != set()
              for (name, p), (name2, p2) in zip(
                  guide.named_parameters(), guide2.named_parameters()
              ):
                  assert name == name2
                  assert torch.allclose(p, p2)
  
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 2 for calling a global function with example usage: test_svi_elbomodule_interface(local_params, num_particles, vectorize_particles, Autoguide) without return types