Skip to content
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

Make it possible to pickle simple kernels and likelihoods #1876

Merged
merged 4 commits into from
Jan 5, 2022

Conversation

dme65
Copy link
Collaborator

@dme65 dme65 commented Jan 5, 2022

We sometimes need to pickle (simple) GPyTorch models, but this doesn't work when using priors since register_prior creates local lambdas. This PR makes it possible to pickle simple kernels such as Matern, RBF, Scale as well as the Gaussian likelihood.

@dme65 dme65 requested a review from Balandat January 5, 2022 01:05
Copy link
Collaborator

@Balandat Balandat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks! Very useful.

@@ -172,7 +172,7 @@ def __init__(
if not isinstance(lengthscale_prior, Prior):
raise TypeError("Expected gpytorch.priors.Prior but got " + type(lengthscale_prior).__name__)
self.register_prior(
"lengthscale_prior", lengthscale_prior, lambda m: m.lengthscale, lambda m, v: m._set_lengthscale(v)
"lengthscale_prior", lengthscale_prior, self._lengthscale_param, self._lengthscale_closure
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should also work here?

Suggested change
"lengthscale_prior", lengthscale_prior, self._lengthscale_param, self._lengthscale_closure
"lengthscale_prior", lengthscale_prior, "lengthscale", self._lengthscale_closure

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works (making this change causes 31 tests to fail). Note that _lengthscale_param returns m.lengthscale and not self.lengthscale.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm not sure I understand why it doesn’t, seems like the closure definition here should do the same?

def closure(module):

Either way, we can figure that out later (or I’m missing sth obvious). Accepting this as is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! Looks like merging is blocked though until the docs can be built successfully. Looking at https://readthedocs.org/projects/gpytorch/builds/15684237/ it looks like the issue is a warning that is unrelated to this PR.

@dme65 dme65 enabled auto-merge (squash) January 5, 2022 16:12
@dme65
Copy link
Collaborator Author

dme65 commented Jan 5, 2022

Ok, fixed the doc building issue by pinning nbsphinx==0.8.7. Looks like they released 0.8.8 on Dec 31, 2021.

@dme65 dme65 merged commit 61f643e into cornellius-gp:master Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants