Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[MXNET-1095] [WIP] Support higher order gradient for cos,sin,negative,mul #12821

Closed
wants to merge 1 commit into from

Conversation

sxjscience
Copy link
Member

@sxjscience sxjscience commented Oct 14, 2018

Description

For context, please refer #10002

Support higher order gradient for cos, sin, negative, mul. I'll add the test later. For now, you may use the following code to test the correctness:

import mxnet.ndarray as nd
from mxnet import autograd
from mxnet.test_utils import assert_almost_equal

x = nd.array([3.0])
x.attach_grad()
with autograd.record():
    y = nd.sin(x)
    y_grad = autograd.grad(y, x, create_graph=True, retain_graph=True)[0]
    z = y_grad * y_grad # Should be cos(x)^2
z.backward()
print(x.grad) # Should be - 2 * cos(x) * sin(x)
gt_grad = - 2 * nd.cos(x) * nd.sin(x)
assert_almost_equal(x.grad.asnumpy(), gt_grad.asnumpy())
[0.2794155]
<NDArray 1 @cpu(0)>

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • higher-order gradient of sin,cos,negative,mul, tests

Comments

  • Need to support more OPs.

@sxjscience
Copy link
Member Author

Need to benchmark the performance though. (I feel that the performance should be similar.)

@sxjscience sxjscience changed the title [WIP] Support higher order gradient for cos,sin,negative,mul [MXNET-1095] [WIP] Support higher order gradient for cos,sin,negative,mul Oct 14, 2018
@Roshrini
Copy link
Member

@mxnet-label-bot [pr-work-in-progress, Operator]

@marcoabreu marcoabreu added Operator pr-work-in-progress PR is still work in progress labels Oct 15, 2018
@ankkhedia
Copy link
Contributor

@sxjscience Thanks for the contribution!
Did you get a chance to benchmark theses changes?

@anirudhacharya
Copy link
Member

@sxjscience pinging for update on this PR :)

@stu1130
Copy link
Contributor

stu1130 commented Nov 21, 2018

@sxjscience ping again
feel free to close it and reopen it once you have time

@sxjscience
Copy link
Member Author

I'll continue working on it next week.

@roywei
Copy link
Member

roywei commented Dec 11, 2018

@sxjscience Thanks for the contribution, do you have any documentations to link? It will help othert contributors adding more operators. Thanks!

@sandeep-krishnamurthy
Copy link
Contributor

@apeforest - FYI

@stu1130
Copy link
Contributor

stu1130 commented Jan 15, 2019

@sxjscience any plan to work on this? Thanks

@sxjscience
Copy link
Member Author

sxjscience commented Jan 16, 2019 via email

@pinaraws
Copy link

@sxjscience Any updates? Are you still planning to continue to work on this PR?

@sxjscience
Copy link
Member Author

sxjscience commented Mar 19, 2019 via email

@piyushghai
Copy link
Contributor

@sxjscience Can this PR be closed if the work is being followed up in another PR by @apeforest as commented above ?

@sxjscience
Copy link
Member Author

sxjscience commented Apr 9, 2019 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Operator pr-work-in-progress PR is still work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants