[FEATURE] Add feature of retain_grad #20500
Conversation
|
Hey @KexinFeng , Thanks for submitting the PR
CI supported jobs: [centos-gpu, centos-cpu, windows-cpu, unix-gpu, website, sanity, edge, miscellaneous, unix-cpu, windows-gpu, clang] Note: |
|
@mxnet-bot run ci [all] |
|
Jenkins CI successfully triggered : [clang, windows-cpu, miscellaneous, centos-cpu, unix-cpu, edge, website, windows-gpu, sanity, centos-gpu, unix-gpu] |
|
@mxnet-bot run ci [unix-cpu] |
|
Jenkins CI successfully triggered : [unix-cpu] |
|
@mxnet-bot run ci [macosx-x86_64, linkcheck] |
|
None of the jobs entered are supported. |
|
@mxnet-bot run ci [centos-gpu, unix-gpu] |
|
Jenkins CI successfully triggered : [centos-gpu, unix-gpu] |
|
@mxnet-bot run ci [website] |
|
Jenkins CI successfully triggered : [website] |
|
@mxnet-bot run ci [unix-cpu] |
|
Jenkins CI successfully triggered : [unix-cpu] |
|
@mxnet-bot run ci [unix-cpu] |
|
Jenkins CI successfully triggered : [unix-cpu] |
|
@mxnet-bot run ci [unix-gpu, centos-gpu] |
|
Jenkins CI successfully triggered : [centos-gpu, unix-gpu] |
|
@mxnet-bot run ci [centos-gpu] |
|
Jenkins CI successfully triggered : [centos-gpu] |
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
Changes
Imperative::MarkVariablesinsrc/imperative/imperative.ccto include the case of marking nonleaf nodesImperative::Backwardinsrc/imperative/imperative.ccto retrieve nonleaf nodes and linknode->info.out_grads[]to buffered arrays.Graph BuildGradientGraphto map forward node to the corresponding gradient node entry.Comments
z.retain_grad(). 2. when it is used combined with detaching computation.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.