Comments (4)
Actually - I ported your example to work on the alpha_release
branch:
import gpytorch
import torch
from gpytorch.kernels import RBFKernel, AdditiveGridInterpolationKernel
from gpytorch.likelihoods import GaussianLikelihood
from gpytorch.means import ConstantMean
from gpytorch.random_variables import GaussianRandomVariable
from torch import nn
from torch.autograd import Variable
class GP(gpytorch.models.ExactGP):
def __init__(self, train_x, train_y, likelihood):
super(GP, self).__init__(train_x, train_y, likelihood)
self.embedding = nn.Embedding(10, 2)
self.mean_module = ConstantMean(constant_bounds=[-1e-5, 1e-5])
self.base_covar_module = RBFKernel(log_lengthscale_bounds=(-5, 6))
self.covar_module = AdditiveGridInterpolationKernel(self.base_covar_module,
grid_size=100, grid_bounds=[(-10, 10)], n_components=2)
self.register_parameter('log_outputscale', nn.Parameter(torch.Tensor([0])), bounds=(-5, 6))
def forward(self, x):
embs = self.embedding(x)
mean_embs = self.mean_module(embs)
covar_embs = self.covar_module(embs)
covar_embs = covar_embs.mul(self.log_outputscale.exp())
latent_pred = GaussianRandomVariable(mean_embs, covar_embs)
return latent_pred
class GPRegressionModel(gpytorch.Module):
def __init__(self, train_x, train_y):
super(GPRegressionModel, self).__init__()
self.likelihood = GaussianLikelihood()
self.gp = GP(train_x, train_y, self.likelihood)
def forward(self, x):
return self.likelihood(self.gp(x))
if __name__ == '__main__':
n = 10
train_x = (torch.rand(n) * 10).type(torch.LongTensor)
train_x = Variable(train_x)
train_y = torch.randn(n)
train_y = Variable(train_y)
model = GPRegressionModel(train_x.data, train_y.data)
output = model(train_x)
loss = -model.gp.marginal_log_likelihood(model.likelihood, output, train_y)
loss.backward()
print('Embedding has gradients!', model.gp.embedding.weight.grad)
"""
Output:
('Embedding has gradients!', Variable containing:
0.0000 0.0000
0.0000 0.0000
0.0000 0.0000
0.0175 -0.0341
0.0000 0.0000
-0.0136 0.0151
-0.0094 0.0722
0.0290 -0.0124
0.0907 0.0171
-0.0657 -0.1519
[torch.FloatTensor of size 10x2]
)
"""
Note that the nn.Embeddings
layer has to live inside the GP
module.
from gpytorch.
Alright, I reproduced your issue, and I think I have pinpointed the problem. Some of our interpolation code is not computing gradients, which then prevents embeddings from getting gradients.
Hopefully we'll have a fix for this soon.
from gpytorch.
Hmmm you should be getting gradients! I'll look into this.
from gpytorch.
Okay - we have a fix for this on the alpha_release
branch.
The interface has changed slightly on this branch, so you'll probably have to update your model a bit.
Could you test out your model on the alpha_release
branch and see if it works?
from gpytorch.
Related Issues (20)
- [Bug] Problems in the normalization and standardization of data HOT 1
- [Bug] Standardization of the output and inverse transform of standard deviation HOT 3
- [Docs] `get_fantasy_model` - are posterior covariances computed from scratch or using efficient cache updates? HOT 1
- [Bug] Bug in GP Regression with KeOps Kernels HOT 1
- [Bug] Extreme oscillation in loss
- [Bug] Extreme loss oscillation during training
- [Docs] Missing docs for HammingIMQKernel
- [Feature Request] Generic typing for scale kernels
- [Docs] Making sense of batch processing and tasks
- [Feature Request] Is it possible to work with Changepoint kernels?
- Nesting GPs; using the sufficient statistics from one GP as sufficient stats in another GP - variance goes to zero
- Label flattening fails with custom mean function from another GP HOT 1
- [Docs] Unexpected behavior setting kernel priors HOT 1
- [Feature Request] Allow `kwargs` to be passed to `ExactMarginalLogLikelihood.forward()` HOT 1
- [Bug] CUDA out of memory, strange numbers HOT 1
- [Docs] qKnowledgeGradient cpu usage HOT 1
- [Bug] Erroneous detaching with (custom?) mean
- [Bug] Multitask-ExactGPs seem to not use mBCG algorithm as Singletask-ExactGPs do
- [Feature Request] Choose which dimentions to differenciate with respect to in derivative multitask GPs
- [Bug] Error in tutorials and derivative GPs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gpytorch.