Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Add hybridblock hybridize() description
Browse files Browse the repository at this point in the history
  • Loading branch information
guanxinq committed Feb 5, 2020
1 parent 80dfaed commit 966a383
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions python/mxnet/gluon/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,20 +656,8 @@ 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)

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 966a383

Please sign in to comment.