-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Conversation
```net.hybridize``` may optimize out some ops. These ops are alive in nn.Block(also nn.HybridBlock), but its names are not contained in symbol's ```arg_names``` list. So ignore these ops except that their name are end with 'running_mean' or 'running_var'.
Hey @chinakook , Thanks for submitting the PR
CI supported jobs: [website, centos-gpu, miscellaneous, unix-gpu, centos-cpu, windows-cpu, sanity, unix-cpu, edge, clang, windows-gpu] Note: |
Thanks for your contribution! Is there any weakness to export all augumented variables? |
It's complicated for that rarely case, I think we can add a standard suffix or let user to register their suffix for user for this case. |
I have this problem just when I export a inference version of ICNet from gluoncv. Its results have four feature maps, but we only use the first one, so other ops and weighs related to the other three feature maps are optimized out by the symbol engine. |
let user can save their extra param.
add allow_extra to let user decide whether to save extra parameters or not.
I think it is related to
If some feature maps are optimized out, their auxiliary states should be removed in It seems that the extra auxiliary states are not removed when some ops are removed in the current implementation. |
It's not aux states that are optimized out. It's some normal convolution ops and weights unused by the graph. They are in the gluon's parameter dict but their name are not in the symbol's |
add moving_mean and moving_var when export model with SymbolBlock
typo Co-authored-by: Sheng Zha <szha@users.noreply.github.com>
cc @leezu |
@chinakook will you update the PR to fix the root cause of the issue? See the example by @sxjscience in #17981 |
I've tested. It can be export successfully after this fix. |
python/mxnet/gluon/block.py
Outdated
Whether to remove the amp_cast and amp_multicast operators, before exporting the model. | ||
allow_extra : bool, optional | ||
Whether to save extra parameters whose names are not in the result symbol. | ||
User can set allow_extra to True to load these parameters with old mxnet.mod.Module.set_params API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mxnet.mod.Module.set_params
does not exist anymore.
python/mxnet/gluon/block.py
Outdated
|
||
remove_amp_cast : bool, optional | ||
Whether to remove the amp_cast and amp_multicast operators, before exporting the model. | ||
allow_extra : bool, optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use-case to save parameters that are not used by the symbol? Do we need this option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's not necessary.
python/mxnet/gluon/block.py
Outdated
if name.endswith('running_mean') or name.endswith('running_var') \ | ||
or name.endswith('moving_mean') or name.endswith('moving_var'): | ||
assert name in aux_names | ||
arg_dict['aux:%s'%name] = param._reduce() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do we ensure that no aux parameter with a name different to running_mean
, running_var
, etc is missing from the resulting params file if allow_extra
is False
?
@chinakook can you help resolve the conflicts? |
Co-authored-by: Leonard Lausen <leonard@lausen.nl>
@mxnet-bot run ci [centos-gpu] |
Jenkins CI successfully triggered : [centos-gpu] |
* fix block.export ```net.hybridize``` may optimize out some ops. These ops are alive in nn.Block(also nn.HybridBlock), but its names are not contained in symbol's ```arg_names``` list. So ignore these ops except that their name are end with 'running_mean' or 'running_var'. * Update block.py let user can save their extra param. * add allow_extra add allow_extra to let user decide whether to save extra parameters or not. * Update block.py add moving_mean and moving_var when export model with SymbolBlock * Update python/mxnet/gluon/block.py typo Co-authored-by: Sheng Zha <szha@users.noreply.github.com> * Update block.py * Update block.py * Update python/mxnet/gluon/block.py Co-authored-by: Leonard Lausen <leonard@lausen.nl> Co-authored-by: Sheng Zha <szha@users.noreply.github.com> Co-authored-by: Leonard Lausen <leonard@lausen.nl>
* fix block.export ```net.hybridize``` may optimize out some ops. These ops are alive in nn.Block(also nn.HybridBlock), but its names are not contained in symbol's ```arg_names``` list. So ignore these ops except that their name are end with 'running_mean' or 'running_var'. * Update block.py let user can save their extra param. * add allow_extra add allow_extra to let user decide whether to save extra parameters or not. * Update block.py add moving_mean and moving_var when export model with SymbolBlock * Update python/mxnet/gluon/block.py typo Co-authored-by: Sheng Zha <szha@users.noreply.github.com> * Update block.py * Update block.py * Update python/mxnet/gluon/block.py Co-authored-by: Leonard Lausen <leonard@lausen.nl> Co-authored-by: Sheng Zha <szha@users.noreply.github.com> Co-authored-by: Leonard Lausen <leonard@lausen.nl>
* fix block.export ```net.hybridize``` may optimize out some ops. These ops are alive in nn.Block(also nn.HybridBlock), but its names are not contained in symbol's ```arg_names``` list. So ignore these ops except that their name are end with 'running_mean' or 'running_var'. * Update block.py let user can save their extra param. * add allow_extra add allow_extra to let user decide whether to save extra parameters or not. * Update block.py add moving_mean and moving_var when export model with SymbolBlock * Update python/mxnet/gluon/block.py typo Co-authored-by: Sheng Zha <szha@users.noreply.github.com> * Update block.py * Update block.py * Update python/mxnet/gluon/block.py Co-authored-by: Leonard Lausen <leonard@lausen.nl> Co-authored-by: Sheng Zha <szha@users.noreply.github.com> Co-authored-by: Leonard Lausen <leonard@lausen.nl>
net.hybridize
may optimize out some ops. These ops are alive in nn.Block(also nn.HybridBlock), but its names are not contained in symbol'sarg_names
list. So ignore these ops except that their name are end with 'running_mean' or 'running_var'.Description
(Brief description on what this PR is about)
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Changes
Comments