cornellius-gp / gpytorch

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

Allow pickle of IndexKernels #2482

Open TobyBoyne opened 4 months ago

TobyBoyne commented 4 months ago

Currently, index kernels cannot be pickled. This PR moves an anonymous function to the module-level to allow pickling.

Current behaviour is that index kernels with a prior throw an error when pickling.

from gpytorch.kernels import IndexKernel
from gpytorch.priors import LKJPrior
import pickle

kernel = IndexKernel(2, prior=LKJPrior(2, 1))
pickle.dumps(kernel)

This throws > AttributeError: Can't pickle local object 'IndexKernel.__init__.<locals>.<lambda>'

There isn't an open issue for this in particular, but there is a request for pickle-able kernels. (#907, #2264)