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):
super().init()
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))
net.to(torch.device(‘cuda:0’))
#Throws the following error:
return self._apply(lambda t: t.cuda(device))
#RuntimeError: CUDA error: device-side assert triggered