Skip to content

Support decoder generated with --for-ort from optimum.exporters.onnx in ORTDecoder#554

Merged
fxmarty merged 13 commits into
huggingface:mainfrom
fxmarty:support-decoder-only-exporters
Dec 8, 2022
Merged

Support decoder generated with --for-ort from optimum.exporters.onnx in ORTDecoder#554
fxmarty merged 13 commits into
huggingface:mainfrom
fxmarty:support-decoder-only-exporters

Conversation

@fxmarty

@fxmarty fxmarty commented Dec 7, 2022

Copy link
Copy Markdown
Contributor

What does this PR do?

Currently, the optimum.exporters.onnx export in separate encoder / decoder files works well. However, for decoder-only models as gpt2, the support was not yet implemented. This PR allows decoder-only models exported through optimum.exporters.onnx to be loaded in ORTDecoder subclasses (as ORTModelForCausalLM).

Note: I am not sure it's super clean to duplicate methods like in this PR for specific cases. @echarlaix how do you plan to support the ONNX export for diffusion models in the current framework, and integrate in optimum.exporters.onnx?

There are tests missing to check:

  • that optimum.exporters.onnx is well interfaced with ORTModel
  • that the CLI of optimum.exporters.onnx works well

Fixes #552

@HuggingFaceDocBuilderDev

HuggingFaceDocBuilderDev commented Dec 7, 2022

Copy link
Copy Markdown

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

@@ -372,7 +372,7 @@ def __init__(
if use_past != self.use_present_in_outputs:
logger.warning(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This warning is always raised, why is the warning necessary? cc @michaelbenayoun

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Basically, it is when use_past and use_present_in_outputs do not have the same value. But you are right the current way is not working all the time. Let me fix that on my end on a small PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes I understand that from the condition! But I'm not sure why there is the warning? In which case would the two be exclusive?

@michaelbenayoun michaelbenayoun Dec 8, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you specify use_present_in_outputs=True and use_past=False. Which can be the case when exporting a model which uses cache.

That is true that we should maybe deprecate use_past and have it as a property being:

@property
def use_past(self):
   return self.use_past_in_inputs or self.use_present_in_outputs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

Comment thread optimum/exporters/onnx/utils.py
Comment thread optimum/exporters/onnx/convert.py Outdated
Comment thread optimum/exporters/onnx/__main__.py Outdated
@@ -372,7 +372,7 @@ def __init__(
if use_past != self.use_present_in_outputs:
logger.warning(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Basically, it is when use_past and use_present_in_outputs do not have the same value. But you are right the current way is not working all the time. Let me fix that on my end on a small PR.

Comment thread optimum/exporters/onnx/convert.py Outdated
Comment thread optimum/exporters/onnx/convert.py Outdated
Comment thread optimum/onnxruntime/modeling_decoder.py Outdated
@fxmarty

fxmarty commented Dec 8, 2022

Copy link
Copy Markdown
Contributor Author

@michaelbenayoun I simplified much of the code duplication for multiple ONNX files export, feel free to rereview.

@michaelbenayoun michaelbenayoun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good refactoring!
I left a few comments, can be merged once they have been considered and/or addressed.

Comment thread optimum/exporters/onnx/__main__.py Outdated
Comment thread optimum/exporters/onnx/__main__.py Outdated
Comment thread optimum/exporters/onnx/convert.py Outdated
Comment thread optimum/exporters/onnx/convert.py Outdated
Comment thread optimum/exporters/onnx/convert.py Outdated
Comment thread optimum/exporters/onnx/convert.py Outdated
@fxmarty

fxmarty commented Dec 8, 2022

Copy link
Copy Markdown
Contributor Author

All good, thanks. Will leave the tests running and merge once passed.

@echarlaix echarlaix left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM !

@fxmarty
fxmarty merged commit 0970ec4 into huggingface:main Dec 8, 2022
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.

Issue to use GPT2 ONNX export with past key values

4 participants