-
Notifications
You must be signed in to change notification settings - Fork 26.3k
register parameters correctly in c++ MultiheadAttention #42037
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
Conversation
[ghstack-poisoned]
|
This is to correct the parameter registration in MultiheadAttention, the root cause is described in #41951. |
| } else { | ||
| std::uniform_int_distribution<int> d(5, 20); | ||
| kv_dim = d(generator); | ||
| while (kv_dim == d_model) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This branch was aimed to test kv_dim != d_model case, but the generator d could generate a same value as d_model, for eg. 9, so I add this while.
| bias_k = register_parameter("bias_k", torch::empty({1, 1, options.embed_dim()})); | ||
| bias_v = register_parameter("bias_v", torch::empty({1, 1, options.embed_dim()})); | ||
| } else { | ||
| bias_k = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to register_parameter('bias_k', {}, /*requires_grad=*/false)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on python impl, No. It only register the non-empty case for bias_k and bias_v.
pytorch/torch/nn/modules/activation.py
Line 837 in 4121d34
| self.bias_k = self.bias_v = None |
zhangguanheng66
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zhangguanheng66
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for the MHA functionality.
|
@glaringlee merged this pull request in 5246bc4. |
Stack from ghstack:
This is to fix #41951
Differential Revision: D22764717