[1.x] Move block.optimize_for backend_opts to kwargs#19386
[1.x] Move block.optimize_for backend_opts to kwargs#19386samskalicky merged 9 commits intoapache:v1.xfrom
Conversation
|
Hey @Kh4L , Thanks for submitting the PR
CI supported jobs: [edge, unix-gpu, unix-cpu, windows-gpu, miscellaneous, sanity, centos-cpu, centos-gpu, clang, website, windows-cpu] Note: |
Signed-off-by: Serge Panev <[email protected]>
aa7a4d1 to
7373172
Compare
|
@mxnet-bot run ci [edge, unix-cpu] |
|
Jenkins CI successfully triggered : [edge, unix-cpu] |
python/mxnet/gluon/block.py
Outdated
| return _regroup(out, self._out_format) | ||
|
|
||
| def optimize_for(self, x, *args, backend=None, backend_opts=None, clear=True, **kwargs): | ||
| def optimize_for(self, x, *args, backend=None, clear=True, static_alloc=False, static_shape=False, **kwargs): |
There was a problem hiding this comment.
I like this, can we do the same for hybridize and eliminate backend_opts altogether?
Change:
def hybridize(self, active=True, backend=None, backend_opts=None, clear=True, **kwargs):
To:
def hybridize(self, active=True, backend=None, clear=True, static_alloc=False, static_shape=False, **kwargs):
6708b59 to
0bc6c84
Compare
Signed-off-by: Serge Panev <[email protected]>
python/mxnet/gluon/block.py
Outdated
| self.hybridize(True, backend, backend_opts, clear, **kwargs) | ||
| if clear or not self._active: | ||
| self.hybridize(True, backend, clear, static_alloc, static_shape, | ||
| inline_limit, forward_bulk_size, backward_bulk_size, kwargs) |
There was a problem hiding this comment.
we dont need to pass kwargs here since we just set them above
Signed-off-by: Serge Panev <[email protected]>
samskalicky
left a comment
There was a problem hiding this comment.
Thanks @Kh4L for all the iterations! This is huge simplification in user experience!
| 'If "{block}" is a child of HybridBlock, the hooks will not take effect.' | ||
| .format(block=self)) | ||
| super(HybridBlock, self).hybridize(active, **kwargs) | ||
| super(HybridBlock, self).hybridize(active, |
There was a problem hiding this comment.
Should we explicitly specify args for Block.hybridize as well now that we have done it here?
https://github.com/apache/incubator-mxnet/blob/09d0cc8418cddefddf3f03aeeb1cbeb1fd4cbafa/python/mxnet/gluon/block.py#L658-L662
There was a problem hiding this comment.
no we can leave this as-is for the Block class since it doesnt really care about what the kwargs are anyway, its just going to pass them all recursively to its children. It would also be a 2nd place were the args would be duplicated for no benefit, creating a maintenance issue.
Signed-off-by: Serge Panev <[email protected]>
* Move block.optimize_for backend_opts to kwargs Signed-off-by: Serge Panev <[email protected]> * Update Hybridize to use kwargs as backend opts Signed-off-by: Serge Panev <[email protected]> * Fix lint Signed-off-by: Serge Panev <[email protected]> * Change clear default to False and allow hybrize+optimize_for calls Signed-off-by: Serge Panev <[email protected]> * Fix nit Signed-off-by: Serge Panev <[email protected]> * Adress review comments Signed-off-by: Serge Panev <[email protected]> * Adress more review comments Signed-off-by: Serge Panev <[email protected]> * Adress more more review comments Signed-off-by: Serge Panev <[email protected]> * Fix nit Signed-off-by: Serge Panev <[email protected]>
* Move block.optimize_for backend_opts to kwargs Signed-off-by: Serge Panev <[email protected]> * Update Hybridize to use kwargs as backend opts Signed-off-by: Serge Panev <[email protected]> * Fix lint Signed-off-by: Serge Panev <[email protected]> * Change clear default to False and allow hybrize+optimize_for calls Signed-off-by: Serge Panev <[email protected]> * Fix nit Signed-off-by: Serge Panev <[email protected]> * Adress review comments Signed-off-by: Serge Panev <[email protected]> * Adress more review comments Signed-off-by: Serge Panev <[email protected]> * Adress more more review comments Signed-off-by: Serge Panev <[email protected]> * Fix nit Signed-off-by: Serge Panev <[email protected]>
* Update MXNet-TRT doc with the new optimize_for API Signed-off-by: Serge Panev <[email protected]> * [1.x] Move block.optimize_for backend_opts to kwargs (#19386) * Move block.optimize_for backend_opts to kwargs Signed-off-by: Serge Panev <[email protected]> * Update Hybridize to use kwargs as backend opts Signed-off-by: Serge Panev <[email protected]> * Fix lint Signed-off-by: Serge Panev <[email protected]> * Change clear default to False and allow hybrize+optimize_for calls Signed-off-by: Serge Panev <[email protected]> * Fix nit Signed-off-by: Serge Panev <[email protected]> * Adress review comments Signed-off-by: Serge Panev <[email protected]> * Adress more review comments Signed-off-by: Serge Panev <[email protected]> * Adress more more review comments Signed-off-by: Serge Panev <[email protected]> * Fix nit Signed-off-by: Serge Panev <[email protected]> * Add 1:many conversions in nnvm_to_onnx and non-flatten GEMM (#19652) Signed-off-by: Serge Panev <[email protected]>
Description
symbol.optimize_forbackend options are given as kwargs but theblock.optimize_forones are given as a separatebackend_optsdict.We end up with an API discrepancy, than can be confusing for the user. Here's an exemple:
Symbol
Block (Gluon)
This limitation was due to preserve the kwargs from hybridize.
However this kwargs is virtually only used to forward the
static_allocandstatic_shapearguments.Change
This PR factors out
static_allocandstatic_shapeand changes thekwargs, in bothoptimize_forandhybridize.Example after the change:
will be now called as
Note: if needed in the future, we can add an
extra_hybridize_kwargs.