[FEATURE] Add feature of attach_grad to nonleaf variables in HybridizedBlock.
Description
This is the same as this https://github.com/apache/incubator-mxnet/pull/20559. The PR adds the support for fetching the gradients of intermediate variables in a gluon HybridizedBlock. This applies uniformly to both when block.hybridize() is on and off. This generates the attach_grad implemented in implemented in PR#20500.
The motivation of this feature comes from this issue#11865.
Checklist
Essentials
- [x] PR's title starts with a category (e.g. [BUGFIX], [MODEL], [TUTORIAL], [FEATURE], [DOC], etc)
- [x] Changes are complete (i.e. I finished coding on this PR)
- [x] All changes have test coverage
- [x] Code is well-documented
Changes
- [x]
block.pywheremark_varsandget_mark_varsare added along withMXNDArrayMarkDCVariables. - [x]
cached_op.invokein cpp backend andCachedOp.__call__have been editted to include the pass of marked nonleaf ndarrays. - [x]
set_nleafsmethod is added intoCachedOpclass to store the marked nonleaf ndarrays. - [x] Inside
void RunGraph, marked nonleaf ndarrays are linked to the marked computational node for autograd computation.
Comments
- This feature is built on top of PR#20500. The modification here is mainly in the invoke of CachedOp computation.
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: [website, clang, miscellaneous, sanity, windows-cpu, edge, windows-gpu, centos-cpu, unix-cpu, unix-gpu, centos-gpu]
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.
@mxnet-bot run ci [unix-cpu, unix-gpu, windows-gpu]
Jenkins CI successfully triggered : [windows-gpu, unix-cpu, unix-gpu]
@mxnet-bot run ci [centos-gpu, windows-gpu]
Jenkins CI successfully triggered : [centos-gpu, windows-gpu]
@mxnet-bot run ci [centos-gpu, windows-gpu]
Jenkins CI successfully triggered : [windows-gpu, centos-gpu]
@mxnet-bot run ci [unix-gpu]
Jenkins CI successfully triggered : [unix-gpu]
@mxnet-bot run ci [macosx-x86_64]
Undefined action detected. Permissible actions are : run ci [all], run ci [job1, job2] Example : @mxnet-bot run ci [all] Example : @mxnet-bot run ci [centos-cpu, clang]
None of the jobs entered are supported. Jobs entered by user: [macosx-x86_64] CI supported Jobs: [unix-cpu, website, sanity, unix-gpu, clang, centos-gpu, windows-cpu, windows-gpu, miscellaneous, edge, centos-cpu]
@mxnet-bot run ci [centos-gpu ]
Jenkins CI successfully triggered : [centos-gpu]
Jenkins CI successfully triggered : [centos-gpu]
@mxnet-bot run ci [centos-gpu ]
Jenkins CI successfully triggered : [centos-gpu]
Jenkins CI successfully triggered : [centos-gpu]
@mxnet-bot run ci [macosx-x86_64]
None of the jobs entered are supported. Jobs entered by user: [macosx-x86_64] CI supported Jobs: [sanity, centos-cpu, clang, unix-cpu, windows-cpu, windows-gpu, miscellaneous, centos-gpu, unix-gpu, edge, website]
@mxnet-bot run ci [macosx-x86_64]
None of the jobs entered are supported. Jobs entered by user: [macosx-x86_64] CI supported Jobs: [sanity, centos-cpu, clang, unix-cpu, windows-cpu, windows-gpu, miscellaneous, centos-gpu, unix-gpu, edge, website]
@mxnet-bot run ci [edge, unix-gpu]
Jenkins CI successfully triggered : [unix-gpu, edge]
@mxnet-bot run ci [unix-gpu]
Jenkins CI successfully triggered : [unix-gpu]
@mxnet-bot run ci [unix-gpu]
Jenkins CI successfully triggered : [unix-gpu]