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

[Time series Informer] fix dtype of cumsum #25431

Merged
merged 3 commits into from
Aug 18, 2023

Conversation

kashif
Copy link
Contributor

@kashif kashif commented Aug 10, 2023

What does this PR do?

Fix an issue when training Informer with FP16, the cumsum returns float32.

See report here: https://discuss.huggingface.co/t/how-to-train-on-multiple-gpus-the-informer-model-for-time-series-forecasting/48984/3

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Aug 10, 2023

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

@kashif kashif requested a review from ArthurZucker August 17, 2023 16:14
Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Nice catch! Thanks for the fix. Is there a reason for float32 -> cast to the correct type instead of computing it in the correct dtype? (If so just add a small comment! )

@@ -647,7 +647,7 @@ def forward(
# calculate context for updating the attn_output, based on:
# https://github.com/zhouhaoyi/Informer2020/blob/ac59c7447135473fb2aafeafe94395f884d5c7a5/models/attn.py#L74
if self.is_decoder:
context = value_states.cumsum(dim=-2)
context = value_states.cumsum(dim=-2, dtype=torch.float32).to(value_states.dtype)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
context = value_states.cumsum(dim=-2, dtype=torch.float32).to(value_states.dtype)
context = value_states.cumsum(dim=-2, dtype=value_states.dtype)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so I wanted the cumsum to be in float32 to avoid overflow etc. and then cast...

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Thanks

@kashif kashif merged commit 8d2f953 into huggingface:main Aug 18, 2023
@kashif kashif deleted the informer-cumsum branch August 18, 2023 12:27
blbadger pushed a commit to blbadger/transformers that referenced this pull request Nov 8, 2023
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.

3 participants