This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix block.export #17970
Merged
Merged
fix block.export #17970
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1c5a325
fix block.export
chinakook da18626
Update block.py
chinakook 8e5e618
add allow_extra
chinakook b75bedf
Update block.py
chinakook e702da9
Update python/mxnet/gluon/block.py
chinakook acb8418
Update block.py
chinakook 3a4cb53
Merge branch 'master' into patch-6
chinakook 7e8b2e7
Update block.py
chinakook 5df00db
Update python/mxnet/gluon/block.py
chinakook File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1234,7 +1234,7 @@ def infer_type(self, *args): | |
"""Infers data type of Parameters from inputs.""" | ||
self._infer_attrs('infer_type', 'dtype', *args) | ||
|
||
def export(self, path, epoch=0, remove_amp_cast=True): | ||
def export(self, path, epoch=0, remove_amp_cast=True, allow_extra=True): | ||
"""Export HybridBlock to json format that can be loaded by | ||
`gluon.SymbolBlock.imports`, `mxnet.mod.Module` or the C++ interface. | ||
|
||
|
@@ -1248,7 +1248,11 @@ def export(self, path, epoch=0, remove_amp_cast=True): | |
will be created, where xxxx is the 4 digits epoch number. | ||
epoch : int | ||
Epoch number of saved model. | ||
|
||
remove_amp_cast : bool, optional | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Returns | ||
------- | ||
symbol_filename : str | ||
|
@@ -1271,8 +1275,13 @@ def export(self, path, epoch=0, remove_amp_cast=True): | |
if name in arg_names: | ||
arg_dict['arg:%s'%name] = param._reduce() | ||
else: | ||
assert name in aux_names | ||
arg_dict['aux:%s'%name] = param._reduce() | ||
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 commentThe 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 |
||
else: | ||
if allow_extra: | ||
arg_dict['aux:%s'%name] = param._reduce() | ||
save_fn = _mx_npx.save if is_np_array() else ndarray.save | ||
params_filename = '%s-%04d.params'%(path, epoch) | ||
save_fn(params_filename, arg_dict) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.