samskalicky commented on a change in pull request #17623: Dynamic subgraph
compile support
URL: https://github.com/apache/incubator-mxnet/pull/17623#discussion_r388508840
##########
File path: python/mxnet/gluon/block.py
##########
@@ -1026,6 +1030,53 @@ def _call_cached_op(self, *args):
out = [out]
return _regroup(out, self._out_format)
+ def optimize_for(self, x, *args, backend=None, backend_opts=None,
**kwargs):
+ """Activates or deactivates :py:class:`HybridBlock` s recursively. Has
no effect on
+ non-hybrid children.
+
+ Parameters
+ ----------
+ x : NDArray
+ first input to model
+ *args : NDArray
+ other inputs to model
+ backend : str
+ The name of backend, as registered in `SubgraphBackendRegistry`,
default None
+ backend_opts : dict of user-specified options to pass to the backend
for partitioning, optional
+ Passed on to `PrePartition` and `PostPartition` functions of
`SubgraphProperty`
+ static_alloc : bool, default False
+ Statically allocate memory to improve speed. Memory usage may
increase.
+ static_shape : bool, default False
+ Optimize for invariant input shapes between iterations. Must also
+ set static_alloc to True. Change of input shapes is still allowed
+ but slower.
+ """
+
+ # do hybrize API call
+ self.hybridize(True, backend, backend_opts, **kwargs)
Review comment:
The meaning of `optimize_for` API in Symbol class is to partition the model.
In Gluon to partition we have to hybridize to build the symbol, and then
partition it. So it made sense to integrate that inside as a single step for
the user.
GluonCV does a similar thing with its `export_block` API where they call
hybridize under the hood instead to provide a better user experience with a
single API call.
https://github.com/dmlc/gluon-cv/blob/9921323263d3698ce3e03a9eb4ada208b7b8bce3/gluoncv/utils/export_helper.py#L129-L133
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services