Clarification reagrding svi.step


#1

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


#2

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)

#3

Great. Thanks a lot