This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[bug] fix higher grad log #15120
Merged
apeforest
merged 7 commits into
apache:master
from
kshitij12345:fix-higher-grad-log-bug
Jun 20, 2019
Merged
[bug] fix higher grad log #15120
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
03cd1c7
fix bug with higher order log implementation.
kshitij12345 37ce3b8
fix grad for head_grads and update relevant test
kshitij12345 10f2b10
address comments
kshitij12345 dee4efb
Merge branch 'master' of https://github.com/apache/incubator-mxnet in…
kshitij12345 23eaf42
address comments
kshitij12345 7736801
Merge branch 'master' of https://github.com/apache/incubator-mxnet in…
kshitij12345 cf80ed6
fix mistyped comment.
kshitij12345 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,13 +108,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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still don't understand what this variable is mathematically... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the clarification. |
||
|
||
# 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(heads=y, variables=x, head_grads=y_grad, | ||
create_graph=True, retain_graph=True)[0] | ||
x_grad.backward(head_grad_grads) | ||
|
||
# Compute expected values. | ||
expected_grad_grad = grad_grad_x.asnumpy() * head_grad_grads.asnumpy() * \ | ||
y_grad.asnumpy() | ||
|
||
# Validate the gradients. | ||
assert_almost_equal(expected_grad_grad, x.grad.asnumpy()) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't elemwise_div require two inputs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it does. However I guess, this thing is skipped in the test computation graph and hence we don't see the error.
Will fix it. However we should somehow find a way to test for the same.