Skip to content
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

OV migrate model export on pytorch frontend #397

Merged
merged 39 commits into from
Sep 19, 2023

Conversation

eaidova
Copy link
Collaborator

@eaidova eaidova commented Aug 2, 2023

What does this PR do?

use openvino pyotrch frontend for exporting model. It should reduce memory consumption and speedup conversion of model in comparison with exporting models with intermediate step to convert to ONNX
model conversion pipeline preserved as close as it is possible to onnx path and reuse configuration, dummy input creation and patching from optimum ort

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Aug 2, 2023

The documentation is not available anymore as the PR was closed or merged.

Copy link
Collaborator

@echarlaix echarlaix left a comment

Choose a reason for hiding this comment

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

Thanks a lot @eaidova

f"The task could not be automatically inferred as this is available only for models hosted on the Hugging Face Hub. Please provide the argument --task with the relevant task from {', '.join(TasksManager.get_all_tasks())}. Detailed error: {e}"
)

model = TasksManager.get_model_from_task(
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be super practical to let users export a model directly and not only from a model path that will be used to load the model (like in this example) we could have an export_model function that could be used by main_export (and that would call _get_submodels_and_onnx_configs directly), what do you think ? (we could also have a get_model_from_task and a save_preprocessors functions that could be used when creating / saving an OVModel)

@eaidova eaidova force-pushed the ea/pt_fe branch 3 times, most recently from 86e4765 to 2348020 Compare August 9, 2023 19:06
@eaidova eaidova force-pushed the ea/pt_fe branch 4 times, most recently from 98bedd9 to bced686 Compare August 13, 2023 14:44
@fxmarty
Copy link
Contributor

fxmarty commented Aug 17, 2023

Let me know if you'd like me to review!

@eaidova
Copy link
Collaborator Author

eaidova commented Aug 21, 2023

Let me know if you'd like me to review!

@fxmarty could you please review?

Copy link
Contributor

@fxmarty fxmarty left a comment

Choose a reason for hiding this comment

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

Looks great thanks a lot! I left a few first comments.

setup.py Outdated
Comment on lines 43 to 44
"openvino": ["openvino==2023.1.0.dev20230811", "onnx", "onnxruntime"],
"nncf": ["nncf @ git+https://github.com/openvinotoolkit/nncf.git"],
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know when the release of openvino 2023.1 and nncf are planned? Maybe it would make sense to wait for their release first?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

these changes very important for us for enabling LLMs (we see large benefit in memory consumption and conversion time for them in the first order), also as I can see this PR blocks several other PRs from merge (and some ongoing optimizations too). So I want to bring it as soon as possible without waiting official release

device=device,
)

custom_architecture = False
Copy link
Contributor

Choose a reason for hiding this comment

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

If hard-coded, I think all the following logic relying on it can be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

do you suggest to remove possibility to provide custom config?
Because its value comes to True if it provided

@eaidova
Copy link
Collaborator Author

eaidova commented Aug 23, 2023

@fxmarty looks like ipex testing pipeline broken after release transformers 4.32.0. this failure does not connected with my pr, could you please take a look?

@echarlaix
Copy link
Collaborator

looks like ipex testing pipeline broken after release transformers 4.32.0. this failure does not connected with my pr, could you please take a look?

Now fixed !

Copy link
Collaborator

@echarlaix echarlaix left a comment

Choose a reason for hiding this comment

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

Huge work @eaidova !! Thanks a lot

import torch


def main_export(
Copy link
Collaborator

Choose a reason for hiding this comment

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

A lot seems to be reused from https://github.com/huggingface/optimum/blob/v1.12.0/optimum/exporters/onnx/__main__.py#L132, it would make sense to create functions usable for both the ONNX, OpenVINO export (and others) but can be done in a following PR


# Export the model to the ONNX format
export(model=model, config=onnx_config, output=save_dir_path / ONNX_WEIGHTS_NAME)

return cls._from_pretrained(
model_id=save_dir_path,
config=config,
from_onnx=True,
from_onnx=not is_torch_model(model),
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would make sense to have an OpenVINO model resulting from export for both pytorch / tensorflow wdyt ? Also could make sense to deprecate from_onnx in the future

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, openvino supports tf model conversion directly as well, but I can not find any testing examples in optimum-intel in support tf models to test this approach, that is why I keep it like in optimum used.
Do you have some models that I can take a look regarding tf support?

@AlexKoff88
Copy link
Collaborator

It's been lasting for too long and is getting hard to rebase this PR. Do we really have major comments that should be resolved? If not, I suggest doing a quick check again, fixing CI and proceeding with the merge. Minor comments can be fixed post-merge.
@fxmarty, @echarlaix, what do you think?

@helena-intel
Copy link
Collaborator

It's been lasting for too long and is getting hard to rebase this PR. Do we really have major comments that should be resolved? If not, I suggest doing a quick check again, fixing CI and proceeding with the merge. Minor comments can be fixed post-merge. @fxmarty, @echarlaix, what do you think?

IMO we should be really careful with requiring an OpenVINO prerelease for optimum-intel. Prereleases often have issues, and it's a reasonable expectation that Optimum will just work with the latest OpenVINO release. We recommend people to install optimum-intel from source in some places too. Final OpenVINO 2023.1 release should be soon. Can we wait for that?

@echarlaix
Copy link
Collaborator

There is still a couple of things to add (currently not tests to check the tf model export even if enabled with this PR for example) but can be added in a following PR so that we don't delay this PR even more as it's been a while already. I agree with @helena-intel, it makes sense to wait for openvino v2023.1 if the release date is previewed for soon, also ok to merge it now in case that makes it easier for you @eaidova (we won't do any minor release on our side in the meantime)
Thanks again for the awesome work @eaidova 🔥

@echarlaix
Copy link
Collaborator

fixing CI and proceeding with the merge

Also to fix the openvino tests, https://github.com/eaidova/optimum-intel/blob/ea/pt_fe/optimum/intel/openvino/modeling.py#L552 should be modified to include the renaming of _to_onnx_to_load to _to_load done in this PR cc @eaidova

@echarlaix
Copy link
Collaborator

Also the documentation related tests can be ignored as unrelated

@eaidova
Copy link
Collaborator Author

eaidova commented Sep 18, 2023

@echarlaix @AlexKoff88 @helena-intel openvino release 2023.1 has been published several hour ago. Could you please take a look one more time?
Thanks

@AlexKoff88
Copy link
Collaborator

@echarlaix, I think we should merge this since quite a lot of new stuff depends on this feature. Thanks!

@echarlaix
Copy link
Collaborator

@echarlaix, I think we should merge this since quite a lot of new stuff depends on this feature. Thanks!

Works for me!

@echarlaix echarlaix merged commit 4b8ed24 into huggingface:main Sep 19, 2023
@eaidova eaidova deleted the ea/pt_fe branch September 19, 2023 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants