diff --git a/python/paddle/fluid/tests/unittests/test_cross_entropy_loss.py b/python/paddle/fluid/tests/unittests/test_cross_entropy_loss.py index b30a5227a9a93c4970b95e814f8e6368f06644a2..6a037ad6be7c559499c147422819b75fbc4332e7 100644 --- a/python/paddle/fluid/tests/unittests/test_cross_entropy_loss.py +++ b/python/paddle/fluid/tests/unittests/test_cross_entropy_loss.py @@ -1377,6 +1377,15 @@ class TestCrossEntropyFAPIError(unittest.TestCase): self.assertRaises(ValueError, test_LabelValue) + def test_LabelValueNeg(): + input_data = paddle.rand(shape=[20, 100]) + label_data = paddle.randint(0, 100, shape=[5, 1], dtype="int64") + label_data[0] = -1 + paddle.nn.functional.cross_entropy( + input=input_data, label=label_data) + + self.assertRaises(ValueError, test_LabelValueNeg) + if __name__ == "__main__": unittest.main()