Times Series Model getting NotImplementedError: AutoGuideList does not support sequential pyro.plate

I’m trying to make a very simple autoregressive time series model/state space model/linear dynamical system. My generative process seems to work fine and make sense but having issues with inference.

I’m just trying to run inference on a single sequence of data with shape 100x5, i.e. 100 time steps with 5 features (no multiple minibatches). I’d like use variational inference with a normalizing flow, so I tried using the autoguide IAF but get the error in the title. I’m not sure if this is just a limitation of the autoguides or if my model is incorrect and I’m misunderstanding something basic. Any help is much appreciated.

class PyroLDS(nn.Module):
    def __init__(self, latent_init, latent_dim = 3, data_dim = 5):
        self.latent_dim = latent_dim
        self.data_dim = data_dim
        self.A = to.rand(latent_dim,latent_dim)
        self.C = to.rand(data_dim,latent_dim)
        assert latent_init.shape[0] == latent_dim
        self.lastx = latent_init
        
    def model(self,data=None):
        assert type(data) is to.Tensor or data == None
        length = 1 if data is None else data.shape[0]
        y = to.zeros(length,self.data_dim)
        for i in pyro.plate("myplate",length):
            a_loc, a_scale = to.Tensor([0]), to.Tensor([1])
            a_noise = pyro.sample("a_noise-{}".format(i,), dist.Normal(loc=a_loc,scale=a_scale).to_event(1))
            x2 = (self.A @ self.lastx + a_noise).flatten()
            self.lastx = x2
            c_loc, c_scale = to.Tensor([0]), to.Tensor([1])
            c_noise = pyro.sample("c_noise-{}".format(i,), dist.Normal(loc=c_loc,scale=c_scale).to_event(1))
            y_loc = self.C @ x2 + c_noise
            y_scale = to.Tensor([1]).repeat(self.data_dim)
            y[i] = pyro.sample("y-{}".format(i,),dist.Normal(loc=y_loc,scale=y_scale),\
                               obs=data[i,:] if data is not None else None)
        return y
problds = PyroLDS(to.Tensor([0.1,0.1,0.1]))
guide = AutoDelta(problds.model)
# set up the optimizer
pyro.clear_param_store()
pyro.enable_validation(True)
adam_params = {"lr": 0.0005, "betas": (0.90, 0.999)}
optimizer = Adam(adam_params)

# setup the inference algorithm
svi = SVI(problds.model, guide, optimizer, loss=Trace_ELBO())

n_steps = 100
# do gradient steps
for step in range(n_steps):
    svi.step(testdata)
~/anaconda3/envs/deeprl/lib/python3.6/site-packages/pyro/contrib/autoguide/__init__.py in _setup_prototype(self, *args, **kwargs)
    115                     self._plates[frame.name] = frame
    116                 else:
--> 117                     raise NotImplementedError("AutoGuideList does not support sequential pyro.plate")
    118 
    119     def median(self, *args, **kwargs):

NotImplementedError: AutoGuideList does not support sequential pyro.plate
Trace Shapes:
 Param Sites:
Sample Sites:

I got it to work, I made some errors including changing pyro.plate to pyro.markov

Hi, I also face similar problems. How do you solve it? Thank you very much!