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 87e4c4f commit e1d30a0
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 @@ -1654,8 +1654,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 1659 in paddlenlp/transformers/llama/modeling.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/llama/modeling.py#L1657-L1659

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

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

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/llama/modeling.py#L1661

Added line #L1661 was not covered by tests

return loss

Expand Down

0 comments on commit e1d30a0

Please sign in to comment.