From 14dcc14c495cd04ee612b89ee0e15ef7fb0cdd2a Mon Sep 17 00:00:00 2001 From: guanxinq Date: Wed, 5 Feb 2020 22:35:36 +0000 Subject: [PATCH] Add hybridblock hybridize() description --- python/mxnet/gluon/block.py | 40 ++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/python/mxnet/gluon/block.py b/python/mxnet/gluon/block.py index 5b6b3ef70532..f13993eb3fc3 100644 --- a/python/mxnet/gluon/block.py +++ b/python/mxnet/gluon/block.py @@ -656,19 +656,7 @@ def initialize(self, init=initializer.Uniform(), ctx=None, verbose=False, self.collect_params().initialize(init, ctx, verbose, force_reinit) def hybridize(self, active=True, **kwargs): - """Activates or deactivates :py:class:`HybridBlock` s recursively. Has no effect on - non-hybrid children. - - Parameters - ---------- - active : bool, default True - Whether to turn hybrid on or off. - 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. + """ Please refer description of HybridBlock hybridize(). """ for cld in self._children.values(): cld.hybridize(active, **kwargs) @@ -1053,11 +1041,31 @@ def register_child(self, block, name=None): self._clear_cached_op() def hybridize(self, active=True, backend=None, backend_args=None, **kwargs): + """Activates or deactivates :py:class:`HybridBlock` s recursively. Has no effect on + non-hybrid children. + + Parameters + ---------- + active : bool, default True + Whether to turn hybrid on or off. + backend : str + The name of backend, as registered in `SubgraphBackendRegistry`, default None + backend_args : dict of arguments, 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. + """ + self._backend = backend - if backend_args is None: - self._backend_args = {} - else: + if backend_args is not None: + assert isinstance(backend_args, dict), \ + "HybridBlock hybridize requires backend_args to be a dictionary." self._backend_args = backend_args + self._active = active self._flags = list(kwargs.items()) self._clear_cached_op()