If you are using DataParallel or DistributedDataParallel, remove the cuda() call in self.latest_input.
These wrappers will push the model replica to the corresponding device for you, while you are explicitly creating this tensor on cuda:0, which could yield the device mismatch error.
PS: Variables are deprecated since PyTorch 0.4 so you can use tensors directly in newer versions.