# Buggy code
def _shaped_noise_covar(self, base_shape: torch.Size, *params: Any, **kwargs: Any):
    if len(params) > 0:
        # we can infer the shape from the params
        shape = None
    else:
        # here shape[:-1] is the batch shape requested, and shape[-1] is `n`, the number of points
        shape = base_shape
    return self.noise_covar(*params, shape=shape, **kwargs)


# Traceback (RuntimeError)
Traceback (most recent call last):

File "<ipython-input-1-88b9df752e72>", line 1, in <module>
runfile('/home/user/Desktop/dl-dev python/gp_examples/test.py', wdir='/home/user/Desktop/dl-dev python/gp_examples')

File "/home/user/anaconda3/envs/dkl/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 827, in runfile
execfile(filename, namespace)

File "/home/user/anaconda3/envs/dkl/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "/home/user/Desktop/dl-dev python/gp_examples/test.py", line 136, in <module>
preds = model(test_x)

File "/home/user/anaconda3/envs/dkl/lib/python3.6/site-packages/gpytorch/models/exact_gp.py", line 294, in __call__
likelihood=self.likelihood,

File "/home/user/anaconda3/envs/dkl/lib/python3.6/site-packages/gpytorch/models/exact_prediction_strategies.py", line 36, in prediction_strategy
return cls(train_inputs, train_prior_dist, train_labels, likelihood)

File "/home/user/anaconda3/envs/dkl/lib/python3.6/site-packages/gpytorch/kernels/grid_interpolation_kernel.py", line 205, in prediction_strategy
return InterpolatedPredictionStrategy(train_inputs, train_prior_dist, train_labels, likelihood)

File "/home/user/anaconda3/envs/dkl/lib/python3.6/site-packages/gpytorch/models/exact_prediction_strategies.py", line 380, in __init__
super().__init__(train_inputs, train_prior_dist, train_labels, likelihood)

File "/home/user/anaconda3/envs/dkl/lib/python3.6/site-packages/gpytorch/models/exact_prediction_strategies.py", line 50, in __init__
mvn = self.likelihood(train_prior_dist, train_inputs)

File "/home/user/anaconda3/envs/dkl/lib/python3.6/site-packages/gpytorch/likelihoods/likelihood.py", line 313, in __call__
return self.marginal(input, *args, **kwargs)

File "/home/user/anaconda3/envs/dkl/lib/python3.6/site-packages/gpytorch/likelihoods/gaussian_likelihood.py", line 76, in marginal
full_covar = covar + noise_covar

File "/home/user/anaconda3/envs/dkl/lib/python3.6/site-packages/gpytorch/lazy/lazy_tensor.py", line 1626, in __add__
return AddedDiagLazyTensor(self, other)

File "/home/user/anaconda3/envs/dkl/lib/python3.6/site-packages/gpytorch/lazy/added_diag_lazy_tensor.py", line 27, in __init__
broadcasting._mul_broadcast_shape(lazy_tensors[0].shape, lazy_tensors[1].shape)

File "/home/user/anaconda3/envs/dkl/lib/python3.6/site-packages/gpytorch/utils/broadcasting.py", line 20, in _mul_broadcast_shape
raise RuntimeError("Shapes are not broadcastable for mul operation")

RuntimeError: Shapes are not broadcastable for mul operatio

# Fixed code
def _shaped_noise_covar(self, base_shape: torch.Size, *params: Any, **kwargs: Any):
    return self.noise_covar(*params, shape=base_shape, **kwargs)