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

[1.x] Move block.optimize_for backend_opts to kwargs #19386

Merged
merged 9 commits into from
Nov 16, 2020

Conversation

Kh4L
Copy link
Contributor

@Kh4L Kh4L commented Oct 20, 2020

Description

symbol.optimize_for backend options are given as kwargs but the block.optimize_for ones are given as a separate backend_opts dict.

We end up with an API discrepancy, than can be confusing for the user. Here's an exemple:

Symbol

sym.optimize_for(backend, args, reqArgs=True, dedup_subgraph=True)

Block (Gluon)

blk.optimize_for(x, backend="addInputPass", clear=False, backend_opts={'dedup_subgraph':True})

This limitation was due to preserve the kwargs from hybridize.
However this kwargs is virtually only used to forward the static_alloc and static_shape arguments.

Change

This PR factors out static_alloc and static_shape and changes the kwargs, in both optimize_for and hybridize.

Example after the change:

blk.optimize_for(x, backend="addInputPass", clear=False, backend_opts={'dedup_subgraph':True})

will be now called as

blk.optimize_for(x, backend="addInputPass", clear=False, dedup_subgraph=True)

Note: if needed in the future, we can add an extra_hybridize_kwargs.

@mxnet-bot
Copy link

Hey @Kh4L , Thanks for submitting the PR
All tests are already queued to run once. If tests fail, you can trigger one or more tests again with the following commands:

  • To trigger all jobs: @mxnet-bot run ci [all]
  • To trigger specific jobs: @mxnet-bot run ci [job1, job2]

CI supported jobs: [edge, unix-gpu, unix-cpu, windows-gpu, miscellaneous, sanity, centos-cpu, centos-gpu, clang, website, windows-cpu]


Note:
Only following 3 categories can trigger CI :PR Author, MXNet Committer, Jenkins Admin.
All CI tests must pass before the PR can be merged.

@lanking520 lanking520 added the pr-work-in-progress PR is still work in progress label Oct 20, 2020
@Kh4L Kh4L changed the title [WIP] Move block.optimize_for backend_opts to kwargs [WIP][1.x] Move block.optimize_for backend_opts to kwargs Oct 21, 2020
@Kh4L Kh4L force-pushed the optimize_for_backend_opts_kwargs branch from aa7a4d1 to 7373172 Compare October 21, 2020 05:33
@Kh4L Kh4L changed the title [WIP][1.x] Move block.optimize_for backend_opts to kwargs [1.x] Move block.optimize_for backend_opts to kwargs Oct 23, 2020
@lanking520 lanking520 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-awaiting-review PR is waiting for code review pr-work-in-progress PR is still work in progress and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test pr-awaiting-review PR is waiting for code review labels Oct 23, 2020
@Kh4L
Copy link
Contributor Author

Kh4L commented Oct 30, 2020

@mxnet-bot run ci [edge, unix-cpu]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [edge, unix-cpu]

@lanking520 lanking520 added pr-awaiting-review PR is waiting for code review and removed pr-work-in-progress PR is still work in progress labels Oct 30, 2020
@@ -1059,7 +1059,7 @@ 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, clear=True, **kwargs):
def optimize_for(self, x, *args, backend=None, clear=True, static_alloc=False, static_shape=False, **kwargs):
Copy link
Contributor

@samskalicky samskalicky Nov 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@lanking520 lanking520 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-work-in-progress PR is still work in progress and removed pr-awaiting-review PR is waiting for code review pr-awaiting-testing PR is reviewed and waiting CI build and test labels Nov 5, 2020
@Kh4L Kh4L force-pushed the optimize_for_backend_opts_kwargs branch from 6708b59 to 0bc6c84 Compare November 5, 2020 19:49
@lanking520 lanking520 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-work-in-progress PR is still work in progress and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test labels Nov 5, 2020
@lanking520 lanking520 added the pr-awaiting-testing PR is reviewed and waiting CI build and test label Nov 14, 2020
Signed-off-by: Serge Panev <[email protected]>
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we dont need to pass kwargs here since we just set them above

Copy link
Contributor Author

@Kh4L Kh4L Nov 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

Copy link
Contributor

@samskalicky samskalicky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Kh4L for all the iterations! This is huge simplification in user experience!

if clear:
self._clear_cached_op()
if active and self._forward_hooks or self._forward_pre_hooks:
warnings.warn('"{block}" is being hybridized while still having forward hook/pre-hook. '
'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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

example/extensions/lib_subgraph/README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@mseth10 mseth10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for simplifying the API @Kh4L

@lanking520 lanking520 added pr-work-in-progress PR is still work in progress and removed pr-awaiting-testing PR is reviewed and waiting CI build and test labels Nov 14, 2020
Signed-off-by: Serge Panev <[email protected]>
@lanking520 lanking520 added pr-awaiting-testing PR is reviewed and waiting CI build and test pr-work-in-progress PR is still work in progress pr-awaiting-review PR is waiting for code review and removed pr-work-in-progress PR is still work in progress pr-awaiting-testing PR is reviewed and waiting CI build and test labels Nov 14, 2020
@samskalicky samskalicky added pr-awaiting-merge Review and CI is complete. Ready to Merge and removed pr-awaiting-review PR is waiting for code review labels Nov 15, 2020
@samskalicky samskalicky merged commit d0710e2 into apache:v1.x Nov 16, 2020
josephevans pushed a commit to josephevans/mxnet that referenced this pull request Dec 8, 2020
* 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]>
Kh4L added a commit to Kh4L/incubator-mxnet that referenced this pull request Mar 5, 2021
* 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]>
@Kh4L Kh4L mentioned this pull request Mar 5, 2021
ptrendx pushed a commit that referenced this pull request Mar 5, 2021
* 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]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr-awaiting-merge Review and CI is complete. Ready to Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants