cornellius-gp / gpytorch

A highly efficient implementation of Gaussian Processes in PyTorch
MIT License
3.46k stars 546 forks source link

Stop rbf_kernel_grad and rbf_kernel_gradgrad creating the full covariance matrix unnecessarily #2388

Closed douglas-boubert closed 11 months ago

douglas-boubert commented 11 months ago

The master implementation creates a PyTorch tensor of zeros to store the full covariance matrix, even if only the diagonal elements are needed.

If diag=True then the (potentially very large) tensor K is created but never used. This can result in a GPU running out of memory in an avoidable situation.

I have moved the creation of the tensor to store the full covariance matrix into the if diag=False branch of the code.