Skip to content

Separate covariance computations for customizable posterior inference#2715

Merged
kayween merged 1 commit into
cornellius-gp:mainfrom
SebastianAment:separating-covariance-computations
Feb 20, 2026
Merged

Separate covariance computations for customizable posterior inference#2715
kayween merged 1 commit into
cornellius-gp:mainfrom
SebastianAment:separating-covariance-computations

Conversation

@SebastianAment
Copy link
Copy Markdown
Contributor

@SebastianAment SebastianAment commented Feb 13, 2026

This commit separates out the computation of the test-set mean and covariances
into _get_test_prior_mean_and_covariances and rewrites exact_prediction to
accept test_mean, test_test_covar, test_train_covar already separated.

This enables:

  1. Latent Kronecker Gaussian Processes with partial observations
  2. Posterior inference of individual components of additive models (BoTorch PR)
  3. Any application where predicted quantities differ from observed quantities, e.g. component-wise prediction of partial derivatives of kernel from observation of the function values.

@SebastianAment SebastianAment force-pushed the separating-covariance-computations branch 3 times, most recently from 8723467 to 3ce2bdf Compare February 13, 2026 21:09
Copy link
Copy Markdown
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.

Thanks, this looks great to me at a high level. cc @kayween, @gpleiss, @jacobrgardner in case they have any comments since this is a pretty deep change

The docs build failure should be resolved once rebased on #2716

Comment thread gpytorch/models/exact_gp.py Outdated
# Concatenate the input to the training input
full_inputs = []
batch_shape = train_inputs[0].shape[:-2]
for train_input, input in length_safe_zip(train_inputs, test_inputs):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Seems like we can replace length_safe_zip with zip(*, strict=True)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

zip(..., strict=True) was added in Python 3.10 (PEP 618), which seems to be GPyTorch's Python version floor, so we can make this change. Since length_safe_zip is used throughout the code base, I'll put up a separate commit for this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Balandat Added this in #2718.

Comment thread gpytorch/models/exact_gp.py Outdated
Comment thread gpytorch/models/exact_gp.py Outdated
if sum(test_train_covar.shape[-2:]) <= settings.max_eager_kernel_size.value():
# If we are calling it here, it requires two calls to "to_dense", but if we
# called it in the test covariance getter, then it would break the other
# prediction strategies (actually it already, does because we are not
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# prediction strategies (actually it already, does because we are not
# prediction strategies (actually it already does because we are not

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should we be overwriting them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think a better design for the prediction strategies is based on multiple-dispatch on the types of the covariance matrices. That way there wouldn't need to be a fall back if the types don't match, it would just call the correct implementation to begin with. With this in mind, I'd prefer to defer further changes to a future commit.

Comment thread gpytorch/models/exact_prediction_strategies.py Outdated
Comment thread gpytorch/models/exact_prediction_strategies.py Outdated
Comment thread gpytorch/models/exact_prediction_strategies.py Outdated
@SebastianAment SebastianAment force-pushed the separating-covariance-computations branch 5 times, most recently from 5ece9e9 to c4ee5f5 Compare February 17, 2026 20:40
@SebastianAment
Copy link
Copy Markdown
Contributor Author

@Balandat Thanks for the review, incorporated your suggestions.

Comment thread gpytorch/models/exact_prediction_strategies.py Outdated
Comment thread gpytorch/models/exact_prediction_strategies.py Outdated
Comment thread gpytorch/models/exact_prediction_strategies.py Outdated
Comment thread gpytorch/models/exact_prediction_strategies.py Outdated
Comment thread gpytorch/models/exact_prediction_strategies.py Outdated
Comment thread gpytorch/models/exact_gp.py Outdated
@kayween
Copy link
Copy Markdown
Collaborator

kayween commented Feb 18, 2026

This refactor looks good to me. Besides unblocking what's in the PR description, this PR also does quite a bit of cleanup, which is great. cc @jacobrgardner @gpleiss in case they want to weigh in here.

@SebastianAment SebastianAment force-pushed the separating-covariance-computations branch 3 times, most recently from 7b18a28 to 4de99c9 Compare February 18, 2026 16:47
Copy link
Copy Markdown
Member

@gpleiss gpleiss left a comment

Choose a reason for hiding this comment

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

LGTM once the comments are addressed!

Comment thread gpytorch/models/exact_gp.py
@SebastianAment SebastianAment force-pushed the separating-covariance-computations branch from 4de99c9 to 502156b Compare February 20, 2026 19:23
@SebastianAment SebastianAment force-pushed the separating-covariance-computations branch from 502156b to c1c1a7b Compare February 20, 2026 19:29
@SebastianAment
Copy link
Copy Markdown
Contributor Author

Thanks for the review @Balandat, @kayween, @gpleiss! This is ready to be merged.

@kayween kayween merged commit 3b9e89e into cornellius-gp:main Feb 20, 2026
7 checks passed
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.

4 participants