-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[FEATURE] Add feature of attach_grad to nonleaf variables in HybridizedBlock. #20559
Conversation
Hey @KexinFeng , Thanks for submitting the PR
CI supported jobs: [sanity, windows-gpu, clang, edge, unix-cpu, windows-cpu, unix-gpu, centos-cpu, website, miscellaneous, centos-gpu] Note: |
python/mxnet/gluon/block.py
Outdated
if not self._active: | ||
raise RuntimeError('Hybridize must be active in order to use mark_vars') |
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.
For a good user experience, it would be great if we have an API that supports both hybrid and imperative mode. It doesn't need to use the same backend implementation, but it would be good to have a consistent frontend API.
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.
Now both hybridized and unhybrized are unified. This is shown in the last two examples in unittest/test_autograd.py
4b28fc8
to
1ac82bb
Compare
1ac82bb
to
84b1626
Compare
Description
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 theattach_grad
implemented in implemented in PR#20500.The motivation of this feature comes from this issue#11865.
Checklist
Essentials
Changes
block.py
wheremark_vars
andget_mark_vars
are added along withMXNDArrayMarkDCVariables
.cached_op.invoke
in cpp backend andCachedOp.__call__
have been editted to include the pass of marked nonleaf ndarrays.set_nleafs
method is added intoCachedOp
class to store the marked nonleaf ndarrays.void RunGraph
, marked nonleaf ndarrays are linked to the marked computational node for autograd computation.Comments