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

[FEATURE] Add feature of retain_grad #20500

Merged
merged 36 commits into from
Sep 23, 2021
Merged

Conversation

KexinFeng
Copy link
Contributor

@KexinFeng KexinFeng commented Aug 9, 2021

Description

The PR adds the support for fetching the gradients of intermediate variables in a computation graph.

The motivation of this feature comes from this issue.

Checklist

Essentials

  • PR's title starts with a category (e.g. [BUGFIX], [MODEL], [TUTORIAL], [FEATURE], [DOC], etc)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage
  • Code is well-documented

Changes

  • Imperative::MarkVariables in src/imperative/imperative.cc to include the case of marking nonleaf nodes
  • Imperative::Backward in src/imperative/imperative.cc to retrieve nonleaf nodes and link node->info.out_grads[] to buffered arrays.
  • Graph BuildGradientGraph to map forward node to the corresponding gradient node entry.

Comments

  • Interesting edge cases to note here: 1. the gradient-queried node is the output node, z.retain_grad(). 2. when it is used combined with detaching computation.
  • Note that u.retain_grad() is called outside the scope of ag.record(). Otherwise, u.retain_grad() would be recorded as operation and trigger building of computational node. This is conceptually not desired.

@mxnet-bot
Copy link

Hey @KexinFeng , Thanks for submitting the PR
All tests are already queued to run once. If tests fail, you can trigger one or more tests again with the following commands:

  • To trigger all jobs: @mxnet-bot run ci [all]
  • To trigger specific jobs: @mxnet-bot run ci [job1, job2]

CI supported jobs: [centos-gpu, centos-cpu, windows-cpu, unix-gpu, website, sanity, edge, miscellaneous, unix-cpu, windows-gpu, clang]


Note:
Only following 3 categories can trigger CI :PR Author, MXNet Committer, Jenkins Admin.
All CI tests must pass before the PR can be merged.

@mseth10 mseth10 added the pr-awaiting-testing PR is reviewed and waiting CI build and test label Aug 9, 2021
@KexinFeng KexinFeng changed the title Add feature of retain_grad Add feature of retain_grad [FEATURE] [issue](https://github.com/apache/incubator-mxnet/issues/11865) Aug 9, 2021
@KexinFeng KexinFeng changed the title Add feature of retain_grad [FEATURE] [issue](https://github.com/apache/incubator-mxnet/issues/11865) Add feature of retain_grad [FEATURE] Aug 9, 2021
@KexinFeng KexinFeng changed the title Add feature of retain_grad [FEATURE] [FEATURE] Add feature of retain_grad Aug 9, 2021
@mseth10 mseth10 added pr-work-in-progress PR is still work in progress and removed pr-awaiting-testing PR is reviewed and waiting CI build and test labels Aug 9, 2021
@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-work-in-progress PR is still work in progress and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test labels Aug 11, 2021
@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test and removed pr-work-in-progress PR is still work in progress labels Aug 11, 2021
@mseth10 mseth10 added pr-work-in-progress PR is still work in progress and removed pr-awaiting-testing PR is reviewed and waiting CI build and test labels Aug 11, 2021
@mseth10 mseth10 removed the pr-work-in-progress PR is still work in progress label Aug 12, 2021
@mxnet-bot
Copy link

Jenkins CI successfully triggered : [unix-cpu]

@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-awaiting-review PR is waiting for code review and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test labels Aug 28, 2021
@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-work-in-progress PR is still work in progress and removed pr-awaiting-review PR is waiting for code review pr-awaiting-testing PR is reviewed and waiting CI build and test labels Sep 17, 2021
@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-work-in-progress PR is still work in progress and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test labels Sep 17, 2021
@barry-jin
Copy link
Contributor

@mxnet-bot run ci [unix-gpu, centos-gpu]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [centos-gpu, unix-gpu]

@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-work-in-progress PR is still work in progress and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test labels Sep 17, 2021
@barry-jin
Copy link
Contributor

@mxnet-bot run ci [centos-gpu]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [centos-gpu]

@mseth10 mseth10 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-awaiting-review PR is waiting for code review and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test labels Sep 20, 2021
@barry-jin barry-jin merged commit 05d1b26 into apache:master Sep 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr-awaiting-review PR is waiting for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants