Skip to content

[Bug] Default noise constraint may be incompatible with some priors #2646

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

Open
gpleiss opened this issue Mar 15, 2025 · 0 comments
Open

[Bug] Default noise constraint may be incompatible with some priors #2646

gpleiss opened this issue Mar 15, 2025 · 0 comments
Labels

Comments

@gpleiss
Copy link
Member

gpleiss commented Mar 15, 2025

🐛 Bug

Using a GammaPrior in conjunction with the GaussianLikelihood can lead to sampling errors with Pyro. This is because the default GaussianLikelihood noise_constraint is [1e-4, \infty), while the GammaLikelihood has support over (0, \infty). When the GammaLikelihood samples a < 1e-4 value, the resulting noise parameter is NaN.

In general, we should set the default noise constraint to match the support of the prior, or we should remove the default noise constraint when using a prior.

@Balandat what would be the least breaking approach with BoTorch?

(See #2643)

To reproduce

** Code snippet to reproduce **

# need pyro installed
import gpytorch
import torch

noise_prior = gpytorch.priors.GammaPrior(1.0, 0.5)
likelihood = gpytorch.likelihoods.GaussianLikelihood(
    noise_prior=noise_prior,
    # noise_constraint=gpytorch.constraints.Positive(),  # <- error goes away if we uncomment this line
    batch_shape=torch.Size([100,])
)
for i in range(1000):
    sampled_likelihood = likelihood.pyro_sample_from_prior()
    noise = sampled_likelihood.noise
    if not torch.equal(noise, noise):
        raise RuntimeError("Sampled noise has NaNs")

** Stack trace/error message **

RuntimeError: Sampled noise has NaNs

System information

  • GPyTorch Version 1.4
  • PyTorch Version 2
  • MacOS X
@gpleiss gpleiss added the bug label Mar 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant