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

[utc] fix cls_positions #4785

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions paddlenlp/transformers/ernie/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,12 +1336,12 @@ def forward(

batch_size, seq_len, hidden_size = sequence_output.shape
flat_sequence_output = paddle.reshape(sequence_output, [-1, hidden_size])
flat_length = paddle.arange(batch_size) * seq_len
flat_length = flat_length.unsqueeze(axis=1).astype("int64")

cls_output = paddle.tensor.gather(flat_sequence_output, cls_positions)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对效果影响大吗?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

训练也是基于有问题的代码吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

小模型的效果有一定影响,在云上训练的代码没有问题。

cls_output = paddle.tensor.gather(flat_sequence_output, cls_positions + flat_length.squeeze(1))
q = self.linear_q(cls_output)

flat_length = paddle.arange(batch_size) * seq_len
flat_length = flat_length.unsqueeze(axis=1).astype("int64")
option_output = paddle.tensor.gather(flat_sequence_output, paddle.reshape(omask_positions + flat_length, [-1]))
option_output = paddle.reshape(option_output, [batch_size, -1, hidden_size])
k = self.linear_k(option_output)
Expand Down