-
Notifications
You must be signed in to change notification settings - Fork 590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues with Cholesky decompositions on simple benchmark #61
Comments
same problem. got issues when using contextual HEBO |
To improve the stability you can add upper constraints on the kernel lengthscales and modify HEBO/hebo/models/gp/gp_utils.py replacing it with this version: # Copyright (C) 2020. Huawei Technologies Co., Ltd. All rights reserved.
# This program is free software; you can redistribute it and/or modify it under
# the terms of the MIT license.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the MIT License for more details.
import numpy as np
import torch
import torch.nn as nn
from torch import FloatTensor, LongTensor
from gpytorch.kernels import MaternKernel, ScaleKernel, ProductKernel
from gpytorch.priors import GammaPrior
from gpytorch.constraints.constraints import LessThan
from ..layers import EmbTransform
class DummyFeatureExtractor(nn.Module):
def __init__(self, num_cont, num_enum, num_uniqs = None, emb_sizes = None):
super().__init__()
self.num_cont = num_cont
self.num_enum = num_enum
self.total_dim = num_cont
if num_enum > 0:
assert num_uniqs is not None
self.emb_trans = EmbTransform(num_uniqs, emb_sizes = emb_sizes)
self.total_dim += self.emb_trans.num_out
def forward(self, x : FloatTensor, xe : LongTensor):
x_all = x
if self.num_enum > 0:
x_all = torch.cat([x, self.emb_trans(xe)], dim = 1)
return x_all
def default_kern(x, xe, y, total_dim = None, ard_kernel = True, fe = None, max_x = 1000):
if fe is None:
has_num = x is not None and x.shape[1] > 0
has_enum = xe is not None and xe.shape[1] > 0
kerns = []
if has_num:
ard_num_dims = x.shape[1] if ard_kernel else None
kernel = MaternKernel(nu = 1.5, ard_num_dims = ard_num_dims, active_dims = torch.arange(x.shape[1]),
lengthscale_constraint=LessThan(5))
if ard_kernel:
lscales = kernel.lengthscale.detach().clone().view(1, -1)
for i in range(x.shape[1]):
idx = np.random.choice(x.shape[0], min(x.shape[0], max_x), replace = False)
lscales[0, i] = torch.pdist(x[idx, i].view(-1, 1)).median().clamp(min = 0.02)
kernel.lengthscale = lscales
kerns.append(kernel)
if has_enum:
kernel = MaternKernel(nu = 1.5, active_dims = torch.arange(x.shape[1], total_dim),
lengthscale_constraint=LessThan(5))
kerns.append(kernel)
final_kern = ScaleKernel(ProductKernel(*kerns), outputscale_prior = GammaPrior(0.5, 0.5))
final_kern.outputscale = y[torch.isfinite(y)].var()
return final_kern
else:
if ard_kernel:
kernel = ScaleKernel(MaternKernel(nu = 1.5, ard_num_dims = total_dim,
lengthscale_constraint=LessThan(5)))
else:
kernel = ScaleKernel(MaternKernel(nu = 1.5))
kernel.outputscale = y[torch.isfinite(y)].var()
return kernel I've tested it on the example provided in the original issue comment and it runs without errors. After further investigation we'll include this to the repo directly. |
…the function `default_kern_rd` in the file as well.
The change from huawei-noah/HEBO#61 (comment) is integrated here.
The change from huawei-noah/HEBO#61 (comment) is integrated here.
The change from huawei-noah/HEBO#61 (comment) is integrated here. With a configuration file whose access mode is changed.
@dimitri-rusin # Copyright (C) 2020. Huawei Technologies Co., Ltd. All rights reserved.
# This program is free software; you can redistribute it and/or modify it under
# the terms of the MIT license.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the MIT License for more details.
import numpy as np
import torch
import torch.nn as nn
from torch import FloatTensor, LongTensor
from gpytorch.kernels import MaternKernel, ScaleKernel, ProductKernel
from gpytorch.priors import GammaPrior
from gpytorch.constraints.constraints import Interval
from ..layers import EmbTransform
class DummyFeatureExtractor(nn.Module):
def __init__(self, num_cont, num_enum, num_uniqs = None, emb_sizes = None):
super().__init__()
self.num_cont = num_cont
self.num_enum = num_enum
self.total_dim = num_cont
if num_enum > 0:
assert num_uniqs is not None
self.emb_trans = EmbTransform(num_uniqs, emb_sizes = emb_sizes)
self.total_dim += self.emb_trans.num_out
def forward(self, x : FloatTensor, xe : LongTensor):
x_all = x
if self.num_enum > 0:
x_all = torch.cat([x, self.emb_trans(xe)], dim = 1)
return x_all
def default_kern(x, xe, y, total_dim = None, ard_kernel = True, fe = None, max_x = 1000):
if fe is None:
has_num = x is not None and x.shape[1] > 0
has_enum = xe is not None and xe.shape[1] > 0
kerns = []
if has_num:
ard_num_dims = x.shape[1] if ard_kernel else None
kernel = MaternKernel(nu = 1.5, ard_num_dims = ard_num_dims, active_dims = torch.arange(x.shape[1]),
lengthscale_constraint=Interval(1e-5, 5))
if ard_kernel:
lscales = kernel.lengthscale.detach().clone().view(1, -1)
for i in range(x.shape[1]):
idx = np.random.choice(x.shape[0], min(x.shape[0], max_x), replace = False)
lscales[0, i] = torch.pdist(x[idx, i].view(-1, 1)).median().clamp(min = 0.02)
kernel.lengthscale = lscales
kerns.append(kernel)
if has_enum:
kernel = MaternKernel(nu = 1.5, active_dims = torch.arange(x.shape[1], total_dim),
lengthscale_constraint=Interval(1e-5, 5))
kerns.append(kernel)
final_kern = ScaleKernel(ProductKernel(*kerns), outputscale_prior = GammaPrior(0.5, 0.5))
final_kern.outputscale = y[torch.isfinite(y)].var()
return final_kern
else:
if ard_kernel:
kernel = ScaleKernel(MaternKernel(nu = 1.5, ard_num_dims = total_dim,
lengthscale_constraint=Interval(1e-5, 5)))
else:
kernel = ScaleKernel(MaternKernel(nu = 1.5))
kernel.outputscale = y[torch.isfinite(y)].var()
return kernel |
Actually it's this, right? default_kern_rd is also needed.
|
I tried this and it was not enough. What worked was catching the jitter fail and increasing jitter till it works.
|
Are there any updates and fixes? NanError: cholesky_cpu: 225 of 225 elements of the torch.Size([15, 15]) tensor are NaN. |
I get some issues with the Cholesky Decompositions. Here's how to reproduce it:
or
What matrix is being decomposed here? Can I influence or change this matrix using some hyperparameters? What can I do?
Thank you!
The text was updated successfully, but these errors were encountered: