KexinFeng commented on a change in pull request #20559:
URL: https://github.com/apache/incubator-mxnet/pull/20559#discussion_r698727521
##########
File path: python/mxnet/gluon/block.py
##########
@@ -1635,6 +1637,47 @@ def reset_ctx(self, ctx):
for p in params.values():
p.reset_ctx(ctx)
+ def mark_vars(self, var_arrays):
+ """Mark the intermediate nodes
+
+ Parameters
+ ----------
+ vars: NDArrays or List[NDArrays] with nonempty
deferredcomputation_entry_
+ """
+ if not self._active:
+ var_arrays = _as_list(var_arrays)
+ self._nleaf_vars.extend(var_arrays)
+ else:
+ prev_val = dc.set_deferred_compute(False)
+ var_arrays = _as_list(var_arrays)
+ # Prepare ctypes array types
+ import ctypes
+ var_handles_type = ctypes.c_void_p * len(var_arrays)
+ # Convert handles
+ var_handles = var_handles_type(*[arr.handle for arr in var_arrays])
+ check_call(_LIB.MXNDArrayMarkDCVariables(var_handles,
len(var_arrays), len(self._nleaf_vars)))
+ self._nleaf_vars.extend(var_arrays)
+ dc.set_deferred_compute(prev_val)
+
+ def get_mark_vars(self, mark_ids):
+ """Retrieve the marked ndarrays according to the order they are marked
+
+ Parameters
+ ----------
+ mark_ids: int or List[int], the order by which the ndarray is marked
Review comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]