Guide for models with unknown samples

I have a somewhat newbie question. I went through the first tutorial (An Introduction to Models in Pyro). The following example is given:

def geometric(p, t=None):
    if t is None:
        t = 0
    x = pyro.sample("x_{}".format(t), pyro.distributions.Bernoulli(p))
    if x.item() == 1:
        return 0
        return 1 + geometric(p, t + 1)

The point is that the models can dynamically sample new variables depending on previous sample outcomes. Then I went through the second tutorial (An Introduction to Inference in Pyro) and there it is explained that the guide functions must satisfy 2 conditions:

  1. all unobserved (i.e., not conditioned) sample statements that appear in the model appear in the guide
  2. the guide has the same input signature as the model (i.e., takes the same arguments)

Let’s say I have some observations for the geometric model x_0, x_1, …, x_n. I can condition the geometric model with the observations and get a new model. However I don’t get how the guide function can sample all unobserved samples, because if the model is ran it can go and try to sample for x_n+1, x_n+2 and so on. Should the guide assume that there can be no such samples because the model is conditioned? How should situations where the guide cannot know what variables will be created be handled?

this is something that may become clearer as you read onwards to the SVI tutorials. essentially, in variational inference, the expectation we compute is with respect to q (the guide), and not the model. what that means in practice is that we never need to sample from the model. so in your example above, the guide is run before the model, and the value x_i sampled in the guide are then used inside the model. in other words, the model “depends” on the guide for the samples, not the other way around.