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

change llama/modeling.py to opt npu performence #8342

Merged
merged 7 commits into from
Apr 30, 2024
Merged
Changes from 1 commit
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
8 changes: 5 additions & 3 deletions paddlenlp/transformers/llama/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def scaled_dot_product_attention(
attention_mask is None,
True,
False,
False,
is_casual_mask(attention_mask),
)[0]
else:
attn_output = F.scaled_dot_product_attention(
Expand Down Expand Up @@ -1704,8 +1704,10 @@ def forward(self, prediction_scores, masked_lm_labels):
_hcg = fleet.get_hybrid_communicate_group()
masked_lm_loss = ConcatSePMaskedLoss.apply(masked_lm_loss, axis=1, group=_hcg.get_sep_parallel_group())
# skip ignore_index which loss == 0
masked_lm_loss = masked_lm_loss[masked_lm_loss > 0]
loss = paddle.mean(masked_lm_loss)
# masked_lm_loss = masked_lm_loss[masked_lm_loss > 0]
# loss = paddle.mean(masked_lm_loss)
binary_sequence = paddle.where(masked_lm_loss > 0, paddle.ones_like(masked_lm_loss), paddle.zeros_like(masked_lm_loss))
loss = paddle.sum(masked_lm_loss * binary_sequence) / paddle.sum(binary_sequence)
Copy link
Collaborator

@wawltor wawltor Apr 29, 2024

Choose a reason for hiding this comment

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

paddle.sum(binary_sequence) 中binary_sequence有可能全为0,导致sum后0;这里loss会有异常

之前的业务遇到过这个问题

Copy link
Collaborator

Choose a reason for hiding this comment

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

同时对GPU性能的影响是什么


return loss

Expand Down
Loading