Skip to content

Fix(informer): Correct tensor shape for input_size=1 #38856

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
merged 3 commits into from
Jun 23, 2025

Conversation

Flink-ddd
Copy link
Contributor

Hi @Rocketknight1, thanks for the great guidance on the previous PR!

This new pull request follows your suggestion to fix the bug at its source. It resolves a RuntimeError that occurs in time series models inheriting from TimeSeriesTransformerModel (such as InformerModel) when config.input_size is set to 1.

The root cause was that when input_size=1, the loc and scale tensors calculated by the scaler retained an extra dimension (e.g., shape [B, 1, 1] instead of [B, 1]). This incorrect shape caused a dimension mismatch error during a later expand() operation.

Instead of overriding the method in the child class, this PR applies a minimal and robust fix directly to the create_network_inputs method in the parent TimeSeriesTransformerModel. It refactors the logic to unconditionally apply .squeeze(1) to both the loc and scale tensors. This approach handles all input_size cases correctly and avoids code duplication.

Fixes #38745

The create_network_inputs function in TimeSeriesTransformerModel
handled the scaler's loc and scale tensors inconsistently.
When input_size=1, the tensors were not squeezed, leading to
downstream dimension errors for models like Informer.

This commit refactors the logic to unconditionally apply .squeeze(1),
which correctly handles all input_size cases and fixes the bug at its source.

Fixes huggingface#38745
The create_network_inputs function in TimeSeriesTransformerModel
handled the scaler's loc and scale tensors inconsistently.
When input_size=1, the tensors were not squeezed, leading to
downstream dimension errors for models like Informer.

This commit refactors the logic to unconditionally apply .squeeze(1),
which correctly handles all input_size cases and fixes the bug at its source.

Fixes huggingface#38745
@Rocketknight1
Copy link
Member

cc @kashif since you worked on the original informer PR , can you take a look? I suggested this change be moved to the original function for TimeSeriesTransformer, but I'm not certain about that - I don't know the models well enough to know what the expected behaviour should be for config.input_size == 1

@kashif
Copy link
Contributor

kashif commented Jun 18, 2025

thanks @Flink-ddd can you also kindly confirm that autoformer model also works?

@Flink-ddd
Copy link
Contributor Author

Hi @kashif and @Rocketknight1 ,

Thanks for the great suggestion to check Autoformer!

You were right to be cautious. I can confirm that AutoformerModel also suffers from the exact same bug. I was able to verify this locally by running a test against the unfixed code, which failed with the identical RuntimeError as Informer did.

This PR fixes the bug in the shared parent class, TimeSeriesTransformerModel, so it should resolve the issue for both Informer, Autoformer, and any other inheriting models.

All relevant CI checks are now passing. Thanks for helping me get to a much cleaner and more robust solution!

@Flink-ddd
Copy link
Contributor Author

Hi @kashif , thanks again for the approval! Just wanted to gently check in and see if there is anything else needed from my side to get this merged. Thanks!

@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.

@kashif kashif merged commit 334bf91 into huggingface:main Jun 23, 2025
14 checks passed
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.

[Bug][InformerForPredict] The shape will cause a problem
4 participants