Issue with predict() in Implementing a custom kernel in GPyTorch
See original GitHub issueSeems like predict() function in Implementing a custom kernel in GPyTorch should operate in eval mode. Otherwise, using predict() on on an untrained model (e.g. after torch.load() is used to load saved parameters) will give an error
should this:
def predict(model, likelihood, test_x=torch.linspace(0, 1, 51)):
# Make predictions by feeding model through likelihood
with torch.no_grad(), gpytorch.settings.fast_pred_var():
# Test points are regularly spaced along [0,1]
return likelihood(model(test_x))
be this (or better yet save the current eval state and return to model to the previous state
def predict(model, likelihood, test_x=torch.linspace(0, 1, 51)):
#set to eval mode
model.eval()
# Make predictions by feeding model through likelihood
with torch.no_grad(), gpytorch.settings.fast_pred_var():
# Test points are regularly spaced along [0,1]
return likelihood(model(test_x))
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Implementing a custom kernel in GPyTorch
In this notebook we are looking at how to implement a custom kernel in GPyTorch. ... predictions by feeding model through likelihood with...
Read more >gpytorch/Implementing_a_custom_Kernel.ipynb at master - GitHub
In this notebook we are looking at how to implement a custom kernel in GPyTorch. ... predictions by feeding model through likelihood with...
Read more >Problem reproducing the predicted covariance of a gaussian ...
The idea is to train a GP using GPytorch, then take the learned hyperparameters, ... ConstantMean() self.covar_module = gpytorch.kernels.
Read more >Gaussian Process Regression using GPyTorch
We'll use the Spectral Mixture (SM) kernel ( gpytorch.kernels.SpectralMixtureKernels() ) for this tutorial. A multivariate normal distribution: ...
Read more >Gaussian Process Regression using GPyTorch
Building a scalable and flexible GP model using GPyTorch ... be applied to supervised learning problems like regression and classification.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@arthus701 yeah - it doesn’t hurt to have the
model.eval()
statement in thepredict
function. I’m making a few improvements to the docs today, so I can implement this change.What do you think @gpleiss? It wouldn’t be much work and I could certainly open a PR that implements the
predict
function the proposed way (i.e. with setting the model intoeval
mode inside of the function), but I do not want to carry the PRs for this example to excess.