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
| """ | ||
| 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.
Discussion with lewtun regarding the use of the function. huggingface/transformers#19525 (comment)
There was a problem hiding this comment.
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.
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.
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)
|
Currently only |
optimum/exporters/onnx/base.py
Outdated
| """ | ||
| 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.
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. |
| 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.
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.
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.
michaelbenayoun
left a comment
There was a problem hiding this comment.
That's really great!
Left a few comments and questions, but huge work @mht-sharma !
| 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.
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.
I think you do not need that since it is already in the onnx config no?
There was a problem hiding this comment.
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
| """ | ||
| 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.
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.
| @abstractmethod |
Co-authored-by: Michael Benayoun <mickbenayoun@gmail.com>
JingyaHuang
left a comment
There was a problem hiding this comment.
LGTM, love the consistency of new ONNX configs.
What does this PR do?
Adds support to export the
encoderanddecoderseparately forencoder-decodermodels usingexporterscli based on cmd line arguments.Fixes #496
Example usage:
Before submitting