By device do you mean cuda and cpu ??
If yes,
You can use the following line to detect,
torch.cuda.is_available()

This returns a Boolean value depending upon wether or not cuda is available. So you can use if statements to look gor devices and this should make it work in both environments.
For ex,
cuda = torch.cuda.is_available()

tensor = some_values
if cuda:
    tensor.cuda()
input = Variable(tensor)
output = model(input)