-
Notifications
You must be signed in to change notification settings - Fork 502
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
Add ort export in exporters for encoder-decoder models #497
Add ort export in exporters for encoder-decoder models #497
Conversation
The documentation is not available anymore as the PR was closed or merged. |
optimum/exporters/onnx/base.py
Outdated
@@ -303,6 +303,56 @@ def flatten_output_collection_property(cls, name: str, field: Iterable[Any]) -> | |||
""" | |||
return {f"{name}.{idx}": item for idx, item in enumerate(itertools.chain.from_iterable(field))} | |||
|
|||
def generate_dummy_inputs_onnxruntime(self, reference_model_inputs: Mapping[str, Any]) -> Mapping[str, Any]: |
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.
Discussion with lewtun regarding the use of the function. huggingface/transformers#19525 (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 is needed to generate the inputs for the separate encoder and decoder models?
Is it only used for validation?
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 is needed only for validation using onnxruntime. Since the onnx model and torch model will have different input signatures when using encoder_outputs
for exporting the 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.
What about calling it generate_dummy_inputs_for_validation
?
I think it can be misleading otherwise (more so now that we use a for-ort
argument that does not mean the same thing)
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.
Agree. Updated!
Currently only |
optimum/exporters/onnx/base.py
Outdated
@@ -303,6 +303,56 @@ def flatten_output_collection_property(cls, name: str, field: Iterable[Any]) -> | |||
""" | |||
return {f"{name}.{idx}": item for idx, item in enumerate(itertools.chain.from_iterable(field))} | |||
|
|||
def generate_dummy_inputs_onnxruntime(self, reference_model_inputs: Mapping[str, Any]) -> Mapping[str, Any]: |
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 is needed to generate the inputs for the separate encoder and decoder models?
Is it only used for validation?
To answer your question: you can also add support for other models if you feel like it! |
28dc7d0
to
fc97e78
Compare
Added support for exporting the Seq2Seq-lm models also. AFAIK I covered the models with existing support let me know if I missed something. |
optimum/exporters/onnx/__main__.py
Outdated
parser.add_argument( | ||
"--for-ort", | ||
action="store_true", | ||
help=( | ||
"This exports models ready to be run with optimum.onnxruntime ORTModelXXX. Useful for encoder-decoder models for" | ||
"conditional generation. If enabled the encoder and decoder of the model are exported separately." | ||
), | ||
) |
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.
Could the name for-ort
be misleading as the models can have other tasks apart from the conditional generation?
I have mentioned Useful for encoder-decoder models for conditional generation
in help. But not sure if this would be enough.
Probably updating ORTModelXXX
-> ORTModelForConditionalGeneration
?
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 would just say to run with optimum.onnxruntime
. I think for-ort
is good enough, or at least I do not have a better naming in mind.
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.
That's really great!
Left a few comments and questions, but huge work @mht-sharma !
optimum/exporters/onnx/__main__.py
Outdated
parser.add_argument( | ||
"--for-ort", | ||
action="store_true", | ||
help=( | ||
"This exports models ready to be run with optimum.onnxruntime ORTModelXXX. Useful for encoder-decoder models for" | ||
"conditional generation. If enabled the encoder and decoder of the model are exported separately." | ||
), | ||
) |
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 would just say to run with optimum.onnxruntime
. I think for-ort
is good enough, or at least I do not have a better naming in mind.
optimum/exporters/onnx/__main__.py
Outdated
args.opset, | ||
args.output, | ||
) | ||
use_past = True if "-with-past" in task else 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.
I think you do not need that since it is already in the onnx config no?
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, was probably thinking of how the ORTModelForConditionalGeneration
is currently implemented which create onnx config always without past. But that can be modified later.
Currently, updated to use use_past
from the onnx config.
optimum/exporters/onnx/base.py
Outdated
@@ -303,6 +303,56 @@ def flatten_output_collection_property(cls, name: str, field: Iterable[Any]) -> | |||
""" | |||
return {f"{name}.{idx}": item for idx, item in enumerate(itertools.chain.from_iterable(field))} | |||
|
|||
def generate_dummy_inputs_onnxruntime(self, reference_model_inputs: Mapping[str, Any]) -> Mapping[str, Any]: |
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 about calling it generate_dummy_inputs_for_validation
?
I think it can be misleading otherwise (more so now that we use a for-ort
argument that does not mean the same thing)
f"{config.model_type} encoder export is not supported yet. ", | ||
f"If you want to support {config.model_type} please propose a PR or open up an issue.", | ||
) | ||
|
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.
@abstractmethod |
Co-authored-by: Michael Benayoun <mickbenayoun@gmail.com>
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.
LGTM!
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.
LGTM, love the consistency of new ONNX configs.
What does this PR do?
Adds support to export the
encoder
anddecoder
separately forencoder-decoder
models usingexporters
cli based on cmd line arguments.Fixes #496
Example usage:
Before submitting