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

embedding/position.py with RuntimeError if d_model is odd #78

Open
bookong22 opened this issue Jun 15, 2020 · 2 comments
Open

embedding/position.py with RuntimeError if d_model is odd #78

bookong22 opened this issue Jun 15, 2020 · 2 comments

Comments

@bookong22
Copy link

such as if set d_model = 29, max_len = 10000
RuntimeError: The expanded size of the tensor (14) must match the existing size (15) at non-singleton dimension 1. Target sizes: [10000, 14]. Tensor sizes: [10000, 15]
code in this line may be fixed (line 30):
pe[:, 1::2] = torch.cos(position * div_term)

@bookong22
Copy link
Author

modify
pe[:, 1::2] = torch.cos(position * div_term)
to
pe[:, 1::2] = torch.cos(position * div_term)[:, :d_model//2]

@cheng940929
Copy link

cheng940929 commented Jun 30, 2022

d_model should be a even number

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

No branches or pull requests

2 participants