-
Notifications
You must be signed in to change notification settings - Fork 415
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
Fixed condition_on_observations in fully Bayesian models #2151
Conversation
@sdaulton has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Thanks for putting this up @hvarfner! |
Thanks for fixing this @hvarfner! These changes generally look good to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making these changes. I left some, mostly cosmetic, comments in line.
One thing I want to make sure is that the model batch shape remains compatible with the model itself. To this end, could you also update the batch_shape
property of SaasFullyBayesianSingleTaskGP
to reflect the correct shape before & after fantasizing?
botorch/models/fully_bayesian.py
Outdated
raise ValueError( | ||
"Conditioning in fully Bayesian models must contain a batch dimension." | ||
"Add a batch dimension (the leading dim) with length matching the " | ||
"number of hyperparameter sets to the conditioned data." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the number of hyper-parameter sets self.num_mcmc_samples
or self.batch_shape
(the two are the same, unless the model is already batched / fantasized)? If I were to attempt fantasizing from an already fantasized model, would this still hold? It'd be good to print out the expected shape as part of the error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a bit of an incorrect rushed comment before, which I deleted. =)
@@ -656,6 +666,77 @@ def test_custom_pyro_model(self): | |||
atol=5e-4, | |||
) | |||
|
|||
def test_condition_on_observation(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding these tests. For completeness, can you add a test that calls model.fantasize
and a test that evaluates some acquisition function (e.g., qLogEI) with the fantasized model? I just want to make sure everything works e2e including the sampler related code inside the acquisition functions.
01f9e5e
to
b4040b5
Compare
@saitcakmak thanks for the feedback! I didn't consider fantasizing before, so I had to rework a little bit to add it. Now, the batch shapes are inferred in condition_on_observations for the fantasizing case |
Thanks for making the changes. I had not realized that your original changes did not affect the model batch size (as in, the output shape and the shape of the lengthscales does not change in the conditioning tests). But fantasizing (which is the use case of conditioning I am most familiar with) does change the batch shape by adding a another dimension to it. So, if I tried to use the fantasized model with some acquisition functions, it will now error out because the
to the end of the fantasize test will raise One option here would be to update the definition of the
|
@saitcakmak Yeah, there seems to be some nuance to this that I failed to consider. I think there are two things that need to be ironed out if we want consistency (and retain only one batch of training data by default):
I am not quite sure how this can be solved in a consistent manner without reconsidering the FBGP altogether (i.e. making the model dim a leading dim), so I am for rolling back as of now! |
That sounds good to me. We can revisit it down the line if there's a need for |
c52c329
to
17fdee8
Compare
@saitcakmak done! I think the long-term fix (which I don't think would be too much work) would be to have |
@saitcakmak has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I haven't thought too deeply about this, but I think a proper way to support fantasize would start with adding support for batched inputs more generally (in init) and add the MCMC dimension as the outer-most dimension as you suggest. We could also store the train_inputs/targets as batched (along the MCMC) dimension to bring the model internals further in-line with other batched models (e.g., SingleTaskGP). That being said, this is a decent bit of work to make these changes (will also require updating other parts of the code base that have specialized logic for this model), so it might not be worth the effort unless there's a real motivator.
@saitcakmak merged this pull request in 0c37aac. |
Motivation
Conditioning on observations in fully bayesian models - enables fully Bayesian JES & KG(?).
Have you read the Contributing Guidelines on pull requests?
Yes.
Test Plan
Tests are written to ensure functionality for inferred and fixed noise. note that the
_aug_batch_shape
attribute assignment was removed incondition_on_observations
. InFullyBayesianGPs
, this argument could not be assigned (hence the removal). I could not find the use for this argument, and all tests passed when removing it.Other changes are commented throughout, and the changes were made so as to assure that FBGPs can have one set of training data throughout. Howver, conditioning on obervations adds a batch dim to the training data (which is necessary in GPyTorch here) to infer the correct batch dim.