Skip to content

Instantly share code, notes, and snippets.

@jojonki
Created November 30, 2017 16:16
Show Gist options
  • Select an option

  • Save jojonki/f30527587712662aeda1c11f06880748 to your computer and use it in GitHub Desktop.

Select an option

Save jojonki/f30527587712662aeda1c11f06880748 to your computer and use it in GitHub Desktop.
Convert to Variable in PyTorch
from torch.autograd import Variable
def to_var(x):
if torch.cuda.is_available():
x = x.cuda()
return Variable(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment