This repository was archived by the owner on Nov 17, 2023. It is now read-only.
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
[MXNet 2.0 Autograd Error] Unexpected Error for Backward Argument #19021
Open
Description
Description
Unexpected gradient results when using .backward() with an array which does not match the functions input.
To Reproduce
# z= np.array([[ 6. 12.],[35. 48.]])
x = np.array([[2.0,3.0],[5,6]])
y = np.array([[3.0,4.0],[7,8]])
x.attach_grad()
y.attach_grad()
#Expected Result
with autograd.record():
z = np.sum(x*y)
z.backward()
print(1.5*x.grad)
print(1.5*y.grad)
#Expected Result
with autograd.record():
z = x*y
z.backward()
print(1.5*x.grad)
print(1.5*y.grad)
#Expected Result
with autograd.record():
z = np.sum(x*y)
z.backward(np.array([1.5]))
print(x.grad)
print(y.grad)
# Unexpected Result
with autograd.record():
z = x*y
z.backward(np.array([1.5]))
print(x.grad)
print(y.grad)
#Unexpected Result
with autograd.record():
z = x*y
z.backward(np.array([1.5,1.5]))
print(x.grad)
print(y.grad)
#Unexpected Result
with autograd.record():
z = x*y
z.backward(np.array([[1.5],[1.5]]))
print(x.grad)
print(y.grad)
Steps to reproduce
Run the code above
What have you tried to solve it?
Make sure the the input to z.backward() has the same shape as z
Environment
I don't think this is relevant right now. I am using !pip install --pre mxnet-cu102 -f https://dist.mxnet.io/python -q to install my environment.