Skip to content
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 ONNX export support for PatchTST #2101

Merged
merged 12 commits into from
Jan 9, 2025
Merged

Add ONNX export support for PatchTST #2101

merged 12 commits into from
Jan 9, 2025

Conversation

xenova
Copy link
Contributor

@xenova xenova commented Nov 21, 2024

What does this PR do?

This PR adds ONNX export support for PatchTST models, as well as fixes other models that contain the torch.unfold operator, which is not supported by torch.onnx.export. This is done by applying a set of default patching specs.

Fixes huggingface/transformers.js#1047

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

Who can review?

@michaelbenayoun, @echarlaix

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@michaelbenayoun michaelbenayoun left a comment

Choose a reason for hiding this comment

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

LGTM!

Let's wait for @echarlaix 's review before merging.

Copy link
Collaborator

@echarlaix echarlaix left a comment

Choose a reason for hiding this comment

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

Looks great, thank you so much @xenova for all the great work!

tests/exporters/exporters_utils.py Outdated Show resolved Hide resolved
optimum/exporters/tasks.py Outdated Show resolved Hide resolved
@@ -177,6 +177,7 @@ class OnnxConfig(ExportConfig, ABC):
"text2text-generation": OrderedDict({"logits": {0: "batch_size", 1: "decoder_sequence_length"}}),
"text-classification": OrderedDict({"logits": {0: "batch_size"}}),
"text-generation": OrderedDict({"logits": {0: "batch_size", 1: "sequence_length"}}),
"time-series-forecasting": OrderedDict({"prediction_outputs": {0: "batch_size"}}),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I can't find "time-series-forecasting" in https://huggingface.co/datasets/huggingface/transformers-metadata/blob/main/pipeline_tags.json, do you know if this specific to PatchTST models ? (-> PatchTSTXxxForPrediction)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, this is not a transformers pipeline id, but it is a pipeline tag on the hub: https://huggingface.co/models?pipeline_tag=time-series-forecasting

(Not specific to patchtst)

optimum/exporters/onnx/model_configs.py Outdated Show resolved Hide resolved
@xenova
Copy link
Contributor Author

xenova commented Jan 7, 2025

  • Applied review suggestions ✅
  • Fixed onnx compatible unfold for negative indices ✅

Ready to merge, I'd say! wdyt @echarlaix?

@xenova xenova merged commit b9fa9aa into main Jan 9, 2025
60 checks passed
@xenova xenova deleted the add-patchtst-onnx branch January 9, 2025 17:41
@echarlaix
Copy link
Collaborator

Yes sounds good, thanks @xenova !

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.

PatchTSTModel, PatchTSTConfig, & Trainer
4 participants