diff --git a/python/paddle/fluid/tests/unittests/test_label_smooth_functional.py b/python/paddle/fluid/tests/unittests/test_label_smooth_functional.py index 83c8ced79b1e8a86ea28cb82349a389547115298..54f5e64fda4b6b5b1dc5bc04885fe21992d25f65 100644 --- a/python/paddle/fluid/tests/unittests/test_label_smooth_functional.py +++ b/python/paddle/fluid/tests/unittests/test_label_smooth_functional.py @@ -19,8 +19,6 @@ import paddle.fluid.dygraph as dg import paddle.nn.functional as F import paddle.fluid.initializer as I import unittest -from paddle.fluid.framework import _enable_legacy_dygraph -_enable_legacy_dygraph() class LabelSmoothTestCase(unittest.TestCase): diff --git a/python/paddle/nn/functional/common.py b/python/paddle/nn/functional/common.py index 907fd4e6252c6fdfac776c588d5c55ecc6144b2e..fe37b8fb97c3d9ca9802fbad6f1a21c19f5dcfc7 100644 --- a/python/paddle/nn/functional/common.py +++ b/python/paddle/nn/functional/common.py @@ -1633,14 +1633,14 @@ def label_smooth(label, prior_dist=None, epsilon=0.1, name=None): #[[[0.03333334 0.93333334 0.03333334] # [0.93333334 0.03333334 0.93333334]]] """ + if epsilon > 1. or epsilon < 0.: + raise ValueError("The value of epsilon must be between 0 and 1.") + if in_dygraph_mode(): return _C_ops.final_state_label_smooth(label, prior_dist, float(epsilon)) - if epsilon > 1. or epsilon < 0.: - raise ValueError("The value of epsilon must be between 0 and 1.") - - if paddle.in_dynamic_mode(): + elif paddle.in_dynamic_mode(): return _C_ops.label_smooth(label, prior_dist, 'epsilon', float(epsilon)) check_variable_and_dtype(label, 'label', ['float32', 'float64'],