Skip to content

Instantly share code, notes, and snippets.

@Kaixhin
Last active October 20, 2017 20:19
Show Gist options
  • Save Kaixhin/8af7261dc790e8c899b4c2b2db97186e to your computer and use it in GitHub Desktop.
Save Kaixhin/8af7261dc790e8c899b4c2b2db97186e to your computer and use it in GitHub Desktop.
Device-agnostic PyTorch code
import torch
def cast(cuda):
if cuda:
return lambda x: x.cuda()
else:
return lambda x: x
torch.cast = cast(False)
a = torch.cast(torch.rand(3, 3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment