Exception: must run observer before calling calculate_qparams!

Running the tutorial at https://pytorch.org/tutorials/advanced/static_quantization_tutorial.html raises exception

/usr/local/lib/python3.6/dist-packages/torch/quantization/observer.py in calculate_qparams(self)
44 n_levels = 255.0
45 if self.max_val is None or self.min_val is None:
—> 46 raise Exception(‘must run observer before calling calculate_qparams!’)
47 max_val, min_val = self.max_val.item(), self.min_val.item()
48 if max_val == min_val:

Exception: must run observer before calling calculate_qparams!

Which version of PyTorch are you using? Seems there are some differences between the code you pasted and the master: https://github.com/pytorch/pytorch/blob/master/torch/quantization/observer.py