Skip to content

Commit

Permalink
[LLM] fix bug when loss is None in llama modeling.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cqulilujia committed May 21, 2024
1 parent daf2f3a commit 7a53d1b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions paddlenlp/transformers/llama/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1645,8 +1645,11 @@ def forward(self, prediction_scores, masked_lm_labels):
binary_sequence = paddle.where(
masked_lm_loss > 0, paddle.ones_like(masked_lm_loss), paddle.zeros_like(masked_lm_loss)
)
sum_ = paddle.sum(binary_sequence)
loss = 0 if sum_ == 0 else paddle.sum(masked_lm_loss * binary_sequence) / sum_
count = paddle.sum(binary_sequence)
if count == 0:
loss = paddle.sum(masked_lm_loss * binary_sequence)

Check warning on line 1650 in paddlenlp/transformers/llama/modeling.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/llama/modeling.py#L1648-L1650

Added lines #L1648 - L1650 were not covered by tests
else:
loss = paddle.sum(masked_lm_loss * binary_sequence) / count

return loss

Expand Down

0 comments on commit 7a53d1b

Please sign in to comment.