-
Notifications
You must be signed in to change notification settings - Fork 612
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
Fix attention concat #902
Fix attention concat #902
Conversation
Fixes #689 |
Codecov Report
@@ Coverage Diff @@
## master #902 +/- ##
==========================================
+ Coverage 89.57% 89.78% +0.20%
==========================================
Files 26 26
Lines 4173 4200 +27
==========================================
+ Hits 3738 3771 +33
+ Misses 435 429 -6
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Hi Jan, Thank you for the great library! As of today (03/24/2022), I started encountering the multitarget bug described in #689 for the first time (in colab notebooks that were previously successfully forecasting multiple targets with TFT as recently as 03/23/2022). |
Hi, @jdb78 . Awesome fix, Since this fix I am getting this error when trying to use the interpret_output function. Do you know what the problem could be? It seems like a small bug when trying to get a dimension of the vector that is a list... interpretation = best_tft.interpret_output(raw_predictions, reduction="sum") AttributeError Traceback (most recent call last) File ~/.local/share/virtualenvs/SPF-25pQYGzl/lib/python3.8/site-packages/pytorch_forecasting/models/temporal_fusion_transformer/init.py:597, in TemporalFusionTransformer.interpret_output(self, out, reduction, attention_prediction_horizon) AttributeError: 'list' object has no attribute 'size' |
Hm, a bit strnage. Do you have a minimal working example? |
Yes, it is strange... When i do it with the tuorial works well. I am using a dataset of my own, the parameters of the time series dataset are
The model is created with:
I create the dataloader exactly as in the tutorial (same parameters and using from_dataset and the to_dataloader. Raw predictions are calculated as in the tutorial as well, with raw_predictions, x, indexx = best_tft.predict(val_dataloader, mode="raw", return_x=True,return_index=True) I don't know where the problem might come from... I think it is that when i get raw_predictions["encoder_attention"] i get a list, maybe its needed in the code an "if statement" that gets when this is a list (in the code this is done only with raw_predictions["decoder_attention"] but not with encoder and thats where the error comes from)? what do you think @jdb78 ? Thank you very much! |
Hi @jdb78 , in my data, if i made a raw_predictions["decoder_attention"].shape i get torch.Size([5147487, 5, 4, 5]). The raw_predictions["encoder_attention"] is a list of tensors indeed, of len()= 5147487, and if i do raw_predictions["encoder_attention"][0].shape i get torch.Size([5, 4, 21]) I am using 4 attention heads and the max_prediction length is 5 and max encoder_ length 21. I think the problem is just that the interpret_output function assumes that raw_predictions["encoder_attention"] is always a tensor, what do you think? Hope this helps to fix the issue, thank you very much! |
@jdb78 I think its just adding the if isinstance(out[“encoder_attention”], (list, tuple)) in the line i marked the error is and changing tensor size for the corresponding with accesing list first... Did you have time to get an eye on this? thank you! |
Description
This PR fixes an issue with attention calculation accross many samples and predict(mode="raw") failing.
Checklist
pre-commit install
.To run hooks independent of commit, execute
pre-commit run --all-files
Make sure to have fun coding!