# Buggy code
def __init__(self, a, b, sigma=0.01, validate_args=False, transform=None):
    TModule.__init__(self)
    _a = torch.tensor(float(a)) if isinstance(a, Number) else a
    _a = _a.view(-1) if _a.dim() < 1 else _a
    _a, _b, _sigma = broadcast_all(_a, b, sigma)
    if not torch.all(constraints.less_than(_b).check(_a)):
        raise ValueError("must have that a < b (element-wise)")
    # TODO: Proper argument validation including broadcasting
    batch_shape, event_shape = _a.shape[:-1], _a.shape[-1:]
    # need to assign values before registering as buffers to make argument validation work
    self.a, self.b, self.sigma = _a, _b, _sigma
    super(SmoothedBoxPrior, self).__init__(
        batch_shape, event_shape, validate_args=validate_args
    )
    # now need to delete to be able to register buffer
    del self.a, self.b, self.sigma
    self.register_buffer("a", _a)
    self.register_buffer("b", _b)
    self.register_buffer("sigma", _sigma)
    self.tails = NormalPrior(torch.zeros_like(_a), _sigma, validate_args=validate_args)
    self._transform = transform


# Traceback (RuntimeError)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-5-6b4b2e881beb> in <module>
2 import gpytorch
3 pr = gpytorch.priors.SmoothedBoxPrior(torch.zeros(2), torch.ones(2))
----> 4 pr.load_state_dict(pr.state_dict())

<...PATH..>/torch/nn/modules/module.py in load_state_dict(self, state_dict, strict)
877         if len(error_msgs) > 0:
878             raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
--> 879                                self.__class__.__name__, "\n\t".join(error_msgs)))
880         return _IncompatibleKeys(missing_keys, unexpected_keys)
881

RuntimeError: Error(s) in loading state_dict for SmoothedBoxPrior:
While copying the parameter named "sigma", whose dimensions in the model are torch.Size([2]) and whose dimensions in the checkpoint are torch.Size([2]), an exception occured : ('unsupported operation: more than one element of the written-to tensor refers to a single memory location. Please clone() the tensor before performing the operation.',).

# Fixed code
def __init__(self, a, b, sigma=0.01, validate_args=False, transform=None):
    TModule.__init__(self)
    _a = torch.tensor(float(a)) if isinstance(a, Number) else a
    _a = _a.view(-1) if _a.dim() < 1 else _a
    _a, _b, _sigma = broadcast_all(_a, b, sigma)
    if not torch.all(constraints.less_than(_b).check(_a)):
        raise ValueError("must have that a < b (element-wise)")
    # TODO: Proper argument validation including broadcasting
    batch_shape, event_shape = _a.shape[:-1], _a.shape[-1:]
    # need to assign values before registering as buffers to make argument validation work
    self.a, self.b, self.sigma = _a, _b, _sigma
    super(SmoothedBoxPrior, self).__init__(
        batch_shape, event_shape, validate_args=validate_args
    )
    # now need to delete to be able to register buffer
    del self.a, self.b, self.sigma
    self.register_buffer("a", _a)
    self.register_buffer("b", _b)
    self.register_buffer("sigma", _sigma.clone())
    self.tails = NormalPrior(torch.zeros_like(_a), _sigma, validate_args=validate_args)
    self._transform = transform