Skip to content

Commit

Permalink
fix unittest coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
LielinJiang committed Nov 17, 2021
1 parent bbcd325 commit db2ffd4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 3 additions & 1 deletion python/paddle/fluid/tests/unittests/test_kldiv_loss_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ def test_kl_loss_static_api(self):
input = paddle.fluid.data(name='input', shape=[5, 20])
label = paddle.fluid.data(name='label', shape=[5, 20])

pred_loss = paddle.nn.functional.kl_div(input, label)
paddle.nn.functional.kl_div(input, label)
paddle.nn.functional.kl_div(input, label, 'sum')
paddle.nn.functional.kl_div(input, label, 'batchmean')


class TestKLDivLossTypePromotion(unittest.TestCase):
Expand Down
5 changes: 2 additions & 3 deletions python/paddle/nn/functional/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,9 +935,8 @@ def kl_div(input, label, reduction='mean', name=None):
elif reduction == 'sum':
loss = paddle.sum(loss)
elif reduction == 'batchmean':
if len(paddle.shape(input)) > 0:
batch_size = paddle.shape(input)[0]
loss = paddle.sum(out) / batch_size
batch_size = paddle.shape(input)[0]
loss = paddle.sum(loss) / batch_size
return loss


Expand Down

1 comment on commit db2ffd4

@paddle-bot-old
Copy link

Choose a reason for hiding this comment

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

Congratulation! Your pull request passed all required CI. You could ask reviewer(s) to approve and merge. 🎉

Please sign in to comment.