-
Notifications
You must be signed in to change notification settings - Fork 124
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
Conversation
The documentation is not available anymore as the PR was closed or merged. |
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 a lot @eaidova
optimum/intel/openvino/export.py
Outdated
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( |
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 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
)
86e4765
to
2348020
Compare
98bedd9
to
bced686
Compare
Let me know if you'd like me to review! |
ae67cc0
to
91798e8
Compare
@fxmarty could you please review? |
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.
Looks great thanks a lot! I left a few first comments.
setup.py
Outdated
"openvino": ["openvino==2023.1.0.dev20230811", "onnx", "onnxruntime"], | ||
"nncf": ["nncf @ git+https://github.com/openvinotoolkit/nncf.git"], |
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.
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?
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.
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 |
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.
If hard-coded, I think all the following logic relying on it can be removed.
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.
do you suggest to remove possibility to provide custom config?
Because its value comes to True if it provided
@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? |
Now fixed ! |
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.
Huge work @eaidova !! Thanks a lot
import torch | ||
|
||
|
||
def main_export( |
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.
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), |
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 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
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.
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?
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. |
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? |
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) |
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 |
Also the documentation related tests can be ignored as unrelated |
@echarlaix @AlexKoff88 @helena-intel openvino release 2023.1 has been published several hour ago. Could you please take a look one more time? |
@echarlaix, I think we should merge this since quite a lot of new stuff depends on this feature. Thanks! |
Works for me! |
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