code: def test_predictive(num_samples, parallel):
      model, data, true_probs = beta_bernoulli()
      init_params, potential_fn, transforms, _ = initialize_model(
          model, model_args=(data,)
      )
      nuts_kernel = NUTS(
          potential_fn=potential_fn, transforms=transforms
      )
      mcmc = MCMC(
          nuts_kernel, 100, initial_params=init_params, warmup_steps=100
      )
      mcmc.run(data)
      samples = mcmc.get_samples()
      with optional(
          pytest.warns(UserWarning), num_samples not in (None, 100)
      ):
          predictive = Predictive(
              model,
              samples,
              num_samples=num_samples,
              return_sites=["beta", "obs"],
              parallel=parallel,
          )
          predictive_samples = predictive()
  
      # check shapes
      assert predictive_samples["beta"].shape == (100, 1, 5)
      assert predictive_samples["obs"].shape == (100, 1000, 5)
  
      # check sample mean
      assert_close(
          predictive_samples["obs"].reshape([-1, 5]).mean(0),
          true_probs,
          rtol=0.1,
      )
  
file_path: pyro/tests/infer/mcmc/test_mcmc_util.py
imports: from functools import partial
  import pytest
  import torch
  import pyro
  import pyro.distributions
  from pyro.infer import Predictive
  from pyro.infer.autoguide import init_to_feasible, init_to_generated, init_to_mean, init_to_median, init_to_sample, init_to_uniform, init_to_value
  from pyro.infer.mcmc import NUTS
  from pyro.infer.mcmc.api import MCMC
  from pyro.infer.mcmc.util import initialize_model
  from pyro.util import optional
  from tests.common import assert_close, str_erase_pointers
label_desc: Use image node_id 2 for calling a global function with example usage: test_predictive(num_samples, parallel) without return types