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

Fix bug in preconditioned KISS-GP / Hadamard Multitask GPs #2090

Merged
merged 2 commits into from
Aug 7, 2022

Conversation

gpleiss
Copy link
Member

@gpleiss gpleiss commented Aug 7, 2022

Previously in PyTorch, calling on a int/long matrix was a no-op.
At some point in the PyTorch releases, this line started throwing an error (since only
floating point operations can have gradients).

Our implementation of pivoted cholesky previously called
matrix_arg.requires_grad_(True) on all LazyTensor/LinearOperator
arguments, without first checking whether matrix_arg was a floating
point dtype.

KISS-GP makes use of InterpolatedLazyTensor (to become InterpolatedLinearOperator), which
has integer matrices (the index matrices for interpolation). This
therefore produced an error message when it was used in conjunction with
the pivoted cholesky preconditioner. A similar bug exists for
preconditioned Hadamard Multitask GPs.

(The reason this bug went undetected is because our tests for KISS-GP
models and multitask models all use small datasets (N < 100).
Preconditioners are not used until N > 2000 or so.)

[Fixes #2056]

Previously in PyTorch, calling  on a int/long matrix was a no-op.
At some point in the PyTorch releases, this line started throwing an error (since only
floating point operations can have gradients).

Our implementation of pivoted cholesky previously called
`matrix_arg.requires_grad_(True)` on all LazyTensor/LinearOperator
arguments, without first checking whether `matrix_arg` was a floating
point dtype.

KISS-GP makes use of InterpolatedLazyTensor (to become InterpolatedLinearOperator), which
has integer matrices (the index matrices for interpolation). This
therefore produced an error message when it was used in conjunction with
the pivoted cholesky preconditioner. A similar bug exists for
preconditioned Hadamard Multitask GPs.

(The reason this bug went undetected is because our tests for KISS-GP
models and multitask models all use small datasets (N < 100).
Preconditioners are not used until N > 2000 or so.)

[Fixes #2056]
@gpleiss gpleiss added bug high priority multitask For questions about multitask models labels Aug 7, 2022
@@ -58,8 +58,8 @@
"metadata": {},
"outputs": [],
"source": [
"train_x1 = torch.rand(50)\n",
"train_x2 = torch.rand(50)\n",
"train_x1 = torch.rand(2000)\n",
Copy link
Collaborator

Choose a reason for hiding this comment

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

By how much does this increase runtime? Should we be concerned here if this is run as part of the unit tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

This change (plus the ones in the other two examples) add at most one second to the test suite - I just checked.

@@ -98,7 +98,11 @@ def backward(ctx, grad_output, _):

with torch.enable_grad():
# Create a new set of matrix args that we can backpropagate through
matrix_args = [matrix_arg.detach().requires_grad_(True) for matrix_arg in _matrix_args]
matrix_args = []
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would say we could also catch the error so that if there are any future changes we don't have to adjust the code here. But then raising errors is unfortunately quite slow in ptorch...

@gpleiss gpleiss merged commit 433b7ee into master Aug 7, 2022
@gpleiss gpleiss deleted the fix_preconditioned_kissgp branch August 7, 2022 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug high priority multitask For questions about multitask models
Projects
None yet
2 participants