-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Refactor Export for Model Conversion and Saving #7934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Han123su <popsmall212@gmail.com>
for more information, see https://pre-commit.ci
Signed-off-by: Han123su <popsmall212@gmail.com>
Signed-off-by: Han123su <popsmall212@gmail.com>
Signed-off-by: Han123su <popsmall212@gmail.com>
Signed-off-by: Han123su <popsmall212@gmail.com>
ericspod
left a comment
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.
It looks much better now. I have a comment on docstrings and something optional about moving arguments around, but otherwise if all the tests pass this is good to go I feel.
|
@binliunls This PR is response to an issue you've raised previously, would you have any comment here? Thanks! |
|
Hi, @ericspod and @binliunls, thank you very much for your suggestions. However, it seems that there might be a slight conflict in the ideas behind the two proposed changes, suggestion 1 and suggestion 2. I would like to explain my thoughts on these two modifications. Thank you!
save_ts = partial(
save_net_with_metadata,
include_config_vals=False,
append_timestamp=False,
)
def _export(
...
) -> None:
...
...
meta_values = parser.get().pop("_meta_", None)
saver(net, filepath, more_extra_files=extra_files, meta_values=meta_values)
logger.info(f"exported to file: {filepath}.")When calling
def ckpt_export/trt_export(
...
) -> None:
...
...
################## Repeat part ####################
extra_files: dict = {}
for i in ensure_tuple(config_file_):
filename = os.path.basename(i)
filename, _ = os.path.splitext(filename)
if filename in extra_files:
raise ValueError(f"Filename part '{filename}' is given multiple times in config file list.")
extra_files[filename] = json.dumps(ConfigParser.load_config_file(i)).encode()
extra_files = {k + ".json": v for k, v in extra_files.items()}
################################################
save_ts = partial(
save_net_with_metadata,
include_config_vals=False,
append_timestamp=False,
meta_values=parser.get().pop("_meta_", None),
more_extra_files=extra_files,
)
...
def _export(
...
) -> None:
...
...
saver(net, filepath,)
...Moving the My thought is that we might perhaps adopt suggestion 1, calling the def save_onnx(onnx_obj: Any, filename_prefix_or_stream: str , **kwargs: Any) -> None:
onnx.save(onnx_obj, filename_prefix_or_stream)Thank you both for reading this explanation. I hope to receive feedback again to make this even better. Thank you very much! |
|
Hi @Han123su, thanks for the detailed explanation. I would prefer the first proposal since parser has been passed to |
I am for suggestion 1, I think it looks good now with that added and with the type issue fixed mentioned by @binliunls. Thanks! |
Ok. Thank you so much for your suggestions! |
Got it, thank you for your valuable feedback! |
|
@binliunls, sorry to bother you, could you please provide some suggestions on the above discussion? Thank you! |
I am OK with the suggestion 1. |
Signed-off-by: Han123su <popsmall212@gmail.com>
…to Fix-issue-6375
for more information, see https://pre-commit.ci
Signed-off-by: Han123su <popsmall212@gmail.com>
…to Fix-issue-6375
Signed-off-by: Han123su <popsmall212@gmail.com>
…to Fix-issue-6375
|
Hi @ericspod @KumoLiu @binliunls, I have made modifications based on the discussions above. Please help review them again, and let me know if there are any further changes needed. Thanks for taking the time to check it out. |
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'm good now if @binliunls @KumoLiu are. Thanks!
KumoLiu
left a comment
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.
Thanks for the update, looks good to me now.
Hi @binliunls, do you have any further comments here, otherwise I will try to merge this one.
LGTM. |
|
/build |
Fixes #6375 .
Description
Changes to be made based on the previous discussion #7835.
Modify the
_exportfunction to call thesaverparameter for saving different models. Rewrite theonnx_exportfunction using the updated_exportto achieve consistency in model format conversion and saving.onnx_exportto call_exportwithconvert_to_onnxand appropriatekwargs.saver: Callableparameter to_export, replacingsave_net_with_metadata.save_net_with_metadatafunction wrapped withpartialto set parameters likeinclude_config_valsandappend_timestamp.Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.