Use ModuleList for composite kernels to handle parameters correctly
@@ -4,6 +4,7 @@ from __future__ import print_function
from __future__ import unicode_literals
import torch
+from torch.nn import ModuleList
from ..module import Module
from ..lazy import LazyEvaluatedKernelVariable, ZeroLazyVariable
import gpytorch
@@ -68,7 +69,7 @@ class Kernel(Module):
class AdditiveKernel(Kernel):
def __init__(self, *kernels):
super(AdditiveKernel, self).__init__()
- self.kernels = kernels
+ self.kernels = ModuleList(kernels)
def forward(self, x1, x2):
res = ZeroLazyVariable()
@@ -81,7 +82,7 @@ class AdditiveKernel(Kernel):
class ProductKernel(Kernel):
def __init__(self, *kernels):
super(ProductKernel, self).__init__()
- self.kernels = kernels
+ self.kernels = ModuleList(kernels)
def forward(self, x1, x2):
return gpytorch.utils.prod([k(x1, x2).evaluate_kernel() for k in self.kernels])
