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 17, 2024
1 parent daf2f3a commit 2d2a503
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion paddlenlp/transformers/llama/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,11 @@ def forward(self, prediction_scores, masked_lm_labels):
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_
if sum_ == 0:
loss = paddle.zeros([], dtype=masked_lm_loss.dtype)
loss.stop_gradient = False

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

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/llama/modeling.py#L1649-L1651

Added lines #L1649 - L1651 were not covered by tests
else:
loss = paddle.sum(masked_lm_loss * binary_sequence) / sum_

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

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/llama/modeling.py#L1653

Added line #L1653 was not covered by tests

return loss

Expand Down

0 comments on commit 2d2a503

Please sign in to comment.