Question on Predictive

Hi All

It is nice to use Predictive facility to get samples after model training. However I am not sure what is the right way to apply Predictive over a trained GPRegression model. It gives me the following error

for name, sample in posterior_samples.items():
AttributeError: 'function' object has no attribute 'items'

Any suggestion? For your convenience, I include the code below

import torch
import numpy as np
import pandas as pd
from torch.distributions import constraints
import pyro
import pyro.distributions as dist
import pyro.optim as optim
from pyro.infer import SVI, Trace_ELBO
from pyro.infer import Predictive
import as gp

assert pyro.__version__.startswith('1.8.4')

# Data
N = 20
X = dist.Uniform(0.0, 5.0).sample(sample_shape=(N,))
y = 0.5 * torch.sin(3 * X) + dist.Normal(0.0, 0.2).sample(sample_shape=(N,))
kernel = gp.kernels.RBF(
    input_dim=1, variance=torch.tensor(6.0), lengthscale=torch.tensor(0.05)
gpr = gp.models.GPRegression(X, y, kernel, noise=torch.tensor(0.1))

# note that our priors have support on the positive reals
gpr.kernel.a_scale = pyro.param('a_scale', torch.tensor(1.),
gpr.kernel.lengthscale = pyro.nn.PyroSample(lambda self: dist.LogNormal(0.0, self.a_scale))
gpr.kernel.variance = pyro.nn.PyroSample(dist.LogNormal(0.0, 1.0))

optimizer = torch.optim.Adam(gpr.parameters(), lr=0.005)  
num_steps = 200
loss = Trace_ELBO(retain_graph=True)
svi = SVI(gpr.model,, optim.Adam({"lr": .05}), loss=loss)

for i in range(num_steps):
    elbo = svi.step()
    if i % 50 == 0:"Elbo loss: {}".format(elbo))

num_samples = 23
predictive = Predictive(gpr.model,, num_samples=num_samples)
A = predictive(X)
svi_samples = {k: v.reshape(num_samples).detach().cpu().numpy()
               for k, v in A.items()
               if k != "obs"}

Know why now.