-
Notifications
You must be signed in to change notification settings - Fork 559
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
[Feature Request] __rmatmul__
for LazyTensors
#1911
Comments
I think an implementation that basically does the above (although of course also transpose other) would be a perfectly reasonable first pass at this. The only thing to note is that lazy tensors that represent symmetric positive definite matrices (which is the dominant use case in gpytorch of course) don't even need to have That said, I just looked through all of the LTs again, and basically every one I see either implements gpytorch/gpytorch/lazy/toeplitz_lazy_tensor.py Lines 52 to 53 in 4df3048
so the quick implementation may be all we need here. |
Good catch regarding transposing def _test_rmatmul(self, lhs):
lazy_tensor = self.create_lazy_tensor().detach().requires_grad_(True)
lazy_tensor_copy = lazy_tensor.clone().detach().requires_grad_(True)
evaluated = self.evaluate_lazy_tensor(lazy_tensor_copy)
res = lhs @ lazy_tensor
actual = lhs @ evaluated
self.assertAllClose(res, actual)
grad = torch.randn_like(res)
res.backward(gradient=grad)
actual.backward(gradient=grad)
for arg, arg_copy in zip(lazy_tensor.representation(), lazy_tensor_copy.representation()):
if arg_copy.requires_grad and arg_copy.is_leaf and arg_copy.grad is not None:
self.assertAllClose(arg.grad, arg_copy.grad, **self.tolerances["matmul"]) |
@j-wilson Yeah, both the implementation and the basic test looks pretty good to me 👍 |
🚀 Feature Request
Implement
__rtmatmul__
for LazyTensors.Motivation
LazyTensors must be converted to vanilla Tensors when used by functions that perform matrix multiplies between Tensors (left) and LazyTensors (right). For example, if
A
is a lazy andK
is not then expressions such asA @ K @ A.T
will fail.Describe the solution you'd like
I do not know what challenges present themselves here. This may be as simple as adding something like
Are you willing to open a pull request?
Potentially, yes. It would be good to determine the scope of the PR first however.
The text was updated successfully, but these errors were encountered: