class GRU(nn.Module):
def __init__(self, input_size, hidden_size, output_size, num_layers):
super(GRU, self).__init__()
self.hidden_size = hidden_size
self.num_layers = num_layers
self.gru = nn.GRU(input_size, hidden_size, num_layers, batch_first=False)
self.softmax = nn.LogSoftmax(dim=2)
self.h2o = nn.Linear(hidden_size, output_size)
self.relu = nn.ReLU(inplace=True)
def forward(self, x, h):
out, h = self.gru(x, h)
out = self.h2o(out)
out = self.relu(out)
out = self.softmax(out)
return out, h
def init_hidden(self, batch_size, device):
weight = next(self.parameters()).data
hidden = weight.new(self.num_layers, batch_size, self.hidden_size).zero_().to(device)
return hidden
out, h = self.gru(x, h)
occurs this error :
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation
and i am dealing with this for straight 5 hours.
i can see no inplace operation in that code .