Fix bug in setting training data for ExactGP.
Move the check about whether strict mode is enabled up so that if strict is False, set_train_data won't fail even if the current training data is None.
@@ -50,14 +50,16 @@ class ExactGP(GP):
if torch.is_tensor(inputs):
inputs = (inputs,)
inputs = tuple(input_.unsqueeze(-1) if input_.ndimension() == 1 else input_ for input_ in inputs)
+ if strict:
for input, t_input in zip(inputs, self.train_inputs):
for attr in {"shape", "dtype", "device"}:
- if strict and getattr(input, attr) != getattr(t_input, attr):
+ if getattr(input, attr) != getattr(t_input, attr):
raise RuntimeError("Cannot modify {attr} of inputs".format(attr=attr))
self.train_inputs = inputs
if targets is not None:
+ if strict:
for attr in {"shape", "dtype", "device"}:
- if strict and getattr(targets, attr) != getattr(self.train_targets, attr):
+ if getattr(targets, attr) != getattr(self.train_targets, attr):
raise RuntimeError("Cannot modify {attr} of targets".format(attr=attr))
self.train_targets = targets
self.prediction_strategy = None
