-
Notifications
You must be signed in to change notification settings - Fork 618
Add ort export in exporters for encoder-decoder models #497
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
Merged
mht-sharma
merged 17 commits into
huggingface:main
from
mht-sharma:export-encoder-decoder-separately-seq2seq-models
Nov 30, 2022
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5126f53
Add ort export in exporters for encoder-decoder models
mht-sharma efcdeb0
Updated error docstring
mht-sharma 2dd0339
Update encoder decoder config location
mht-sharma 90b9271
Added tests
mht-sharma 90153cf
Update arguments help
mht-sharma bbb89e1
Updated docstring and removed redundant code
mht-sharma fc97e78
Updated config location
mht-sharma 7ec493d
Added methods for ncoder/decoder onnx export and validation
mht-sharma 634c682
Added Seq2Seq-lm encoder-decoder configs
mht-sharma db97f8d
Uncommented tests
mht-sharma bc81a41
Fixed test
mht-sharma bbd201c
Updated argument help
mht-sharma f9713dc
Removed use-past and updated docstring
mht-sharma 936b114
Updated input generator Seq2SeqDecoderConfig
mht-sharma 56db9c5
Update docstrings to use Optional
mht-sharma 224f79c
Added optional import
mht-sharma eef106c
Remove reduntant task from the export function
mht-sharma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -303,6 +303,18 @@ 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_for_validation(self, reference_model_inputs: Mapping[str, Any]) -> Mapping[str, Any]: | ||||||
| """ | ||||||
| Generate inputs for ONNX Runtime using the reference model inputs. Override this to run inference with seq2seq | ||||||
| models which have the encoder and decoder exported as separate ONNX files. | ||||||
| Args: | ||||||
| reference_model_inputs ([`Mapping[str, Tensor]`): | ||||||
| Reference inputs for the model. | ||||||
| Returns: | ||||||
| `Mapping[str, Tensor]`: The mapping holding the kwargs to provide to the model's forward function | ||||||
| """ | ||||||
| return reference_model_inputs | ||||||
|
|
||||||
|
|
||||||
| class OnnxConfigWithPast(OnnxConfig, ABC): | ||||||
| PAD_ATTENTION_MASK_TO_MATCH_TOTAL_SEQUENCE_LENGTH = True | ||||||
|
|
@@ -454,3 +466,43 @@ def flatten_past_key_values(self, flattened_output, name, idx, t): | |||||
| flattened_output[f"{name}.{idx}.decoder.value"] = t[1] | ||||||
| flattened_output[f"{name}.{idx}.encoder.key"] = t[2] | ||||||
| flattened_output[f"{name}.{idx}.encoder.value"] = t[3] | ||||||
|
|
||||||
| def get_encoder_onnx_config(self, config: "PretrainedConfig") -> OnnxConfig: | ||||||
| """ | ||||||
| Returns ONNX encoder config for `Seq2Seq` models. Implement the method to export the encoder | ||||||
| of the model separately. | ||||||
|
|
||||||
| Args: | ||||||
| config (`PretrainedConfig`): | ||||||
| The encoder model's configuration to use when exporting to ONNX. | ||||||
|
|
||||||
| Returns: | ||||||
| `OnnxConfig`: An instance of the ONNX configuration object. | ||||||
| """ | ||||||
| raise NotImplementedError( | ||||||
| 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.", | ||||||
| ) | ||||||
michaelbenayoun marked this conversation as resolved.
Show resolved
Hide resolved
michaelbenayoun marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| def get_decoder_onnx_config( | ||||||
| self, config: "PretrainedConfig", task: str = "default", use_past: bool = False | ||||||
| ) -> OnnxConfig: | ||||||
| """ | ||||||
| Returns ONNX decoder config for `Seq2Seq` models. Implement the method to export the decoder | ||||||
| of the model separately. | ||||||
|
|
||||||
| Args: | ||||||
| config (`PretrainedConfig`): | ||||||
| The decoder model's configuration to use when exporting to ONNX. | ||||||
| task (`str`, defaults to `"default"`): | ||||||
| The task the model should be exported for. | ||||||
| use_past (`bool`, defaults to `False`): | ||||||
| Whether to export the model with past_key_values. | ||||||
|
|
||||||
| Returns: | ||||||
| `OnnxConfig`: An instance of the ONNX configuration object. | ||||||
| """ | ||||||
| raise NotImplementedError( | ||||||
| f"{config.model_type} decoder export is not supported yet. ", | ||||||
| f"If you want to support {config.model_type} please propose a PR or open up an issue.", | ||||||
| ) | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.