How can I know If a Variable is a cuda Varialbe?

print(encoder.cuda())

EncoderRNN (
  (embedding): Embedding(5955, 500)
  (gru): GRU(500, 500, num_layers=2, batch_first=True)
)

print(encoder)

EncoderRNN (
  (embedding): Embedding(5955, 500)
  (gru): GRU(500, 500, num_layers=2, batch_first=True)
)

The print result is same.How can I know If a Variable is a cuda Varialbe?

2 Likes

I think what you have is a neural network layer, which I believe is CPU/GPU agnostic.

The inputs/outputs are Variables, which can either be on the CPU or GPU. You can check that with the following:

inputs = Variable(torch.randn(2,2))
inputs.is_cuda  # will return false
inputs = Variable(torch.randn(2,2).cuda())
inputs.is_cuda # returns true
19 Likes