RNN working on CPU, shows loss but cannot send to GPU

I’m new to NLP. I’m trying to use the Torch’s nn.Embeddings and nn.RNN().
I noticed a strange thing while doing this. For some reason, my model trains on CPU. But I cannot send it to GPU for training.
Here is the Model architecture:

#single layer RNN.
import torch.nn as nn
import torch

class RNN(nn.Module):
def init(self, ip_dim, emb_dim, hidden_dim, op_dim):
self.embedding = nn.Embedding(ip_dim, emb_dim, padding_idx=0)
self.rnn = nn.RNN(emb_dim, hidden_dim)
self.fc = nn.Linear(hidden_dim, op_dim)
def forward(self, text):
text = torch.transpose(text, 0,1)
emb = self.embedding(text)
op, hidden = self.rnn(emb)
out = self.fc(hidden)
return out

Here is me instantiating the model:

emb_dim_len = 100
hdim = 256
net = RNN(ip_dim = len(v2i), # v2i = vocab to index. dictionary with elements like: {“ice” : 1}
emb_dim = emb_dim_len, hidden_dim = hdim,
op_dim = len(Classes))

#Throws the following error:
return self._apply(lambda t: t.cuda(device))

#RuntimeError: CUDA error: device-side assert triggered

Please use ‘preformatted text Ctrl-Shift-C’ for posting codes.

Also, seems like def init might be first issue to resolve, make it dunder.

1 Like

Were you able to use the GPU in the past?
If so, are you able to create a simple tensor on the device via: torch.randn(10, device='cuda')?

1 Like