-
Notifications
You must be signed in to change notification settings - Fork 756
[Bug fix] Fix lm head bias #3185
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,13 @@ def __init__( | |
| dtype=paddle.get_default_dtype(), | ||
| is_bias=False, | ||
| ) | ||
| if self.bias_key is not None: | ||
| self.bias = self.create_parameter( | ||
| shape=[num_embeddings], | ||
| dtype=paddle.get_default_dtype(), | ||
| is_bias=True, | ||
| ) | ||
|
|
||
| else: | ||
| if self.column_cut: | ||
| need_gather = True | ||
|
|
@@ -107,6 +114,10 @@ def load_state_dict(self, state_dict: Dict[str, paddle.Tensor | np.ndarray]): | |
|
|
||
| if self.use_ep: | ||
| self.weight.set_value(get_tensor(state_dict.pop(self.weight_key)).astype(paddle.get_default_dtype())) | ||
| if self.bias_key is not None: | ||
| self.bias.set_value( | ||
| get_tensor(state_dict.pop(self.linear_bias_key)).astype(paddle.get_default_dtype()) | ||
| ) | ||
| else: | ||
| if self.tie_word_embeddings: | ||
| self.linear.weight.set_value( | ||
|
|
@@ -134,7 +145,10 @@ def forward(self, input: paddle.Tensor) -> paddle.Tensor: | |
| """ | ||
| logits = input | ||
| if self.use_ep: | ||
| logits = paddle.matmul(logits, self.weight) | ||
| if self.linear_bias_key is None: | ||
| logits = paddle.matmul(logits, self.weight) | ||
| else: | ||
| logits = paddle.incubate.nn.functional.fused_linear(logits, self.weight, self.bias) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这两个底层调用的OP不一致么,会有性能diff么
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不一致,paddle.matmul调用cublas,paddle.incubate.nn.functional.fused_linear调用融合的cublasLt,可以将bias的加法融合到epilogue中,理论上比单独调用 |
||
| else: | ||
| logits = self.linear(logits) | ||
| return logits | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
lm_head是否有bias不应该写在use_ep逻辑下吧?应该是通用的
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.
TP下面用了ColumnLinear的类,类里面会判断。之所以EP不复用ColumnLinear,原因在于这里直接传入了从fleet获取的num_ranks信息。合并EP和TP可以用fd_config中的ep_rank和tp_rank去判断。限于人力这里没有做重构。