Open stevenstetzler opened 5 years ago
The fix you have seems sensible enough, but do we think it's a good idea to allow for ExactMarginalLogLikelihood
being called with the model in eval
mode at all? This has in the past led to people accidentally "training" their models in eval mode, and getting the test log likelihood can be better accomplished without normalization e.g. with:
log_lik = likelihood(model(train_x[:3]), noise=train_y_err[:3]).log_prob(train_y[:3])
normalized_log_lik = log_lik/3 # Keep in mind ExactMarginalLogLikelihood normalizes itself by n...
print(normalized_log_lik)
# Out: tensor(-1.3459, grad_fn=<DivBackward0>)
What do you think? Also @Balandat @gpleiss
I think it makes sense that ExactMarginalLogLikelihood only should work in training mode. You could always compute the log likelihood of test data using likelihood(model(test_x)).log_prob(test_y)
I think it makes sense that ExactMarginalLogLikelihood only should work in training mode
agreed
Right, I saw that I could compute the log likelihood with log_prob
on my targets, but I noticed in the ExactMarginalLogLikelihood
class that additional likelihood terms, specifically those from priors, are included in the computation of the likelihood after calls to log_prob
:
class ExactMarginalLogLikelihood(MarginalLogLikelihood):
...
def forward(self, output, target, *params):
...
res = output.log_prob(target)
# Add terms for SGPR / when inducing points are learned
added_loss = torch.zeros_like(res)
for added_loss_term in self.model.added_loss_terms():
added_loss.add(added_loss_term.loss())
res = res.add(0.5, added_loss)
# Add log probs of priors on the (functions of) parameters
for _, prior, closure, _ in self.named_priors():
res.add_(prior.log_prob(closure()).sum())
My concern was that if I added priors on my kernel parameters in my model, calls to log_prob
wouldn't account for them and I would have to write a layer of code to attach on the priors. Am I thinking about / using the log probability from the likelihood in the wrong way? What I am imagining in application in the end is using an MCMC to marginalize over kernel parameters, where gradients don't matter as much as just evaluating the log likelihood with priors included.
🐛 Bug
Currently the log likelihood computed through the use of
gpytorch.mlls.ExactMarginalLogLikelihood
can't be computed correctly with fixed Gaussian noise.To reproduce
Code snippet to reproduce
I changed
gpytorch/mlls/exact_marginal_log_likelihood.py
to modify theforward
method to acceptkwargs
and pass them to thelikelihood
call, as is currently done with*params
:was changed to:
This results in a different log likelihood calculation (a presumably correct one) with no warning:
Stack trace/error message
Expected Behavior
I expect that calls to ExactMarginalLogLikelihood should be able to accommodate fixed noise models. I believe the above changes fix that.