cornellius-gp / gpytorch

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

root_decomposition: Auto-switch to cholesky for small matrices #422

Open Balandat opened 5 years ago

Balandat commented 5 years ago

Currently, root_decomposition fails for LazyTensors with a single element with an obscure index error (except for DiagLazyTensor, where it is special-cased). More generally, the iterative low-rank approximation algorithm is quite wasteful to use for small matrix sizes - performing a Cholesky decomposition on the evaluated LazyTensor can be much faster (see this nb: root_decomposition_perf.ipynb.txt)

We should dig some more into this and do a more thorough analysis. I suggest once we have done this we can just choose whether to perform a cholesky decomposition or instead use the iterative algorithm depending on the size of the tensor.

In fact, for now I will push a small fix that does this for all cases with n * n < 250 or so.

cc @bkarrer

gpleiss commented 5 years ago

@Balandat this seems very reasonable. Rather than numel, I would do self.matrix_shape.numel() as the check, which would then use Cholesky on large batches of small matrices.

jacobrgardner commented 5 years ago

Closed by #423

Balandat commented 5 years ago

Reopening this so we can dig deeper and determine a better default schedule for selecting between the two mechanisms.