samskalicky commented on a change in pull request #17623: Dynamic subgraph 
compile support
URL: https://github.com/apache/incubator-mxnet/pull/17623#discussion_r388635890
 
 

 ##########
 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:
   calling `hybridize` and then `optimize_for` is fine. Since `optimize_for` 
will just call `hybridize` again internally anyway.
   
   Calling `optimize_for` and then `hybridize` though will reset the cachedOp 
since `hybridize` calls `_clear_cached_op`. So not a problem per-se. User just 
needs to realize what they are doing.

----------------------------------------------------------------
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

Reply via email to