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

Wrong PositionalEncoding in the Transformer example #19138

Open
Galaxy-Husky opened this issue Dec 11, 2023 · 7 comments · May be fixed by #20203
Open

Wrong PositionalEncoding in the Transformer example #19138

Galaxy-Husky opened this issue Dec 11, 2023 · 7 comments · May be fixed by #20203
Assignees
Labels
bug Something isn't working example good first issue Good for newcomers help wanted Open to be worked on ver: 2.2.x

Comments

@Galaxy-Husky
Copy link

Galaxy-Husky commented Dec 11, 2023

Bug description

Hi,

I think there are several mistakes in the implemention of the PositionalEncoding in the lightning/pytorch/demos/transformer.py.

Since the transformer is set to

  1. The shape of the pe should be [batch_size, len, dim]. This transpose operation is redundant.
    pe = pe.unsqueeze(0).transpose(0, 1)
  2. And the shape of self.pe should be self.pe[:, :x.size(1)]
  3. The result of the addition above is not assigned to x, so the pe will not take effect.

Would you please let me know if I'm wrong?

What version are you seeing the problem on?

master

How to reproduce the bug

No response

Error messages and logs

# Error messages and logs here please

Environment

Current environment
#- Lightning Component (e.g. Trainer, LightningModule, LightningApp, LightningWork, LightningFlow):
#- PyTorch Lightning Version (e.g., 1.5.0):
#- Lightning App Version (e.g., 0.5.2):
#- PyTorch Version (e.g., 2.0):
#- Python version (e.g., 3.9):
#- OS (e.g., Linux):
#- CUDA/cuDNN version:
#- GPU models and configuration:
#- How you installed Lightning(`conda`, `pip`, source):
#- Running environment of LightningApp (e.g. local, cloud):

More info

No response

cc @Borda

@Galaxy-Husky Galaxy-Husky added bug Something isn't working needs triage Waiting to be triaged by maintainers labels Dec 11, 2023
@NicholasKiefer
Copy link

You are not on the master branch.

@Galaxy-Husky
Copy link
Author

You are not on the master branch.
Thank you for your reply. I checked the code permalinks and found that they will be changed automatically to branch 275822 from master after I copy and paste in the box. In fact, they are exactly the same.

@awaelchli
Copy link
Contributor

@Galaxy-Husky Do you want to make the adjustments in a PR?

@awaelchli awaelchli added example help wanted Open to be worked on and removed needs triage Waiting to be triaged by maintainers labels Dec 11, 2023
@awaelchli
Copy link
Contributor

I think it would be good to go over the example one more time to fix the correctness issues. The initial version was just ported from the PyTorch examples repo but the goal then was not to make it train well but to serve as dummy example for quick testing.

@Galaxy-Husky
Copy link
Author

@Galaxy-Husky Do you want to make the adjustments in a PR?

Sure, I'd love to.

@Galaxy-Husky
Copy link
Author

I think it would be good to go over the example one more time to fix the correctness issues. The initial version was just ported from the PyTorch examples repo but the goal then was not to make it train well but to serve as dummy example for quick testing.

Thank you for your explanation. I got it !

@awaelchli awaelchli added the good first issue Good for newcomers label Jul 29, 2024
@manu-chauhan
Copy link

manu-chauhan commented Aug 14, 2024

Help needed for this ? I see this is still open. @awaelchli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working example good first issue Good for newcomers help wanted Open to be worked on ver: 2.2.x
Projects
None yet
4 participants