apeforest commented on a change in pull request #15120: [bug] fix higher grad 
log 
URL: https://github.com/apache/incubator-mxnet/pull/15120#discussion_r293485580
 
 

 ##########
 File path: tests/python/unittest/test_higher_order_grad.py
 ##########
 @@ -66,13 +66,26 @@ def grad_grad_op(x):
 
 def check_second_order_unary(x, op, grad_grad_op):
     x = nd.array(x)
-    expect_grad_grad = grad_grad_op(x)
+    grad_grad_x = grad_grad_op(x)
     x.attach_grad()
+
+    # Manual head_grads.
+    y_grad = nd.random.normal(shape=x.shape)
+    head_grad_grads = nd.random.normal(shape=x.shape)
+
+    # Perform compute.
     with autograd.record():
         y = op(x)
-        y_grad = autograd.grad(y, x, create_graph=True, retain_graph=True)[0]
-    y_grad.backward()
-    assert_almost_equal(expect_grad_grad.asnumpy(), x.grad.asnumpy())
+        x_grad = autograd.grad(y, x, head_grads=y_grad,
 
 Review comment:
   Can you explicitly specify the argument as 
   
   ```suggestion
           x_grad = autograd.grad(heads=y, variables=x, head_grads=y_grad, 
create_graph=True, retain_graph=True)
   ```
   
   I think this will make it easier to understand.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to