code: def test_plate_elbo_vectorized_particles(Elbo, reparameterized):
      pyro.clear_param_store()
      data = torch.tensor([-0.5, 2.0])
      num_particles = 200000
      precision = 0.06
      Normal = (
          dist.Normal
          if reparameterized
          else fakes.NonreparameterizedNormal
      )
  
      def model():
          data_plate = pyro.plate("data", len(data))
  
          pyro.sample("nuisance_a", Normal(0, 1))
          with data_plate:
              z = pyro.sample("z", Normal(0, 1))
          pyro.sample("nuisance_b", Normal(2, 3))
          with data_plate:
              pyro.sample("x", Normal(z, 1), obs=data)
          pyro.sample("nuisance_c", Normal(4, 5))
  
      def guide():
          loc = pyro.param("loc", torch.zeros(len(data)))
          scale = pyro.param("scale", torch.tensor([1.0]))
  
          pyro.sample("nuisance_c", Normal(4, 5))
          with pyro.plate("data", len(data)):
              pyro.sample("z", Normal(loc, scale))
          pyro.sample("nuisance_b", Normal(2, 3))
          pyro.sample("nuisance_a", Normal(0, 1))
  
      optim = Adam({"lr": 0.1})
      loss = Elbo(
          num_particles=num_particles,
          vectorize_particles=True,
          strict_enumeration_warning=False,
      )
      inference = SVI(model, guide, optim, loss=loss)
      inference.loss_and_grads(model, guide)
      params = dict(pyro.get_param_store().named_parameters())
      actual_grads = {
          name: param.grad.detach().cpu().numpy()
          for name, param in params.items()
      }
  
      expected_grads = {
          "loc": np.array([0.5, -2.0]),
          "scale": np.array([2.0]),
      }
      for name in sorted(params):
          logger.info(
              "expected {} = {}".format(name, expected_grads[name])
          )
          logger.info(
              "actual   {} = {}".format(name, actual_grads[name])
          )
      assert_equal(actual_grads, expected_grads, prec=precision)
  
file_path: pyro/tests/infer/test_gradient.py
imports: import logging
  import numpy
  import pytest
  import torch
  import torch.optim
  from torch.distributions import constraints
  import pyro
  import pyro.distributions
  import pyro.poutine
  from pyro.distributions.testing import fakes
  from pyro.infer import SVI, JitTrace_ELBO, JitTraceEnum_ELBO, JitTraceGraph_ELBO, JitTraceMeanField_ELBO, Trace_ELBO, TraceEnum_ELBO, TraceGraph_ELBO, TraceMeanField_ELBO, config_enumerate
  from pyro.optim import Adam
  from tests.common import assert_equal, xfail_if_not_implemented, xfail_param
label_desc: Use image node_id 5 for calling a global function with example usage: test_plate_elbo_vectorized_particles(Elbo, reparameterized) without return types