code: def _predictive_sequential(
      model,
      posterior_samples,
      model_args,
      model_kwargs,
      num_samples,
      return_site_shapes,
      return_trace=False,
  ):
      collected = []
      samples = [
          {k: v[i] for k, v in posterior_samples.items()}
          for i in range(num_samples)
      ]
      for i in range(num_samples):
          trace = poutine.trace(
              poutine.condition(model, samples[i])
          ).get_trace(*model_args, **model_kwargs)
          if return_trace:
              collected.append(trace)
          else:
              collected.append(
                  {
                      site: trace.nodes[site]["value"]
                      for site in return_site_shapes
                  }
              )
  
      if return_trace:
          return collected
      else:
          return {
              site: torch.stack([s[site] for s in collected]).reshape(
                  shape
              )
              for site, shape in return_site_shapes.items()
          }
  
file_path: pyro/pyro/infer/predictive.py
imports: import warnings
  from functools import reduce
  import torch
  import pyro
  import pyro.poutine
  from pyro.poutine.util import prune_subsample_sites
label_desc: Use image node_id 2 for calling a global function with example usage: _predictive_sequential(model, posterior_samples, model_args, model_kwargs, num_samples, return_site_shapes, return_trace) and returns: collected, unknown