You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
Hello, I am making a gated recurrent unit from scratch and I am having trouble getting the autograd package to calculate the gradients correctly.
Here is the error I am getting: MXNetError: Check failed: !AGInfo: :IsNone(*i): Cannot differentiate node because it is not in a computational graph. You need to set is_recording to true or use autograd.record() to save computational graphs for backward. If you want to differentiate the same graph twice, you need to pass retain_graph=True to backward.
Have one of yall had this issue before? How can I go about fixing it?
Attached below is the code I am using to compute the gradients. All the weights and biases have had .attach_grad() called on them when I initialized them.
def ComputeGradient(self, X):
with autograd.record():
y = self.forward(X)
y.backward()
def forward(self, X):
HiddenStateVector = pickle.load(open(self.HiddenStateVectorPath, 'rb'))
# Loads previous hidden state vector into memory
UpdateWeightInput, UpdateWeightHidden, UpdateBias = self.GetWeights('Update')
UpdateGate = mx.nd.sigmoid(mx.nd.dot(X,UpdateWeightInput) + mx.nd.dot(HiddenStateVector, UpdateWeightHidden) + UpdateBias)
del UpdateWeightInput, UpdateWeightHidden, UpdateBias
# Computes the update gate
ResetWeightInput, ResetWeightHidden, ResetBias = self.GetWeights('Reset')
ResetGate = mx.nd.sigmoid(mx.nd.dot(X, ResetWeightInput) + mx.nd.dot(HiddenStateVector, ResetWeightHidden) + ResetBias)
del ResetWeightInput, ResetWeightHidden, ResetBias
# Computes the reset gate
HiddenWeightInput, HiddenWeightHidden, HiddenBias = self.GetWeights('Hidden')
HiddenGate = mx.nd.tanh(mx.nd.dot(X, HiddenWeightInput) + mx.nd.dot(ResetGate * HiddenStateVector, HiddenWeightHidden) + HiddenBias)
del HiddenWeightInput, HiddenWeightHidden, HiddenBias, ResetGate
# Computes the hidden gate
HiddenStateVector = UpdateGate * HiddenStateVector + (1-UpdateGate) * HiddenGate
pickle.dump(HiddenStateVector, open(self.HiddenStateVectorPath, 'wb'))
# Computes the hidden state vector and saves it to memory
output = pickle.load(open(self.outputpath, 'rb'))
outputBias = pickle.load(open(self.outputBiaspath, 'rb'))
# Computes the output and output bias
return mx.nd.dot(HiddenStateVector, output) + outputBias
# Forward pass through the neural network
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, I am making a gated recurrent unit from scratch and I am having trouble getting the autograd package to calculate the gradients correctly.
Here is the error I am getting:
MXNetError: Check failed: !AGInfo: :IsNone(*i): Cannot differentiate node because it is not in a computational graph. You need to set is_recording to true or use autograd.record() to save computational graphs for backward. If you want to differentiate the same graph twice, you need to pass retain_graph=True to backward.
Have one of yall had this issue before? How can I go about fixing it?
Attached below is the code I am using to compute the gradients. All the weights and biases have had .attach_grad() called on them when I initialized them.
Beta Was this translation helpful? Give feedback.
All reactions