Imported from https://github.com/rosinality/igebm-pytorch