我正在尝试训练多任务gpytorch模型,但模型火车出现错误 例子在这里- https://github.com/cornellius-gp/gpytorch/blob/master/examples/03_Multitask_GP_Regression/Multitask_GP_Regression.ipynb
model.train()
likelihood.train()
Use the adam optimizer
optimizer = torch.optim.Adam([
{‘params’: model.parameters()}, # Includes GaussianLikelihood parameters
], lr=0.1)
“Loss” for GPs - the marginal log likelihood
mll = gpytorch.mlls.ExactMarginalLogLikelihood(likelihood, model)
n_iter = 50
for i in range(n_iter):
optimizer.zero_grad()
output = model(train_x)
loss = -mll(output, train_y)
loss.backward()
print(‘Iter %d/%d - Loss: %.3f’ % (i + 1, n_iter, loss.item()))
optimizer.step()
RuntimeError Traceback (most recent call last)
in ()
16 optimizer.zero_grad()
17 output = model(train_x)
—> 18 loss = -mll(output, train_y)
19 loss.backward()
20 print(‘Iter %d/%d - Loss: %.3f’ % (i + 1, n_iter, loss.item()))
3 frames
/usr/local/lib/python3.6/dist-packages/gpytorch/distributions/multivariate_normal.py in log_prob(self, value)
112
113 mean, covar = self.loc, self.lazy_covariance_matrix
–> 114 diff = value - mean
115
116 # Repeat the covar to match the batch shape of diff
RuntimeError: expected backend CPU and dtype Double but got backend CPU and dtype Float
我遇到一个运行时错误,我有两个张量,一个x和两个y值,我正在尝试多任务示例。