Clarification reagrding svi.step

I am doing bayesian inference in Pyro. I have defined the model and the guide functions inside a class.

consider the following:

class bayesian_inf(object):

… some lines of code
def model(self,images,labels):
… some lines of code

def guide(self,images,labels):
…some lines of code

def do_inference(self):
… some lines of code

svi=SVI(self.model,self.guide,optimizer,loss)

… some lines of code

elbo=svi.step(images,labels)

My doubt is that does the svi.step function provide images and labels(ex: for each mini-batch of examples) to the model and guide function automatically behind the scenes? or do I need to send every mini batch of data to do_inference function

svi calls model and guide with the args passed to it:

def model(data):
    ...

svi.step(data)  # data will be passed to the model above

if you want to do minibatching, you have to do it outside of svi:

def model(images, labels):
    ...

def guide(images, labels):
    ...

for i in range(epochs):
    minibatch_images = ...
    minibatch_labels = ...
    svi = SVI(model, guide, optim, loss)
    svi.step(minibatch_images, minibatch_labels)

Great. Thanks a lot

Can you clarify why svi = SVI(model, guide, optim, loss) is inside the for loop (initialized each epoch)? Thanks!

that’s a mistake. SVI should be initialized (once) outside the loop.

Okay phew thought I was missing something big-- thanks!