code: def test_deterministic(with_plate, event_shape):
      def model(y=None):
          with pyro.util.optional(pyro.plate("plate", 3), with_plate):
              x = pyro.sample(
                  "x", dist.Normal(0, 1).expand(event_shape).to_event()
              )
              x2 = pyro.deterministic(
                  "x2", x**2, event_dim=len(event_shape)
              )
  
          pyro.deterministic("x3", x2)
          return pyro.sample(
              "obs", dist.Normal(x2, 0.1).to_event(), obs=y
          )
  
      y = torch.tensor(4.0)
      guide = AutoDiagonalNormal(model)
      svi = SVI(model, guide, optim.Adam(dict(lr=0.1)), Trace_ELBO())
      for i in range(100):
          svi.step(y)
  
      actual = Predictive(
          model,
          guide=guide,
          return_sites=["x2", "x3"],
          num_samples=1000,
      )()
      x2_batch_shape = (3,) if with_plate else ()
      assert (
          actual["x2"].shape == (1000,) + x2_batch_shape + event_shape
      )
      # x3 shape is prepended 1 to match Pyro shape semantics
      x3_batch_shape = (1, 3) if with_plate else ()
      assert (
          actual["x3"].shape == (1000,) + x3_batch_shape + event_shape
      )
      assert_close(actual["x2"].mean(), y, rtol=0.1)
      assert_close(actual["x3"].mean(), y, rtol=0.1)
  
file_path: pyro/tests/infer/test_predictive.py
imports: import pytest
  import torch
  import pyro
  import pyro.distributions
  import pyro.optim
  import pyro.poutine
  from pyro.infer import SVI, Predictive, Trace_ELBO
  from pyro.infer.autoguide import AutoDelta, AutoDiagonalNormal
  from tests.common import assert_close
label_desc: Use image node_id 9 for calling a global function with example usage: test_deterministic(with_plate, event_shape) and returns: pyro