Can't send pytorch tensor to cuda
I create a torch tensor and I want it to go to GPU but it doesn't. This is so broken. What's wrong?
def test_model_works_on_gpu():
    with torch.cuda.device(0) as cuda:
        some_random_d_model = 2 ** 9
        five_sentences_of_twenty_words = torch.from_numpy(np.random.random((5, 20, T * d))).float()
        five_sentences_of_twenty_words_mask = torch.from_numpy(np.ones((5, 1, 20))).float()
        pytorch_model = make_sentence_model(d_model=some_random_d_model, T_sgnn=T, d_sgnn=d)

        five_sentences_of_twenty_words.to(cuda)
        five_sentences_of_twenty_words_mask.to(cuda)
        print(type(five_sentences_of_twenty_words), type(five_sentences_of_twenty_words_mask))
        print(five_sentences_of_twenty_words.is_cuda, five_sentences_of_twenty_words_mask.is_cuda)
        pytorch_model.to(cuda)
        output_before_match = pytorch_model(five_sentences_of_twenty_words, five_sentences_of_twenty_words_mask)

        assert output_before_match.shape == (5, some_random_d_model)
        print(type(output_before_match))
        print(output_before_match.is_cuda, output_before_match.get_device())

tests/test_model.py:58: RuntimeError

&lt;class 'torch.Tensor'&gt; &lt;class 'torch.Tensor'&gt;
False False
&lt;class 'torch.Tensor'&gt;

&gt;       print(output_before_match.is_cuda, output_before_match.get_device())
E       RuntimeError: get_device is not implemented for tensors with CPU backend

Also:
&gt;&gt;&gt; torch.cuda.is_available()
True
&gt;&gt;&gt; torch.cuda.device_count()
2

And:
pip freeze | grep -i torch
torch==1.0.0
torchvision==0.2.1


Your issue is the following lines:
five_sentences_of_twenty_words.to(cuda)
five_sentences_of_twenty_words_mask.to(cuda)

.to(device) only operates in place when applied to a model.
When applied to a tensor, it must be assigned:
five_sentences_of_twenty_words = five_sentences_of_twenty_words.to(cuda)
five_sentences_of_twenty_words_mask = five_sentences_of_twenty_words_mask.to(cuda)

