You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/08/26 21:15:45 UTC

[GitHub] [incubator-mxnet] mathephysicist opened a new issue #19021: [MXNet 2.0 Autograd Error] Unexpected Error for Backward Argument

mathephysicist opened a new issue #19021:
URL: https://github.com/apache/incubator-mxnet/issues/19021


   ## 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.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org