-
Notifications
You must be signed in to change notification settings - Fork 487
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
527bbda
767c509
e348d47
eeb3159
e2828ff
43c21d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ | |
NormalizedTextAndVisionConfig, | ||
NormalizedTextConfig, | ||
NormalizedTextConfigWithGQA, | ||
NormalizedTimeSeriesForecastingConfig, | ||
NormalizedVisionConfig, | ||
check_if_diffusers_greater, | ||
check_if_transformers_greater, | ||
|
@@ -2445,3 +2446,51 @@ class EncoderDecoderOnnxConfig(EncoderDecoderBaseOnnxConfig): | |
NORMALIZED_CONFIG_CLASS = NormalizedEncoderDecoderConfig | ||
|
||
DEFAULT_ONNX_OPSET = 14 # uses SDPA in Transformers, hence opset>=14. | ||
|
||
|
||
class PatchTSTDummyInputGenerator(DummyInputGenerator): | ||
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. |
||
SUPPORTED_INPUT_NAMES = ("past_values",) | ||
|
||
def __init__( | ||
self, | ||
task: str, | ||
normalized_config: NormalizedConfig, | ||
batch_size: int = DEFAULT_DUMMY_SHAPES["batch_size"], | ||
**kwargs, | ||
): | ||
self.task = task | ||
self.normalized_config = normalized_config | ||
|
||
self.batch_size = batch_size | ||
self.context_length = normalized_config.context_length | ||
self.num_input_channels = normalized_config.num_input_channels | ||
|
||
def generate(self, input_name: str, framework: str = "pt", int_dtype: str = "int64", float_dtype: str = "fp32"): | ||
return self.random_float_tensor( | ||
shape=[self.batch_size, self.context_length, self.num_input_channels], | ||
min_value=-1, | ||
max_value=1, | ||
framework=framework, | ||
dtype=float_dtype, | ||
) | ||
|
||
|
||
class PatchTSTOnnxConfig(OnnxConfig): | ||
NORMALIZED_CONFIG_CLASS = NormalizedTimeSeriesForecastingConfig | ||
DUMMY_INPUT_GENERATOR_CLASSES = (PatchTSTDummyInputGenerator,) | ||
ATOL_FOR_VALIDATION = 1e-4 | ||
|
||
@property | ||
def inputs(self) -> Dict[str, Dict[int, str]]: | ||
return {"past_values": {0: "batch_size", 1: "sequence_length"}} | ||
|
||
@property | ||
def outputs(self) -> Dict[str, Dict[int, str]]: | ||
if self.task == "feature-extraction": | ||
return {"last_hidden_state": {0: "batch_size"}} | ||
else: | ||
return super().outputs | ||
|
||
|
||
class PatchTSMixerOnnxConfig(PatchTSTOnnxConfig): | ||
pass |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -314,6 +314,10 @@ class TasksManager: | |||||||||||||
} | ||||||||||||||
|
||||||||||||||
_CUSTOM_CLASSES = { | ||||||||||||||
("pt", "patchtsmixer", "feature-extraction"): ("transformers", "PatchTSMixerModel"), | ||||||||||||||
("pt", "patchtsmixer", "time-series-forecasting"): ("transformers", "PatchTSMixerForPrediction"), | ||||||||||||||
("pt", "patchtst", "feature-extraction"): ("transformers", "PatchTSTModel"), | ||||||||||||||
("pt", "patchtst", "time-series-forecasting"): ("transformers", "PatchTSTForPrediction"), | ||||||||||||||
Comment on lines
+317
to
+320
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. shouldn't
Suggested change
|
||||||||||||||
("pt", "pix2struct", "image-to-text"): ("transformers", "Pix2StructForConditionalGeneration"), | ||||||||||||||
("pt", "pix2struct", "visual-question-answering"): ("transformers", "Pix2StructForConditionalGeneration"), | ||||||||||||||
("pt", "visual-bert", "question-answering"): ("transformers", "VisualBertForQuestionAnswering"), | ||||||||||||||
|
@@ -911,6 +915,16 @@ class TasksManager: | |||||||||||||
"text-classification", | ||||||||||||||
onnx="OPTOnnxConfig", | ||||||||||||||
), | ||||||||||||||
"patchtst": supported_tasks_mapping( | ||||||||||||||
"feature-extraction", | ||||||||||||||
"time-series-forecasting", | ||||||||||||||
onnx="PatchTSTOnnxConfig", | ||||||||||||||
), | ||||||||||||||
"patchtsmixer": supported_tasks_mapping( | ||||||||||||||
"feature-extraction", | ||||||||||||||
"time-series-forecasting", | ||||||||||||||
onnx="PatchTSMixerOnnxConfig", | ||||||||||||||
), | ||||||||||||||
"qwen2": supported_tasks_mapping( | ||||||||||||||
"feature-extraction", | ||||||||||||||
"feature-extraction-with-past", | ||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -128,6 +128,8 @@ | |||||
"opt": "hf-internal-testing/tiny-random-OPTModel", | ||||||
"owlv2": "hf-internal-testing/tiny-random-Owlv2Model", | ||||||
"owlvit": "hf-tiny-model-private/tiny-random-OwlViTModel", | ||||||
"patchtst": "ibm/test-patchtst", | ||||||
"patchtsmixer": "ibm/test-patchtsmixer", | ||||||
"pegasus": "hf-internal-testing/tiny-random-PegasusModel", | ||||||
"perceiver": { | ||||||
"hf-internal-testing/tiny-random-language_perceiver": ["fill-mask", "text-classification"], | ||||||
|
@@ -255,6 +257,8 @@ | |||||
"nystromformer": "hf-internal-testing/tiny-random-NystromformerModel", | ||||||
"owlv2": "google/owlv2-base-patch16", | ||||||
"owlvit": "google/owlvit-base-patch32", | ||||||
"patchtst": "ibm/test-patchtst", | ||||||
"patchtsmixer": "ibm/test-patchtsmixer", | ||||||
Comment on lines
+260
to
+261
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. already included in
Suggested change
|
||||||
"perceiver": "hf-internal-testing/tiny-random-PerceiverModel", # Not using deepmind/language-perceiver because it takes too much time for testing. | ||||||
# "rembert": "google/rembert", | ||||||
"poolformer": "hf-internal-testing/tiny-random-PoolFormerModel", | ||||||
|
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 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
)