Exception has occurred: RuntimeError One of the differentiated Tensors appears to not have been used in the graph. Set allow_unused=True if this is the desired behavior

Is there a way to debug this? To find out which tensor it’s refering to?

It’s hard to say without more details (ideally a runnable code snippet that reproduces the error), but presumably this error message is referring to some neural net parameter in your model that isn’t being used in the forward pass or is being canceled in some higher-order derivative computation.

If that’s intended behavior, one workaround is to fork the code for the inference algorithm you’re using and set allow_unused=True in the appropriate place(s). If not, one tedious but effective debugging strategy would be to compute and differentiate the loss directly (perhaps via the ELBO.differentiable_loss method in the case of VI) with respect to one single parameter at a time until you identify the source of the error.